Add context to DecortAPICall method
This commit is contained in:
1
go.mod
1
go.mod
@@ -8,4 +8,5 @@ require (
|
|||||||
github.com/hashicorp/terraform-plugin-docs v0.5.1
|
github.com/hashicorp/terraform-plugin-docs v0.5.1
|
||||||
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 // indirect
|
github.com/hashicorp/terraform-plugin-sdk/v2 v2.17.0 // indirect
|
||||||
github.com/sirupsen/logrus v1.7.0
|
github.com/sirupsen/logrus v1.7.0
|
||||||
|
golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
@@ -325,7 +326,7 @@ func (config *ControllerCfg) validateLegacyUser() (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *ControllerCfg) DecortAPICall(method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam
|
func (config *ControllerCfg) DecortAPICall(ctx context.Context, method string, api_name string, url_values *url.Values) (json_resp string, err error) { //nolint:unparam
|
||||||
// This is a convenience wrapper around standard HTTP request methods that is aware of the
|
// This is a convenience wrapper around standard HTTP request methods that is aware of the
|
||||||
// authorization mode for which the provider was initialized and compiles request accordingly.
|
// authorization mode for which the provider was initialized and compiles request accordingly.
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ limitations under the License.
|
|||||||
package location
|
package location
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -30,13 +31,13 @@ import (
|
|||||||
|
|
||||||
var DefaultGridID int
|
var DefaultGridID int
|
||||||
|
|
||||||
func UtilityLocationGetDefaultGridID(m interface{}) (int, error) {
|
func UtilityLocationGetDefaultGridID(ctx context.Context, m interface{}) (int, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
log.Debug("utilityLocationGetDefaultGridID: retrieving locations list")
|
log.Debug("utilityLocationGetDefaultGridID: retrieving locations list")
|
||||||
apiResp, err := c.DecortAPICall("POST", LocationsListAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", LocationsListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
"github.com/rudecs/terraform-provider-decort/internal/location"
|
"github.com/rudecs/terraform-provider-decort/internal/location"
|
||||||
@@ -122,7 +123,9 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
gridId, err := location.UtilityLocationGetDefaultGridID(decsController)
|
ctx := context.Background()
|
||||||
|
|
||||||
|
gridId, err := location.UtilityLocationGetDefaultGridID(ctx, decsController)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
acc, err := utilityAccountCheckPresence(d, m)
|
acc, err := utilityAccountCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func flattenAccountAuditsList(aal AccountAuditsList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountAuditsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountAuditsList, err := utilityAccountAuditsListCheckPresence(d, m)
|
accountAuditsList, err := utilityAccountAuditsListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func flattenAccountComputesList(acl AccountComputesList) []map[string]interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountComputesList, err := utilityAccountComputesListCheckPresence(d, m)
|
accountComputesList, err := utilityAccountComputesListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountConsumedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(d, m)
|
accountConsumedUnits, err := utilityAccountConsumedUnitsCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountConsumedUnitsByTypeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
result, err := utilityAccountConsumedUnitsByTypeCheckPresence(d, m)
|
result, err := utilityAccountConsumedUnitsByTypeCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountDeletedList, err := utilityAccountDeletedListCheckPresence(d, m)
|
accountDeletedList, err := utilityAccountDeletedListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func flattenAccountDisksList(adl AccountDisksList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountDisksListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountDisksList, err := utilityAccountDisksListCheckPresence(d, m)
|
accountDisksList, err := utilityAccountDisksListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func flattenAccountFlipGroupsList(afgl AccountFlipGroupsList) []map[string]inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountFlipGroupsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(d, m)
|
accountFlipGroupsList, err := utilityAccountFlipGroupsListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,7 @@ func flattenAccountList(al AccountList) []map[string]interface{} {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountList, err := utilityAccountListCheckPresence(d, m)
|
accountList, err := utilityAccountListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountReservedUnitsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(d, m)
|
accountReservedUnits, err := utilityAccountReservedUnitsCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ func flattenAccRGResources(argr AccountRGResources) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountRGListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountRGList, err := utilityAccountRGListCheckPresence(d, m)
|
accountRGList, err := utilityAccountRGListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func flattenAccountTemplatesList(atl AccountTemplatesList) []map[string]interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountTemplatesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(d, m)
|
accountTemplatesList, err := utilityAccountTemplatesListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ func flattenAccountVinsList(avl AccountVinsList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceAccountVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
accountVinsList, err := utilityAccountVinsListCheckPresence(d, m)
|
accountVinsList, err := utilityAccountVinsListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
log.Debugf("resourceAccountCreate")
|
log.Debugf("resourceAccountCreate")
|
||||||
|
|
||||||
if accountId, ok := d.GetOk("account_id"); ok {
|
if accountId, ok := d.GetOk("account_id"); ok {
|
||||||
if exists, err := resourceAccountExists(d, m); exists {
|
if exists, err := resourceAccountExists(ctx, d, m); exists {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountId, err := c.DecortAPICall("POST", accountCreateAPI, urlValues)
|
accountId, err := c.DecortAPICall(ctx, "POST", accountCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -155,7 +155,7 @@ func resourceAccountCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceAccountRead")
|
log.Debugf("resourceAccountRead")
|
||||||
|
|
||||||
acc, err := utilityAccountCheckPresence(d, m)
|
acc, err := utilityAccountCheckPresence(ctx, d, m)
|
||||||
if acc == nil {
|
if acc == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -194,7 +194,7 @@ func resourceAccountRead(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceAccountDelete")
|
log.Debugf("resourceAccountDelete")
|
||||||
|
|
||||||
account, err := utilityAccountCheckPresence(d, m)
|
account, err := utilityAccountCheckPresence(ctx, d, m)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -207,7 +207,7 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", accountDeleteAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", accountDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -216,10 +216,10 @@ func resourceAccountDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceAccountExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceAccountExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceAccountExists")
|
log.Debugf("resourceAccountExists")
|
||||||
|
|
||||||
account, err := utilityAccountCheckPresence(d, m)
|
account, err := utilityAccountCheckPresence(ctx, d, m)
|
||||||
if account == nil {
|
if account == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -243,7 +243,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
}
|
}
|
||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
if d.HasChange("account_name") {
|
if d.HasChange("account_name") {
|
||||||
urlValues.Add("name", d.Get("account_name").(string))
|
urlValues.Add("name", d.Get("account_name").(string))
|
||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
_, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -318,7 +318,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
}
|
}
|
||||||
|
|
||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
_, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -329,7 +329,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
if d.HasChange("send_access_emails") {
|
if d.HasChange("send_access_emails") {
|
||||||
urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool)))
|
urlValues.Add("sendAccessEmails", strconv.FormatBool(d.Get("send_access_emails").(bool)))
|
||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
_, err := c.DecortAPICall("POST", accountUpdateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountUpdateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -341,7 +341,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
restore := d.Get("restore").(bool)
|
restore := d.Get("restore").(bool)
|
||||||
if restore {
|
if restore {
|
||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
_, err := c.DecortAPICall("POST", accountRestoreAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountRestoreAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
urlValues.Add("userId", userConv["user_id"].(string))
|
urlValues.Add("userId", userConv["user_id"].(string))
|
||||||
urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool)))
|
urlValues.Add("recursivedelete", strconv.FormatBool(userConv["recursive_delete"].(bool)))
|
||||||
_, err := c.DecortAPICall("POST", accountDeleteUserAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountDeleteUserAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -394,7 +394,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
urlValues.Add("userId", userConv["user_id"].(string))
|
urlValues.Add("userId", userConv["user_id"].(string))
|
||||||
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
||||||
_, err := c.DecortAPICall("POST", accountAddUserAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountAddUserAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -409,7 +409,7 @@ func resourceAccountEdit(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
urlValues.Add("userId", userConv["user_id"].(string))
|
urlValues.Add("userId", userConv["user_id"].(string))
|
||||||
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
urlValues.Add("accesstype", strings.ToUpper(userConv["access_type"].(string)))
|
||||||
_, err := c.DecortAPICall("POST", accountUpdateUserAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", accountUpdateUserAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -786,7 +786,6 @@ func ResourceAccount() *schema.Resource {
|
|||||||
ReadContext: resourceAccountRead,
|
ReadContext: resourceAccountRead,
|
||||||
UpdateContext: resourceAccountEdit,
|
UpdateContext: resourceAccountEdit,
|
||||||
DeleteContext: resourceAccountDelete,
|
DeleteContext: resourceAccountDelete,
|
||||||
Exists: resourceAccountExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*AccountWithResources, error) {
|
func utilityAccountCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*AccountWithResources, error) {
|
||||||
account := &AccountWithResources{}
|
account := &AccountWithResources{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -54,7 +55,7 @@ func utilityAccountCheckPresence(d *schema.ResourceData, m interface{}) (*Accoun
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountCheckPresence: load account")
|
log.Debugf("utilityAccountCheckPresence: load account")
|
||||||
accountRaw, err := c.DecortAPICall("POST", accountGetAPI, urlValues)
|
accountRaw, err := c.DecortAPICall(ctx, "POST", accountGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountAuditsList, error) {
|
func utilityAccountAuditsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountAuditsList, error) {
|
||||||
accountAuditsList := AccountAuditsList{}
|
accountAuditsList := AccountAuditsList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountAuditsListCheckPresence(d *schema.ResourceData, m interface{}
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountAuditsListCheckPresence: load account list")
|
log.Debugf("utilityAccountAuditsListCheckPresence: load account list")
|
||||||
accountAuditsListRaw, err := c.DecortAPICall("POST", accountAuditsAPI, urlValues)
|
accountAuditsListRaw, err := c.DecortAPICall(ctx, "POST", accountAuditsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountComputesList, error) {
|
func utilityAccountComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountComputesList, error) {
|
||||||
accountComputesList := AccountComputesList{}
|
accountComputesList := AccountComputesList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountComputesListCheckPresence(d *schema.ResourceData, m interface
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
log.Debugf("utilityAccountComputesListCheckPresence: load account list")
|
||||||
accountComputesListRaw, err := c.DecortAPICall("POST", accountListComputesAPI, urlValues)
|
accountComputesListRaw, err := c.DecortAPICall(ctx, "POST", accountListComputesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
func utilityAccountConsumedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
||||||
accountConsumedUnits := &ResourceLimits{}
|
accountConsumedUnits := &ResourceLimits{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountConsumedUnitsCheckPresence(d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list")
|
log.Debugf("utilityAccountConsumedUnitsCheckPresence: load account list")
|
||||||
accountConsumedUnitsRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsAPI, urlValues)
|
accountConsumedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m interface{}) (float64, error) {
|
func utilityAccountConsumedUnitsByTypeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (float64, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountConsumedUnitsByTypeCheckPresence(d *schema.ResourceData, m in
|
|||||||
urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string)))
|
urlValues.Add("cutype", strings.ToUpper(d.Get("cu_type").(string)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence")
|
log.Debugf("utilityAccountConsumedUnitsByTypeCheckPresence")
|
||||||
resultRaw, err := c.DecortAPICall("POST", accountGetConsumedUnitsByTypeAPI, urlValues)
|
resultRaw, err := c.DecortAPICall(ctx, "POST", accountGetConsumedUnitsByTypeAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
func utilityAccountDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
||||||
accountDeletedList := AccountCloudApiList{}
|
accountDeletedList := AccountCloudApiList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -55,7 +56,7 @@ func utilityAccountDeletedListCheckPresence(d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
log.Debugf("utilityAccountDeletedListCheckPresence: load")
|
||||||
accountDeletedListRaw, err := c.DecortAPICall("POST", accountListDeletedAPI, urlValues)
|
accountDeletedListRaw, err := c.DecortAPICall(ctx, "POST", accountListDeletedAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{}) (AccountDisksList, error) {
|
func utilityAccountDisksListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountDisksList, error) {
|
||||||
accountDisksList := AccountDisksList{}
|
accountDisksList := AccountDisksList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountDisksListCheckPresence(d *schema.ResourceData, m interface{})
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountDisksListCheckPresence: load account list")
|
log.Debugf("utilityAccountDisksListCheckPresence: load account list")
|
||||||
accountDisksListRaw, err := c.DecortAPICall("POST", accountListDisksAPI, urlValues)
|
accountDisksListRaw, err := c.DecortAPICall(ctx, "POST", accountListDisksAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) {
|
func utilityAccountFlipGroupsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountFlipGroupsList, error) {
|
||||||
accountFlipGroupsList := AccountFlipGroupsList{}
|
accountFlipGroupsList := AccountFlipGroupsList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountFlipGroupsListCheckPresence(d *schema.ResourceData, m interfa
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
|
log.Debugf("utilityAccountFlipGroupsListCheckPresence")
|
||||||
accountFlipGroupsListRaw, err := c.DecortAPICall("POST", accountListFlipGroupsAPI, urlValues)
|
accountFlipGroupsListRaw, err := c.DecortAPICall(ctx, "POST", accountListFlipGroupsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
func utilityAccountListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountCloudApiList, error) {
|
||||||
accountList := AccountCloudApiList{}
|
accountList := AccountCloudApiList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -55,7 +56,7 @@ func utilityAccountListCheckPresence(d *schema.ResourceData, m interface{}) (Acc
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityAccountListCheckPresence: load account list")
|
log.Debugf("utilityAccountListCheckPresence: load account list")
|
||||||
accountListRaw, err := c.DecortAPICall("POST", accountListAPI, urlValues)
|
accountListRaw, err := c.DecortAPICall(ctx, "POST", accountListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
func utilityAccountReservedUnitsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ResourceLimits, error) {
|
||||||
accountReservedUnits := &ResourceLimits{}
|
accountReservedUnits := &ResourceLimits{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountReservedUnitsCheckPresence(d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountReservedUnitsCheckPresence: load units")
|
log.Debugf("utilityAccountReservedUnitsCheckPresence: load units")
|
||||||
accountReservedUnitsRaw, err := c.DecortAPICall("POST", accountGetReservedUnitsAPI, urlValues)
|
accountReservedUnitsRaw, err := c.DecortAPICall(ctx, "POST", accountGetReservedUnitsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (AccountRGList, error) {
|
func utilityAccountRGListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountRGList, error) {
|
||||||
accountRGList := AccountRGList{}
|
accountRGList := AccountRGList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountRGListCheckPresence(d *schema.ResourceData, m interface{}) (A
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
log.Debugf("utilityAccountRGListCheckPresence: load account list")
|
||||||
accountRGListRaw, err := c.DecortAPICall("POST", accountListRGAPI, urlValues)
|
accountRGListRaw, err := c.DecortAPICall(ctx, "POST", accountListRGAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) {
|
func utilityAccountTemplatesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountTemplatesList, error) {
|
||||||
accountTemplatesList := AccountTemplatesList{}
|
accountTemplatesList := AccountTemplatesList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountTemplatesListCheckPresence(d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
log.Debugf("utilityAccountTemplatesListCheckPresence: load")
|
||||||
accountTemplatesListRaw, err := c.DecortAPICall("POST", accountListTemplatesAPI, urlValues)
|
accountTemplatesListRaw, err := c.DecortAPICall(ctx, "POST", accountListTemplatesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package account
|
package account
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{}) (AccountVinsList, error) {
|
func utilityAccountVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (AccountVinsList, error) {
|
||||||
accountVinsList := AccountVinsList{}
|
accountVinsList := AccountVinsList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityAccountVinsListCheckPresence(d *schema.ResourceData, m interface{})
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
log.Debugf("utilityAccountVinsListCheckPresence: load account list")
|
||||||
accountVinsListRaw, err := c.DecortAPICall("POST", accountListVinsAPI, urlValues)
|
accountVinsListRaw, err := c.DecortAPICall(ctx, "POST", accountListVinsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
bs, err := utilityBasicServiceCheckPresence(d, m)
|
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceBasicServiceDeletedListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(d, m)
|
basicServiceDeletedList, err := utilityBasicServiceDeletedListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
|
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func flattenBasicServiceList(bsl BasicServiceList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceBasicServiceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
basicServiceList, err := utilityBasicServiceListCheckPresence(d, m)
|
basicServiceList, err := utilityBasicServiceListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceBasicServiceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(d, m)
|
basicServiceSnapshotList, err := utilityBasicServiceSnapshotListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
log.Debugf("resourceBasicServiceCreate")
|
log.Debugf("resourceBasicServiceCreate")
|
||||||
|
|
||||||
if serviceId, ok := d.GetOk("service_id"); ok {
|
if serviceId, ok := d.GetOk("service_id"); ok {
|
||||||
if exists, err := resourceBasicServiceExists(d, m); exists {
|
if exists, err := resourceBasicServiceExists(ctx, d, m); exists {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
urlValues.Add("sshUser", sshUser.(string))
|
urlValues.Add("sshUser", sshUser.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceId, err := c.DecortAPICall("POST", bserviceCreateAPI, urlValues)
|
serviceId, err := c.DecortAPICall(ctx, "POST", bserviceCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,7 @@ func resourceBasicServiceCreate(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceBasicServiceRead")
|
log.Debugf("resourceBasicServiceRead")
|
||||||
|
|
||||||
bs, err := utilityBasicServiceCheckPresence(d, m)
|
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
|
||||||
if bs == nil {
|
if bs == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -143,7 +143,7 @@ func resourceBasicServiceRead(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceBasicServiceDelete")
|
log.Debugf("resourceBasicServiceDelete")
|
||||||
|
|
||||||
bs, err := utilityBasicServiceCheckPresence(d, m)
|
bs, err := utilityBasicServiceCheckPresence(ctx, d, m)
|
||||||
if bs == nil {
|
if bs == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -156,7 +156,7 @@ func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", bserviceDeleteAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", bserviceDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -165,10 +165,10 @@ func resourceBasicServiceDelete(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceBasicServiceExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceBasicServiceExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceBasicServiceExists")
|
log.Debugf("resourceBasicServiceExists")
|
||||||
|
|
||||||
bservice, err := utilityBasicServiceCheckPresence(d, m)
|
bservice, err := utilityBasicServiceCheckPresence(ctx, d, m)
|
||||||
if bservice == nil {
|
if bservice == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -192,7 +192,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
}
|
}
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
restore := d.Get("restore").(bool)
|
restore := d.Get("restore").(bool)
|
||||||
if restore {
|
if restore {
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
_, err := c.DecortAPICall("POST", bserviceRestoreAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceRestoreAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -221,7 +221,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
}
|
}
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -257,7 +257,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
snapshotConv := snapshot.(map[string]interface{})
|
snapshotConv := snapshot.(map[string]interface{})
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("label", snapshotConv["label"].(string))
|
urlValues.Add("label", snapshotConv["label"].(string))
|
||||||
_, err := c.DecortAPICall("POST", bserviceSnapshotDeleteAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -271,7 +271,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
snapshotConv := snapshot.(map[string]interface{})
|
snapshotConv := snapshot.(map[string]interface{})
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("label", snapshotConv["label"].(string))
|
urlValues.Add("label", snapshotConv["label"].(string))
|
||||||
_, err := c.DecortAPICall("POST", bserviceSnapshotCreateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -285,7 +285,7 @@ func resourceBasicServiceEdit(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
snapshotConv := snapshot.(map[string]interface{})
|
snapshotConv := snapshot.(map[string]interface{})
|
||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("label", snapshotConv["label"].(string))
|
urlValues.Add("label", snapshotConv["label"].(string))
|
||||||
_, err := c.DecortAPICall("POST", bserviceSnapshotRollbackAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotRollbackAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -545,7 +545,6 @@ func ResourceBasicService() *schema.Resource {
|
|||||||
ReadContext: resourceBasicServiceRead,
|
ReadContext: resourceBasicServiceRead,
|
||||||
UpdateContext: resourceBasicServiceEdit,
|
UpdateContext: resourceBasicServiceEdit,
|
||||||
DeleteContext: resourceBasicServiceDelete,
|
DeleteContext: resourceBasicServiceDelete,
|
||||||
Exists: resourceBasicServiceExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData
|
|||||||
|
|
||||||
if compgroupId, ok := d.GetOk("compgroup_id"); ok {
|
if compgroupId, ok := d.GetOk("compgroup_id"); ok {
|
||||||
if _, ok := d.GetOk("service_id"); ok {
|
if _, ok := d.GetOk("service_id"); ok {
|
||||||
if exists, err := resourceBasicServiceGroupExists(d, m); exists {
|
if exists, err := resourceBasicServiceGroupExists(ctx, d, m); exists {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData
|
|||||||
urlValues.Add("extnets", temp)
|
urlValues.Add("extnets", temp)
|
||||||
}
|
}
|
||||||
|
|
||||||
compgroupId, err := c.DecortAPICall("POST", bserviceGroupAddAPI, urlValues)
|
compgroupId, err := c.DecortAPICall(ctx, "POST", bserviceGroupAddAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ func resourceBasicServiceGroupCreate(ctx context.Context, d *schema.ResourceData
|
|||||||
func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceBasicServiceGroupRead")
|
log.Debugf("resourceBasicServiceGroupRead")
|
||||||
|
|
||||||
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
|
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
|
||||||
if bsg == nil {
|
if bsg == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -185,7 +185,7 @@ func resourceBasicServiceGroupRead(ctx context.Context, d *schema.ResourceData,
|
|||||||
func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceBasicServiceGroupDelete")
|
log.Debugf("resourceBasicServiceGroupDelete")
|
||||||
|
|
||||||
bsg, err := utilityBasicServiceGroupCheckPresence(d, m)
|
bsg, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
|
||||||
if bsg == nil {
|
if bsg == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -198,7 +198,7 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", bserviceGroupRemoveAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", bserviceGroupRemoveAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -207,10 +207,10 @@ func resourceBasicServiceGroupDelete(ctx context.Context, d *schema.ResourceData
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceBasicServiceGroupExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceBasicServiceGroupExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceBasicServiceGroupExists")
|
log.Debugf("resourceBasicServiceGroupExists")
|
||||||
|
|
||||||
bserviceGroup, err := utilityBasicServiceGroupCheckPresence(d, m)
|
bserviceGroup, err := utilityBasicServiceGroupCheckPresence(ctx, d, m)
|
||||||
if bserviceGroup == nil {
|
if bserviceGroup == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -232,7 +232,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int)))
|
urlValues.Add("count", strconv.Itoa(d.Get("comp_count").(int)))
|
||||||
urlValues.Add("mode", strings.ToUpper(d.Get("mode").(string)))
|
urlValues.Add("mode", strings.ToUpper(d.Get("mode").(string)))
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupResizeAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupResizeAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -251,7 +251,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupUpdateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -296,7 +296,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("extnets", temp)
|
urlValues.Add("extnets", temp)
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupUpdateExtnetAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateExtnetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -322,7 +322,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("vinses", temp)
|
urlValues.Add("vinses", temp)
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupUpdateVinsAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupUpdateVinsAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -356,7 +356,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("parentId", strconv.Itoa(parentConv))
|
urlValues.Add("parentId", strconv.Itoa(parentConv))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupParentRemoveAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentRemoveAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -371,7 +371,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
urlValues.Add("serviceId", strconv.Itoa(d.Get("service_id").(int)))
|
||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("parentId", strconv.Itoa(parentConv))
|
urlValues.Add("parentId", strconv.Itoa(parentConv))
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupParentAddAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupParentAddAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -389,7 +389,7 @@ func resourceBasicServiceGroupEdit(ctx context.Context, d *schema.ResourceData,
|
|||||||
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
urlValues.Add("compgroupId", strconv.Itoa(d.Get("compgroup_id").(int)))
|
||||||
urlValues.Add("computeId", strconv.Itoa(rc.(int)))
|
urlValues.Add("computeId", strconv.Itoa(rc.(int)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", bserviceGroupComputeRemoveAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", bserviceGroupComputeRemoveAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -652,7 +652,6 @@ func ResourceBasicServiceGroup() *schema.Resource {
|
|||||||
ReadContext: resourceBasicServiceGroupRead,
|
ReadContext: resourceBasicServiceGroupRead,
|
||||||
UpdateContext: resourceBasicServiceGroupEdit,
|
UpdateContext: resourceBasicServiceGroupEdit,
|
||||||
DeleteContext: resourceBasicServiceGroupDelete,
|
DeleteContext: resourceBasicServiceGroupDelete,
|
||||||
Exists: resourceBasicServiceGroupExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
|
func utilityBasicServiceDeletedListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
|
||||||
basicServiceDeletedList := BasicServiceList{}
|
basicServiceDeletedList := BasicServiceList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -61,7 +62,7 @@ func utilityBasicServiceDeletedListCheckPresence(d *schema.ResourceData, m inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityBasicServiceDeletedListCheckPresence")
|
log.Debugf("utilityBasicServiceDeletedListCheckPresence")
|
||||||
basicServiceDeletedListRaw, err := c.DecortAPICall("POST", bserviceListDeletedAPI, urlValues)
|
basicServiceDeletedListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListDeletedAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) {
|
func utilityBasicServiceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceExtend, error) {
|
||||||
bservice := &BasicServiceExtend{}
|
bservice := &BasicServiceExtend{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -54,7 +55,7 @@ func utilityBasicServiceCheckPresence(d *schema.ResourceData, m interface{}) (*B
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityBasicServiceCheckPresence")
|
log.Debugf("utilityBasicServiceCheckPresence")
|
||||||
bserviceRaw, err := c.DecortAPICall("POST", bserviceGetAPI, urlValues)
|
bserviceRaw, err := c.DecortAPICall(ctx, "POST", bserviceGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) {
|
func utilityBasicServiceGroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*BasicServiceGroup, error) {
|
||||||
bserviceGroup := &BasicServiceGroup{}
|
bserviceGroup := &BasicServiceGroup{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -55,7 +56,7 @@ func utilityBasicServiceGroupCheckPresence(d *schema.ResourceData, m interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityBasicServiceGroupCheckPresence")
|
log.Debugf("utilityBasicServiceGroupCheckPresence")
|
||||||
bserviceGroupRaw, err := c.DecortAPICall("POST", bserviceGroupGetAPI, urlValues)
|
bserviceGroupRaw, err := c.DecortAPICall(ctx, "POST", bserviceGroupGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
|
func utilityBasicServiceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceList, error) {
|
||||||
basicServiceList := BasicServiceList{}
|
basicServiceList := BasicServiceList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -61,7 +62,7 @@ func utilityBasicServiceListCheckPresence(d *schema.ResourceData, m interface{})
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityBasicServiceListCheckPresence")
|
log.Debugf("utilityBasicServiceListCheckPresence")
|
||||||
basicServiceListRaw, err := c.DecortAPICall("POST", bserviceListAPI, urlValues)
|
basicServiceListRaw, err := c.DecortAPICall(ctx, "POST", bserviceListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package bservice
|
package bservice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) {
|
func utilityBasicServiceSnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (BasicServiceSnapshots, error) {
|
||||||
basicServiceSnapshotList := BasicServiceSnapshots{}
|
basicServiceSnapshotList := BasicServiceSnapshots{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -52,7 +53,7 @@ func utilityBasicServiceSnapshotListCheckPresence(d *schema.ResourceData, m inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityBasicServiceSnapshotListCheckPresence")
|
log.Debugf("utilityBasicServiceSnapshotListCheckPresence")
|
||||||
basicServiceSnapshotListRaw, err := c.DecortAPICall("POST", bserviceSnapshotListAPI, urlValues)
|
basicServiceSnapshotListRaw, err := c.DecortAPICall(ctx, "POST", bserviceSnapshotListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ func flattenDisk(d *schema.ResourceData, disk_facts string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
disk_facts, err := utilityDiskCheckPresence(d, m)
|
disk_facts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||||
if disk_facts == "" {
|
if disk_facts == "" {
|
||||||
// if empty string is returned from utilityDiskCheckPresence then there is no
|
// if empty string is returned from utilityDiskCheckPresence then there is no
|
||||||
// such Disk and err tells so - just return it to the calling party
|
// such Disk and err tells so - just return it to the calling party
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ func flattendDiskSnapshotList(sl SnapshotRecordList) []interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceDiskListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
diskList, err := utilityDiskListCheckPresence(d, m)
|
diskList, err := utilityDiskListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
urlValues.Add("description", argVal.(string))
|
urlValues.Add("description", argVal.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
apiResp, err := c.DecortAPICall("POST", DisksCreateAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", DisksCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ func resourceDiskCreate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceDiskRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||||
if diskFacts == "" {
|
if diskFacts == "" {
|
||||||
// if empty string is returned from utilityDiskCheckPresence then there is no
|
// if empty string is returned from utilityDiskCheckPresence then there is no
|
||||||
// such Disk and err tells so - just return it to the calling party
|
// such Disk and err tells so - just return it to the calling party
|
||||||
@@ -121,7 +121,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
sizeParams := &url.Values{}
|
sizeParams := &url.Values{}
|
||||||
sizeParams.Add("diskId", d.Id())
|
sizeParams.Add("diskId", d.Id())
|
||||||
sizeParams.Add("size", fmt.Sprintf("%d", newSize.(int)))
|
sizeParams.Add("size", fmt.Sprintf("%d", newSize.(int)))
|
||||||
_, err := c.DecortAPICall("POST", DisksResizeAPI, sizeParams)
|
_, err := c.DecortAPICall(ctx, "POST", DisksResizeAPI, sizeParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ func resourceDiskUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
renameParams := &url.Values{}
|
renameParams := &url.Values{}
|
||||||
renameParams.Add("diskId", d.Id())
|
renameParams.Add("diskId", d.Id())
|
||||||
renameParams.Add("name", newName.(string))
|
renameParams.Add("name", newName.(string))
|
||||||
_, err := c.DecortAPICall("POST", DisksRenameAPI, renameParams)
|
_, err := c.DecortAPICall(ctx, "POST", DisksRenameAPI, renameParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
log.Debugf("resourceDiskDelete: called for Disk ID / name %d / %s, Account ID %d",
|
log.Debugf("resourceDiskDelete: called for Disk ID / name %d / %s, Account ID %d",
|
||||||
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
||||||
|
|
||||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||||
if diskFacts == "" {
|
if diskFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -187,7 +187,7 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
params.Add("permanently", "1")
|
params.Add("permanently", "1")
|
||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
_, err = c.DecortAPICall("POST", DisksDeleteAPI, params)
|
_, err = c.DecortAPICall(ctx, "POST", DisksDeleteAPI, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -195,12 +195,12 @@ func resourceDiskDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceDiskExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceDiskExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
||||||
log.Debugf("resourceDiskExists: called for Disk ID / name %d / %s, Account ID %d",
|
log.Debugf("resourceDiskExists: called for Disk ID / name %d / %s, Account ID %d",
|
||||||
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
d.Get("disk_id").(int), d.Get("name").(string), d.Get("account_id").(int))
|
||||||
|
|
||||||
diskFacts, err := utilityDiskCheckPresence(d, m)
|
diskFacts, err := utilityDiskCheckPresence(ctx, d, m)
|
||||||
if diskFacts == "" {
|
if diskFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -320,7 +320,6 @@ func ResourceDisk() *schema.Resource {
|
|||||||
ReadContext: resourceDiskRead,
|
ReadContext: resourceDiskRead,
|
||||||
UpdateContext: resourceDiskUpdate,
|
UpdateContext: resourceDiskUpdate,
|
||||||
DeleteContext: resourceDiskDelete,
|
DeleteContext: resourceDiskDelete,
|
||||||
Exists: resourceDiskExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package disks
|
package disks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -43,7 +44,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
func utilityDiskCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||||
// This function tries to locate Disk by one of the following algorithms depending on
|
// This function tries to locate Disk by one of the following algorithms depending on
|
||||||
// the parameters passed:
|
// the parameters passed:
|
||||||
// - if disk ID is specified -> by disk ID
|
// - if disk ID is specified -> by disk ID
|
||||||
@@ -81,7 +82,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
|||||||
// disk ID is specified, try to get disk instance straight by this ID
|
// disk ID is specified, try to get disk instance straight by this ID
|
||||||
log.Debugf("utilityDiskCheckPresence: locating disk by its ID %d", theId)
|
log.Debugf("utilityDiskCheckPresence: locating disk by its ID %d", theId)
|
||||||
urlValues.Add("diskId", fmt.Sprintf("%d", theId))
|
urlValues.Add("diskId", fmt.Sprintf("%d", theId))
|
||||||
diskFacts, err := c.DecortAPICall("POST", DisksGetAPI, urlValues)
|
diskFacts, err := c.DecortAPICall(ctx, "POST", DisksGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -100,7 +101,7 @@ func utilityDiskCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
|||||||
// obtain Account ID by account name - it should not be zero on success
|
// obtain Account ID by account name - it should not be zero on success
|
||||||
|
|
||||||
urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int)))
|
urlValues.Add("accountId", fmt.Sprintf("%d", d.Get("account_id").(int)))
|
||||||
diskFacts, err := c.DecortAPICall("POST", DisksListAPI, urlValues)
|
diskFacts, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package disks
|
package disks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -43,7 +44,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksListResp, error) {
|
func utilityDiskListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (DisksListResp, error) {
|
||||||
diskList := DisksListResp{}
|
diskList := DisksListResp{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -62,7 +63,7 @@ func utilityDiskListCheckPresence(d *schema.ResourceData, m interface{}) (DisksL
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityDiskListCheckPresence: load grid list")
|
log.Debugf("utilityDiskListCheckPresence: load grid list")
|
||||||
diskListRaw, err := c.DecortAPICall("POST", DisksListAPI, urlValues)
|
diskListRaw, err := c.DecortAPICall(ctx, "POST", DisksListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceExtnetRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
e, err := utilityExtnetCheckPresence(d, m)
|
e, err := utilityExtnetCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ func flattenExtnetComputesList(ecl ExtnetComputesList) []map[string]interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceExtnetComputesListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
extnetComputesList, err := utilityExtnetComputesListCheckPresence(d, m)
|
extnetComputesList, err := utilityExtnetComputesListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceExtnetDefaultRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
extnetId, err := utilityExtnetDefaultCheckPresence(d, m)
|
extnetId, err := utilityExtnetDefaultCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func flattenExtnetList(el ExtnetList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceExtnetListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
extnetList, err := utilityExtnetListCheckPresence(d, m)
|
extnetList, err := utilityExtnetListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetCheckPresence(d *schema.ResourceData, m interface{}) (*ExtnetDetailed, error) {
|
func utilityExtnetCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*ExtnetDetailed, error) {
|
||||||
extnet := &ExtnetDetailed{}
|
extnet := &ExtnetDetailed{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityExtnetCheckPresence(d *schema.ResourceData, m interface{}) (*ExtnetD
|
|||||||
urlValues.Add("net_id", strconv.Itoa(d.Get("net_id").(int)))
|
urlValues.Add("net_id", strconv.Itoa(d.Get("net_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityExtnetCheckPresence")
|
log.Debugf("utilityExtnetCheckPresence")
|
||||||
extnetRaw, err := c.DecortAPICall("POST", extnetGetAPI, urlValues)
|
extnetRaw, err := c.DecortAPICall(ctx, "POST", extnetGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetComputesListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetComputesList, error) {
|
func utilityExtnetComputesListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ExtnetComputesList, error) {
|
||||||
extnetComputesList := ExtnetComputesList{}
|
extnetComputesList := ExtnetComputesList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityExtnetComputesListCheckPresence(d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
urlValues.Add("accountId", strconv.Itoa(d.Get("account_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityExtnetComputesListCheckPresence")
|
log.Debugf("utilityExtnetComputesListCheckPresence")
|
||||||
extnetComputesListRaw, err := c.DecortAPICall("POST", extnetListComputesAPI, urlValues)
|
extnetComputesListRaw, err := c.DecortAPICall(ctx, "POST", extnetListComputesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
@@ -40,12 +41,12 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetDefaultCheckPresence(_ *schema.ResourceData, m interface{}) (string, error) {
|
func utilityExtnetDefaultCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
log.Debugf("utilityExtnetDefaultCheckPresence")
|
log.Debugf("utilityExtnetDefaultCheckPresence")
|
||||||
res, err := c.DecortAPICall("POST", extnetGetDefaultAPI, urlValues)
|
res, err := c.DecortAPICall(ctx, "POST", extnetGetDefaultAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package extnet
|
package extnet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (ExtnetList, error) {
|
func utilityExtnetListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ExtnetList, error) {
|
||||||
extnetList := ExtnetList{}
|
extnetList := ExtnetList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -58,7 +59,7 @@ func utilityExtnetListCheckPresence(d *schema.ResourceData, m interface{}) (Extn
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityExtnetListCheckPresence")
|
log.Debugf("utilityExtnetListCheckPresence")
|
||||||
extnetListRaw, err := c.DecortAPICall("POST", extnetListAPI, urlValues)
|
extnetListRaw, err := c.DecortAPICall(ctx, "POST", extnetListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
//urlValues.Add("desc", desc.(string))
|
//urlValues.Add("desc", desc.(string))
|
||||||
//}
|
//}
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", K8sCreateAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", K8sCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("auditId", strings.Trim(resp, `"`))
|
urlValues.Add("auditId", strings.Trim(resp, `"`))
|
||||||
|
|
||||||
for {
|
for {
|
||||||
resp, err := c.DecortAPICall("POST", AsyncTaskGetAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", AsyncTaskGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
k8s, err := utilityK8sCheckPresence(d, m)
|
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -136,7 +136,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues = &url.Values{}
|
urlValues = &url.Values{}
|
||||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||||
|
|
||||||
resp, err = c.DecortAPICall("POST", LbGetAPI, urlValues)
|
resp, err = c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
|
|
||||||
urlValues = &url.Values{}
|
urlValues = &url.Values{}
|
||||||
urlValues.Add("k8sId", d.Id())
|
urlValues.Add("k8sId", d.Id())
|
||||||
kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues)
|
kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("could not get kubeconfig: %v", err)
|
log.Warnf("could not get kubeconfig: %v", err)
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ func resourceK8sCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
log.Debugf("resourceK8sRead: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||||
|
|
||||||
k8s, err := utilityK8sCheckPresence(d, m)
|
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||||
if k8s == nil {
|
if k8s == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -180,7 +180,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
urlValues.Add("lbId", strconv.Itoa(k8s.LbID))
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", LbGetAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", LbGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ func resourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
|
|
||||||
urlValues = &url.Values{}
|
urlValues = &url.Values{}
|
||||||
urlValues.Add("k8sId", d.Id())
|
urlValues.Add("k8sId", d.Id())
|
||||||
kubeconfig, err := c.DecortAPICall("POST", K8sGetConfigAPI, urlValues)
|
kubeconfig, err := c.DecortAPICall(ctx, "POST", K8sGetConfigAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("could not get kubeconfig: %v", err)
|
log.Warnf("could not get kubeconfig: %v", err)
|
||||||
}
|
}
|
||||||
@@ -213,14 +213,14 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("k8sId", d.Id())
|
urlValues.Add("k8sId", d.Id())
|
||||||
urlValues.Add("name", d.Get("name").(string))
|
urlValues.Add("name", d.Get("name").(string))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", K8sUpdateAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", K8sUpdateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("workers") {
|
if d.HasChange("workers") {
|
||||||
k8s, err := utilityK8sCheckPresence(d, m)
|
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -234,13 +234,13 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
|
|
||||||
if newWorkers.Num > wg.Num {
|
if newWorkers.Num > wg.Num {
|
||||||
urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num))
|
urlValues.Add("num", strconv.Itoa(newWorkers.Num-wg.Num))
|
||||||
if _, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues); err != nil {
|
if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues); err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for i := wg.Num - 1; i >= newWorkers.Num; i-- {
|
for i := wg.Num - 1; i >= newWorkers.Num; i-- {
|
||||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||||
if _, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues); err != nil {
|
if _, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues); err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ func resourceK8sUpdate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
log.Debugf("resourceK8sDelete: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||||
|
|
||||||
k8s, err := utilityK8sCheckPresence(d, m)
|
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||||
if k8s == nil {
|
if k8s == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -266,7 +266,7 @@ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("k8sId", d.Id())
|
urlValues.Add("k8sId", d.Id())
|
||||||
urlValues.Add("permanently", "true")
|
urlValues.Add("permanently", "true")
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", K8sDeleteAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", K8sDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -274,10 +274,10 @@ func resourceK8sDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceK8sExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceK8sExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceK8sExists: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
log.Debugf("resourceK8sExists: called with id %s, rg %d", d.Id(), d.Get("rg_id").(int))
|
||||||
|
|
||||||
k8s, err := utilityK8sCheckPresence(d, m)
|
k8s, err := utilityK8sCheckPresence(ctx, d, m)
|
||||||
if k8s == nil {
|
if k8s == nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -385,7 +385,6 @@ func ResourceK8s() *schema.Resource {
|
|||||||
ReadContext: resourceK8sRead,
|
ReadContext: resourceK8sRead,
|
||||||
UpdateContext: resourceK8sUpdate,
|
UpdateContext: resourceK8sUpdate,
|
||||||
DeleteContext: resourceK8sDelete,
|
DeleteContext: resourceK8sDelete,
|
||||||
Exists: resourceK8sExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("workerRam", strconv.Itoa(d.Get("ram").(int)))
|
urlValues.Add("workerRam", strconv.Itoa(d.Get("ram").(int)))
|
||||||
urlValues.Add("workerDisk", strconv.Itoa(d.Get("disk").(int)))
|
urlValues.Add("workerDisk", strconv.Itoa(d.Get("disk").(int)))
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", K8sWgCreateAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", K8sWgCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -97,7 +97,7 @@ func resourceK8sWgCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceK8sWgRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
|
log.Debugf("resourceK8sWgRead: called with k8s id %d", d.Get("k8s_id").(int))
|
||||||
|
|
||||||
wg, err := utilityK8sWgCheckPresence(d, m)
|
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
|
||||||
if wg == nil {
|
if wg == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -117,7 +117,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
|
|
||||||
wg, err := utilityK8sWgCheckPresence(d, m)
|
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -128,14 +128,14 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
|
|
||||||
if newNum := d.Get("num").(int); newNum > wg.Num {
|
if newNum := d.Get("num").(int); newNum > wg.Num {
|
||||||
urlValues.Add("num", strconv.Itoa(newNum-wg.Num))
|
urlValues.Add("num", strconv.Itoa(newNum-wg.Num))
|
||||||
_, err := c.DecortAPICall("POST", K8sWorkerAddAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", K8sWorkerAddAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for i := wg.Num - 1; i >= newNum; i-- {
|
for i := wg.Num - 1; i >= newNum; i-- {
|
||||||
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
urlValues.Set("workerId", strconv.Itoa(wg.DetailedInfo[i].ID))
|
||||||
_, err := c.DecortAPICall("POST", K8sWorkerDeleteAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", K8sWorkerDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ func resourceK8sWgUpdate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int))
|
log.Debugf("resourceK8sWgDelete: called with k8s id %d", d.Get("k8s_id").(int))
|
||||||
|
|
||||||
wg, err := utilityK8sWgCheckPresence(d, m)
|
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
|
||||||
if wg == nil {
|
if wg == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -161,7 +161,7 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||||
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
|
urlValues.Add("workersGroupId", strconv.Itoa(wg.ID))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", K8sWgDeleteAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", K8sWgDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -169,10 +169,10 @@ func resourceK8sWgDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceK8sWgExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceK8sWgExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceK8sWgExists: called with k8s id %d", d.Get("k8s_id").(int))
|
log.Debugf("resourceK8sWgExists: called with k8s id %d", d.Get("k8s_id").(int))
|
||||||
|
|
||||||
wg, err := utilityK8sWgCheckPresence(d, m)
|
wg, err := utilityK8sWgCheckPresence(ctx, d, m)
|
||||||
if wg == nil {
|
if wg == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -240,7 +240,6 @@ func ResourceK8sWg() *schema.Resource {
|
|||||||
ReadContext: resourceK8sWgRead,
|
ReadContext: resourceK8sWgRead,
|
||||||
UpdateContext: resourceK8sWgUpdate,
|
UpdateContext: resourceK8sWgUpdate,
|
||||||
DeleteContext: resourceK8sWgDelete,
|
DeleteContext: resourceK8sWgDelete,
|
||||||
Exists: resourceK8sWgExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityK8sCheckPresence(d *schema.ResourceData, m interface{}) (*K8sRecord, error) {
|
func utilityK8sCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sRecord, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("k8sId", d.Id())
|
urlValues.Add("k8sId", d.Id())
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package k8s
|
package k8s
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -40,12 +41,12 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityK8sWgCheckPresence(d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) {
|
func utilityK8sWgCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*K8sNodeRecord, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
urlValues.Add("k8sId", strconv.Itoa(d.Get("k8s_id").(int)))
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", K8sGetAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", K8sGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -196,7 +196,7 @@ func flattenCompute(d *schema.ResourceData, compFacts string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceComputeRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
compFacts, err := utilityComputeCheckPresence(d, m)
|
compFacts, err := utilityComputeCheckPresence(ctx, d, m)
|
||||||
if compFacts == "" {
|
if compFacts == "" {
|
||||||
// if empty string is returned from utilityComputeCheckPresence then there is no
|
// if empty string is returned from utilityComputeCheckPresence then there is no
|
||||||
// such Compute and err tells so - just return it to the calling party
|
// such Compute and err tells so - just return it to the calling party
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
apiResp, err := c.DecortAPICall("POST", computeCreateAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", computeCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -124,41 +124,26 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
log.Debugf("resourceComputeCreate: new simple Compute ID %d, name %s created", compId, d.Get("name").(string))
|
log.Debugf("resourceComputeCreate: new simple Compute ID %d, name %s created", compId, d.Get("name").(string))
|
||||||
|
|
||||||
// Configure data disks if any
|
// Configure data disks if any
|
||||||
extraDisksOk := true
|
|
||||||
argVal, argSet = d.GetOk("extra_disks")
|
argVal, argSet = d.GetOk("extra_disks")
|
||||||
if argSet && argVal.(*schema.Set).Len() > 0 {
|
if argSet && argVal.(*schema.Set).Len() > 0 {
|
||||||
// urlValues.Add("desc", argVal.(string))
|
// urlValues.Add("desc", argVal.(string))
|
||||||
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
|
log.Debugf("resourceComputeCreate: calling utilityComputeExtraDisksConfigure to attach %d extra disk(s)", argVal.(*schema.Set).Len())
|
||||||
err = utilityComputeExtraDisksConfigure(d, m, false) // do_delta=false, as we are working on a new compute
|
err = utilityComputeExtraDisksConfigure(ctx, d, m, false) // do_delta=false, as we are working on a new compute
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", compId, err)
|
log.Errorf("resourceComputeCreate: error when attaching extra disk(s) to a new Compute ID %d: %v", compId, err)
|
||||||
extraDisksOk = false
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if extraDisksOk {
|
|
||||||
d.SetPartial("extra_disks")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Configure external networks if any
|
// Configure external networks if any
|
||||||
netsOk := true
|
|
||||||
argVal, argSet = d.GetOk("network")
|
argVal, argSet = d.GetOk("network")
|
||||||
if argSet && argVal.(*schema.Set).Len() > 0 {
|
if argSet && argVal.(*schema.Set).Len() > 0 {
|
||||||
log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len())
|
log.Debugf("resourceComputeCreate: calling utilityComputeNetworksConfigure to attach %d network(s)", argVal.(*schema.Set).Len())
|
||||||
err = utilityComputeNetworksConfigure(d, m, false) // do_delta=false, as we are working on a new compute
|
err = utilityComputeNetworksConfigure(ctx, d, m, false) // do_delta=false, as we are working on a new compute
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", compId, err)
|
log.Errorf("resourceComputeCreate: error when attaching networks to a new Compute ID %d: %s", compId, err)
|
||||||
netsOk = false
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if netsOk {
|
|
||||||
// there were no errors reported when configuring networks
|
|
||||||
d.SetPartial("network")
|
|
||||||
}
|
|
||||||
|
|
||||||
if extraDisksOk && netsOk {
|
|
||||||
// if there were no errors in setting any of the subresources, we may leave Partial mode
|
|
||||||
d.Partial(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
|
// Note bene: we created compute in a STOPPED state (this is required to properly attach 1st network interface),
|
||||||
// now we need to start it before we report the sequence complete
|
// now we need to start it before we report the sequence complete
|
||||||
@@ -166,7 +151,7 @@ func resourceComputeCreate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
reqValues := &url.Values{}
|
reqValues := &url.Values{}
|
||||||
reqValues.Add("computeId", fmt.Sprintf("%d", compId))
|
reqValues.Add("computeId", fmt.Sprintf("%d", compId))
|
||||||
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId)
|
log.Debugf("resourceComputeCreate: starting Compute ID %d after completing its resource configuration", compId)
|
||||||
if _, err := c.DecortAPICall("POST", ComputeStartAPI, reqValues); err != nil {
|
if _, err := c.DecortAPICall(ctx, "POST", ComputeStartAPI, reqValues); err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -184,7 +169,7 @@ func resourceComputeRead(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d",
|
log.Debugf("resourceComputeRead: called for Compute name %s, RG ID %d",
|
||||||
d.Get("name").(string), d.Get("rg_id").(int))
|
d.Get("name").(string), d.Get("rg_id").(int))
|
||||||
|
|
||||||
compFacts, err := utilityComputeCheckPresence(d, m)
|
compFacts, err := utilityComputeCheckPresence(ctx, d, m)
|
||||||
if compFacts == "" {
|
if compFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -222,8 +207,6 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
doUpdate := false
|
doUpdate := false
|
||||||
params.Add("computeId", d.Id())
|
params.Add("computeId", d.Id())
|
||||||
|
|
||||||
d.Partial(true)
|
|
||||||
|
|
||||||
oldCpu, newCpu := d.GetChange("cpu")
|
oldCpu, newCpu := d.GetChange("cpu")
|
||||||
if oldCpu.(int) != newCpu.(int) {
|
if oldCpu.(int) != newCpu.(int) {
|
||||||
params.Add("cpu", fmt.Sprintf("%d", newCpu.(int)))
|
params.Add("cpu", fmt.Sprintf("%d", newCpu.(int)))
|
||||||
@@ -245,13 +228,10 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
oldCpu.(int), newCpu.(int),
|
oldCpu.(int), newCpu.(int),
|
||||||
oldRam.(int), newRam.(int))
|
oldRam.(int), newRam.(int))
|
||||||
params.Add("force", "true")
|
params.Add("force", "true")
|
||||||
_, err := c.DecortAPICall("POST", ComputeResizeAPI, params)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeResizeAPI, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetPartial("cpu")
|
|
||||||
d.SetPartial("ram")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Resize (grow) Boot disk
|
// 2. Resize (grow) Boot disk
|
||||||
@@ -262,23 +242,22 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
bdsParams.Add("size", fmt.Sprintf("%d", newSize.(int)))
|
bdsParams.Add("size", fmt.Sprintf("%d", newSize.(int)))
|
||||||
log.Debugf("resourceComputeUpdate: compute ID %s, boot disk ID %d resize %d -> %d",
|
log.Debugf("resourceComputeUpdate: compute ID %s, boot disk ID %d resize %d -> %d",
|
||||||
d.Id(), d.Get("boot_disk_id").(int), oldSize.(int), newSize.(int))
|
d.Id(), d.Get("boot_disk_id").(int), oldSize.(int), newSize.(int))
|
||||||
_, err := c.DecortAPICall("POST", DisksResizeAPI, bdsParams)
|
_, err := c.DecortAPICall(ctx, "POST", DisksResizeAPI, bdsParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
d.SetPartial("boot_disk_size")
|
|
||||||
} else if oldSize.(int) > newSize.(int) {
|
} else if oldSize.(int) > newSize.(int) {
|
||||||
log.Warnf("resourceComputeUpdate: compute ID %s - shrinking boot disk is not allowed", d.Id())
|
log.Warnf("resourceComputeUpdate: compute ID %s - shrinking boot disk is not allowed", d.Id())
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Calculate and apply changes to data disks
|
// 3. Calculate and apply changes to data disks
|
||||||
err := utilityComputeExtraDisksConfigure(d, m, true) // pass do_delta = true to apply changes, if any
|
err := utilityComputeExtraDisksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4. Calculate and apply changes to network connections
|
// 4. Calculate and apply changes to network connections
|
||||||
err = utilityComputeNetworksConfigure(d, m, true) // pass do_delta = true to apply changes, if any
|
err = utilityComputeNetworksConfigure(ctx, d, m, true) // pass do_delta = true to apply changes, if any
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -287,11 +266,11 @@ func resourceComputeUpdate(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
params := &url.Values{}
|
params := &url.Values{}
|
||||||
params.Add("computeId", d.Id())
|
params.Add("computeId", d.Id())
|
||||||
if d.Get("started").(bool) {
|
if d.Get("started").(bool) {
|
||||||
if _, err := c.DecortAPICall("POST", ComputeStartAPI, params); err != nil {
|
if _, err := c.DecortAPICall(ctx, "POST", ComputeStartAPI, params); err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if _, err := c.DecortAPICall("POST", ComputeStopAPI, params); err != nil {
|
if _, err := c.DecortAPICall(ctx, "POST", ComputeStopAPI, params); err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -310,7 +289,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
log.Debugf("resourceComputeDelete: called for Compute name %s, RG ID %d",
|
log.Debugf("resourceComputeDelete: called for Compute name %s, RG ID %d",
|
||||||
d.Get("name").(string), d.Get("rg_id").(int))
|
d.Get("name").(string), d.Get("rg_id").(int))
|
||||||
|
|
||||||
compFacts, err := utilityComputeCheckPresence(d, m)
|
compFacts, err := utilityComputeCheckPresence(ctx, d, m)
|
||||||
if compFacts == "" {
|
if compFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -340,7 +319,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
detachParams.Add("computeId", d.Id())
|
detachParams.Add("computeId", d.Id())
|
||||||
detachParams.Add("diskId", fmt.Sprintf("%d", diskFacts.ID))
|
detachParams.Add("diskId", fmt.Sprintf("%d", diskFacts.ID))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", ComputeDiskDetachAPI, detachParams)
|
_, err = c.DecortAPICall(ctx, "POST", ComputeDiskDetachAPI, detachParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// We do not fail compute deletion on data disk detach errors
|
// We do not fail compute deletion on data disk detach errors
|
||||||
log.Errorf("resourceComputeDelete: error when detaching Disk ID %d: %s", diskFacts.ID, err)
|
log.Errorf("resourceComputeDelete: error when detaching Disk ID %d: %s", diskFacts.ID, err)
|
||||||
@@ -353,7 +332,7 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
params.Add("permanently", "1")
|
params.Add("permanently", "1")
|
||||||
// TODO: this is for the upcoming API update - params.Add("detachdisks", "1")
|
// TODO: this is for the upcoming API update - params.Add("detachdisks", "1")
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", ComputeDeleteAPI, params)
|
_, err = c.DecortAPICall(ctx, "POST", ComputeDeleteAPI, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -361,12 +340,12 @@ func resourceComputeDelete(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceComputeExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceComputeExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
||||||
log.Debugf("resourceComputeExist: called for Compute name %s, RG ID %d",
|
log.Debugf("resourceComputeExist: called for Compute name %s, RG ID %d",
|
||||||
d.Get("name").(string), d.Get("rg_id").(int))
|
d.Get("name").(string), d.Get("rg_id").(int))
|
||||||
|
|
||||||
compFacts, err := utilityComputeCheckPresence(d, m)
|
compFacts, err := utilityComputeCheckPresence(ctx, d, m)
|
||||||
if compFacts == "" {
|
if compFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -384,7 +363,6 @@ func ResourceCompute() *schema.Resource {
|
|||||||
ReadContext: resourceComputeRead,
|
ReadContext: resourceComputeRead,
|
||||||
UpdateContext: resourceComputeUpdate,
|
UpdateContext: resourceComputeUpdate,
|
||||||
DeleteContext: resourceComputeDelete,
|
DeleteContext: resourceComputeDelete,
|
||||||
Exists: resourceComputeExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package kvmvm
|
package kvmvm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -43,7 +44,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error {
|
func utilityComputeExtraDisksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||||
// d is filled with data according to computeResource schema, so extra disks config is retrieved via "extra_disks" key
|
// d is filled with data according to computeResource schema, so extra disks config is retrieved via "extra_disks" key
|
||||||
// If do_delta is true, this function will identify changes between new and existing specs for extra disks and try to
|
// If do_delta is true, this function will identify changes between new and existing specs for extra disks and try to
|
||||||
// update compute configuration accordingly
|
// update compute configuration accordingly
|
||||||
@@ -71,7 +72,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do
|
|||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("computeId", d.Id())
|
urlValues.Add("computeId", d.Id())
|
||||||
urlValues.Add("diskId", fmt.Sprintf("%d", disk.(int)))
|
urlValues.Add("diskId", fmt.Sprintf("%d", disk.(int)))
|
||||||
_, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to attach extra disk - partial resource update
|
// failed to attach extra disk - partial resource update
|
||||||
apiErrCount++
|
apiErrCount++
|
||||||
@@ -94,7 +95,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do
|
|||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("computeId", d.Id())
|
urlValues.Add("computeId", d.Id())
|
||||||
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
||||||
_, err := c.DecortAPICall("POST", ComputeDiskDetachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskDetachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to detach disk - there will be partial resource update
|
// failed to detach disk - there will be partial resource update
|
||||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err)
|
log.Errorf("utilityComputeExtraDisksConfigure: failed to detach disk ID %d from Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||||
@@ -109,7 +110,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do
|
|||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("computeId", d.Id())
|
urlValues.Add("computeId", d.Id())
|
||||||
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
urlValues.Add("diskId", fmt.Sprintf("%d", diskId.(int)))
|
||||||
_, err := c.DecortAPICall("POST", ComputeDiskAttachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeDiskAttachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to attach disk - there will be partial resource update
|
// failed to attach disk - there will be partial resource update
|
||||||
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
log.Errorf("utilityComputeExtraDisksConfigure: failed to attach disk ID %d to Compute ID %s: %s", diskId.(int), d.Id(), err)
|
||||||
@@ -127,7 +128,7 @@ func utilityComputeExtraDisksConfigure(d *schema.ResourceData, m interface{}, do
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_delta bool) error {
|
func utilityComputeNetworksConfigure(ctx context.Context, d *schema.ResourceData, m interface{}, do_delta bool) error {
|
||||||
// "d" is filled with data according to computeResource schema, so extra networks config is retrieved via "network" key
|
// "d" is filled with data according to computeResource schema, so extra networks config is retrieved via "network" key
|
||||||
// If do_delta is true, this function will identify changes between new and existing specs for network and try to
|
// If do_delta is true, this function will identify changes between new and existing specs for network and try to
|
||||||
// update compute configuration accordingly
|
// update compute configuration accordingly
|
||||||
@@ -156,7 +157,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d
|
|||||||
if ipSet {
|
if ipSet {
|
||||||
urlValues.Add("ipAddr", ipaddr.(string))
|
urlValues.Add("ipAddr", ipaddr.(string))
|
||||||
}
|
}
|
||||||
_, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to attach network - partial resource update
|
// failed to attach network - partial resource update
|
||||||
apiErrCount++
|
apiErrCount++
|
||||||
@@ -180,7 +181,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d
|
|||||||
urlValues.Add("computeId", d.Id())
|
urlValues.Add("computeId", d.Id())
|
||||||
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
||||||
urlValues.Add("mac", net_data["mac"].(string))
|
urlValues.Add("mac", net_data["mac"].(string))
|
||||||
_, err := c.DecortAPICall("POST", ComputeNetDetachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeNetDetachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to detach this network - there will be partial resource update
|
// failed to detach this network - there will be partial resource update
|
||||||
log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s",
|
log.Errorf("utilityComputeNetworksConfigure: failed to detach net ID %d of type %s from Compute ID %s: %s",
|
||||||
@@ -201,7 +202,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d
|
|||||||
if net_data["ip_address"].(string) != "" {
|
if net_data["ip_address"].(string) != "" {
|
||||||
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
urlValues.Add("ipAddr", net_data["ip_address"].(string))
|
||||||
}
|
}
|
||||||
_, err := c.DecortAPICall("POST", ComputeNetAttachAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", ComputeNetAttachAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// failed to attach this network - there will be partial resource update
|
// failed to attach this network - there will be partial resource update
|
||||||
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
|
log.Errorf("utilityComputeNetworksConfigure: failed to attach net ID %d of type %s to Compute ID %s: %s",
|
||||||
@@ -220,7 +221,7 @@ func utilityComputeNetworksConfigure(d *schema.ResourceData, m interface{}, do_d
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
func utilityComputeCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||||
// This function tries to locate Compute by one of the following approaches:
|
// This function tries to locate Compute by one of the following approaches:
|
||||||
// - if compute_id is specified - locate by compute ID
|
// - if compute_id is specified - locate by compute ID
|
||||||
// - if compute_name is specified - locate by a combination of compute name and resource
|
// - if compute_name is specified - locate by a combination of compute name and resource
|
||||||
@@ -255,7 +256,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
// compute ID is specified, try to get compute instance straight by this ID
|
// compute ID is specified, try to get compute instance straight by this ID
|
||||||
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId)
|
log.Debugf("utilityComputeCheckPresence: locating compute by its ID %d", theId)
|
||||||
urlValues.Add("computeId", fmt.Sprintf("%d", theId))
|
urlValues.Add("computeId", fmt.Sprintf("%d", theId))
|
||||||
computeFacts, err := c.DecortAPICall("POST", ComputeGetAPI, urlValues)
|
computeFacts, err := c.DecortAPICall(ctx, "POST", ComputeGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -275,7 +276,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
urlValues.Add("rgId", fmt.Sprintf("%d", rgId))
|
urlValues.Add("rgId", fmt.Sprintf("%d", rgId))
|
||||||
apiResp, err := c.DecortAPICall("POST", RgListComputesAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", RgListComputesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -297,7 +298,7 @@ func utilityComputeCheckPresence(d *schema.ResourceData, m interface{}) (string,
|
|||||||
// we found the Compute we need - now get detailed information via compute/get API
|
// we found the Compute we need - now get detailed information via compute/get API
|
||||||
cgetValues := &url.Values{}
|
cgetValues := &url.Values{}
|
||||||
cgetValues.Add("computeId", fmt.Sprintf("%d", item.ID))
|
cgetValues.Add("computeId", fmt.Sprintf("%d", item.ID))
|
||||||
apiResp, err = c.DecortAPICall("POST", ComputeGetAPI, cgetValues)
|
apiResp, err = c.DecortAPICall(ctx, "POST", ComputeGetAPI, cgetValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,14 +59,14 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("publicPortEnd", strconv.Itoa(portEnd.(int)))
|
urlValues.Add("publicPortEnd", strconv.Itoa(portEnd.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
pfwId, err := c.DecortAPICall("POST", ComputePfwAddAPI, urlValues)
|
pfwId, err := c.DecortAPICall(ctx, "POST", ComputePfwAddAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
d.SetId(fmt.Sprintf("%d-%s", d.Get("compute_id").(int), pfwId))
|
d.SetId(fmt.Sprintf("%d-%s", d.Get("compute_id").(int), pfwId))
|
||||||
|
|
||||||
pfw, err := utilityPfwCheckPresence(d, m)
|
pfw, err := utilityPfwCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@ func resourcePfwCreate(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourcePfwRead: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
log.Debugf("resourcePfwRead: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
||||||
|
|
||||||
pfw, err := utilityPfwCheckPresence(d, m)
|
pfw, err := utilityPfwCheckPresence(ctx, d, m)
|
||||||
if pfw == nil {
|
if pfw == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -101,7 +101,7 @@ func resourcePfwRead(ctx context.Context, d *schema.ResourceData, m interface{})
|
|||||||
func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourcePfwDelete: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
log.Debugf("resourcePfwDelete: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
||||||
|
|
||||||
pfw, err := utilityPfwCheckPresence(d, m)
|
pfw, err := utilityPfwCheckPresence(ctx, d, m)
|
||||||
if pfw == nil {
|
if pfw == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -114,7 +114,7 @@ func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
urlValues.Add("ruleId", strconv.Itoa(pfw.ID))
|
urlValues.Add("ruleId", strconv.Itoa(pfw.ID))
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", ComputePfwDelAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", ComputePfwDelAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -122,10 +122,10 @@ func resourcePfwDelete(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourcePfwExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourcePfwExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourcePfwExists: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
log.Debugf("resourcePfwExists: called for compute %d, rule %s", d.Get("compute_id").(int), d.Id())
|
||||||
|
|
||||||
pfw, err := utilityPfwCheckPresence(d, m)
|
pfw, err := utilityPfwCheckPresence(ctx, d, m)
|
||||||
if pfw == nil {
|
if pfw == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -193,7 +193,6 @@ func ResourcePfw() *schema.Resource {
|
|||||||
CreateContext: resourcePfwCreate,
|
CreateContext: resourcePfwCreate,
|
||||||
ReadContext: resourcePfwRead,
|
ReadContext: resourcePfwRead,
|
||||||
DeleteContext: resourcePfwDelete,
|
DeleteContext: resourcePfwDelete,
|
||||||
Exists: resourcePfwExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package pfw
|
package pfw
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -41,12 +42,12 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityPfwCheckPresence(d *schema.ResourceData, m interface{}) (*PfwRecord, error) {
|
func utilityPfwCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*PfwRecord, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
resp, err := c.DecortAPICall("POST", ComputePfwListAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", ComputePfwListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func flattenResgroup(d *schema.ResourceData, rg_facts string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
rg_facts, err := utilityResgroupCheckPresence(d, m)
|
rg_facts, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||||
if rg_facts == "" {
|
if rg_facts == "" {
|
||||||
// if empty string is returned from utilityResgroupCheckPresence then there is no
|
// if empty string is returned from utilityResgroupCheckPresence then there is no
|
||||||
// such resource group and err tells so - just return it to the calling party
|
// such resource group and err tells so - just return it to the calling party
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ func flattenRgResourceLimits(rl ResourceLimits) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceRgListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
rgList, err := utilityRgListCheckPresence(d, m)
|
rgList, err := utilityRgListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
url_values.Add("extIp", ext_ip.(string))
|
url_values.Add("extIp", ext_ip.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
api_resp, err := c.DecortAPICall("POST", ResgroupCreateAPI, url_values)
|
api_resp, err := c.DecortAPICall(ctx, "POST", ResgroupCreateAPI, url_values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ func resourceResgroupCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
d.SetId(api_resp) // rg/create API returns ID of the newly creted resource group on success
|
d.SetId(api_resp) // rg/create API returns ID of the newly creted resource group on success
|
||||||
// rg.ID, _ = strconv.Atoi(api_resp)
|
// rg.ID, _ = strconv.Atoi(api_resp)
|
||||||
if !set_quota {
|
if !set_quota {
|
||||||
resp, err := utilityResgroupCheckPresence(d, m)
|
resp, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -154,7 +154,7 @@ func resourceResgroupRead(ctx context.Context, d *schema.ResourceData, m interfa
|
|||||||
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d",
|
log.Debugf("resourceResgroupRead: called for RG name %s, account ID %d",
|
||||||
d.Get("name").(string), d.Get("account_id").(int))
|
d.Get("name").(string), d.Get("account_id").(int))
|
||||||
|
|
||||||
rg_facts, err := utilityResgroupCheckPresence(d, m)
|
rg_facts, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||||
if rg_facts == "" {
|
if rg_facts == "" {
|
||||||
// if empty string is returned from utilityResgroupCheckPresence then there is no
|
// if empty string is returned from utilityResgroupCheckPresence then there is no
|
||||||
// such resource group and err tells so - just return it to the calling party
|
// such resource group and err tells so - just return it to the calling party
|
||||||
@@ -255,7 +255,7 @@ func resourceResgroupUpdate(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
|
|
||||||
if do_general_update {
|
if do_general_update {
|
||||||
log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG")
|
log.Debugf("resourceResgroupUpdate: detected delta between new and old RG specs - updating the RG")
|
||||||
_, err := c.DecortAPICall("POST", ResgroupUpdateAPI, url_values)
|
_, err := c.DecortAPICall(ctx, "POST", ResgroupUpdateAPI, url_values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -272,7 +272,7 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
log.Debugf("resourceResgroupDelete: called for RG name %s, account ID %d",
|
log.Debugf("resourceResgroupDelete: called for RG name %s, account ID %d",
|
||||||
d.Get("name").(string), d.Get("account_id").(int))
|
d.Get("name").(string), d.Get("account_id").(int))
|
||||||
|
|
||||||
rg_facts, err := utilityResgroupCheckPresence(d, m)
|
rg_facts, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||||
if rg_facts == "" {
|
if rg_facts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -289,7 +289,7 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
url_values.Add("reason", "Destroyed by DECORT Terraform provider")
|
url_values.Add("reason", "Destroyed by DECORT Terraform provider")
|
||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
_, err = c.DecortAPICall("POST", ResgroupDeleteAPI, url_values)
|
_, err = c.DecortAPICall(ctx, "POST", ResgroupDeleteAPI, url_values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -297,9 +297,9 @@ func resourceResgroupDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceResgroupExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceResgroupExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
// Reminder: according to Terraform rules, this function should NOT modify ResourceData argument
|
// Reminder: according to Terraform rules, this function should NOT modify ResourceData argument
|
||||||
rg_facts, err := utilityResgroupCheckPresence(d, m)
|
rg_facts, err := utilityResgroupCheckPresence(ctx, d, m)
|
||||||
if rg_facts == "" {
|
if rg_facts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -317,7 +317,6 @@ func ResourceResgroup() *schema.Resource {
|
|||||||
ReadContext: resourceResgroupRead,
|
ReadContext: resourceResgroupRead,
|
||||||
UpdateContext: resourceResgroupUpdate,
|
UpdateContext: resourceResgroupUpdate,
|
||||||
DeleteContext: resourceResgroupDelete,
|
DeleteContext: resourceResgroupDelete,
|
||||||
Exists: resourceResgroupExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package rg
|
package rg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -45,7 +46,7 @@ import (
|
|||||||
|
|
||||||
// On success this function returns a string, as returned by API rg/get, which could be unmarshalled
|
// On success this function returns a string, as returned by API rg/get, which could be unmarshalled
|
||||||
// into ResgroupGetResp structure
|
// into ResgroupGetResp structure
|
||||||
func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
func utilityResgroupCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||||
// This function tries to locate resource group by one of the following algorithms depending
|
// This function tries to locate resource group by one of the following algorithms depending
|
||||||
// on the parameters passed:
|
// on the parameters passed:
|
||||||
// - if resource group ID is specified -> by RG ID
|
// - if resource group ID is specified -> by RG ID
|
||||||
@@ -84,7 +85,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string
|
|||||||
// go straight for the RG by its ID
|
// go straight for the RG by its ID
|
||||||
log.Debugf("utilityResgroupCheckPresence: locating RG by its ID %d", theId)
|
log.Debugf("utilityResgroupCheckPresence: locating RG by its ID %d", theId)
|
||||||
urlValues.Add("rgId", fmt.Sprintf("%d", theId))
|
urlValues.Add("rgId", fmt.Sprintf("%d", theId))
|
||||||
rgFacts, err := c.DecortAPICall("POST", ResgroupGetAPI, urlValues)
|
rgFacts, err := c.DecortAPICall(ctx, "POST", ResgroupGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -101,7 +102,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string
|
|||||||
// obtain Account ID by account name - it should not be zero on success
|
// obtain Account ID by account name - it should not be zero on success
|
||||||
|
|
||||||
urlValues.Add("includedeleted", "false")
|
urlValues.Add("includedeleted", "false")
|
||||||
apiResp, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", ResgroupListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -125,7 +126,7 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string
|
|||||||
// Namely, we need resource quota settings
|
// Namely, we need resource quota settings
|
||||||
reqValues := &url.Values{}
|
reqValues := &url.Values{}
|
||||||
reqValues.Add("rgId", fmt.Sprintf("%d", item.ID))
|
reqValues.Add("rgId", fmt.Sprintf("%d", item.ID))
|
||||||
apiResp, err := c.DecortAPICall("POST", ResgroupGetAPI, reqValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", ResgroupGetAPI, reqValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package rg
|
package rg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (ResgroupListResp, error) {
|
func utilityRgListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ResgroupListResp, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
@@ -59,7 +60,7 @@ func utilityRgListCheckPresence(d *schema.ResourceData, m interface{}) (Resgroup
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityRgListCheckPresence: load rg list")
|
log.Debugf("utilityRgListCheckPresence: load rg list")
|
||||||
rgListRaw, err := c.DecortAPICall("POST", ResgroupListAPI, urlValues)
|
rgListRaw, err := c.DecortAPICall(ctx, "POST", ResgroupListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ func flattenSnapshotList(gl SnapshotList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceSnapshotListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
snapshotList, err := utilitySnapshotListCheckPresence(d, m)
|
snapshotList, err := utilitySnapshotListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
urlValues.Add("label", d.Get("label").(string))
|
urlValues.Add("label", d.Get("label").(string))
|
||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
|
|
||||||
snapshotId, err := c.DecortAPICall("POST", snapshotCreateAPI, urlValues)
|
snapshotId, err := c.DecortAPICall(ctx, "POST", snapshotCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -71,7 +71,7 @@ func resourceSnapshotCreate(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceSnapshotRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
snapshot, err := utilitySnapshotCheckPresence(d, m)
|
snapshot, err := utilitySnapshotCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -92,7 +92,7 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
urlValues.Add("label", d.Get("label").(string))
|
urlValues.Add("label", d.Get("label").(string))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", snapshotDeleteAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", snapshotDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -101,8 +101,8 @@ func resourceSnapshotDelete(ctx context.Context, d *schema.ResourceData, m inter
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceSnapshotExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
snapshot, err := utilitySnapshotCheckPresence(d, m)
|
snapshot, err := utilitySnapshotCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -116,7 +116,7 @@ func resourceSnapshotExists(d *schema.ResourceData, m interface{}) (bool, error)
|
|||||||
func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
if d.HasChange("rollback") {
|
if d.HasChange("rollback") {
|
||||||
if d.Get("rollback").(bool) {
|
if d.Get("rollback").(bool) {
|
||||||
err := resourceSnapshotRollback(d, m)
|
err := resourceSnapshotRollback(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -126,14 +126,14 @@ func resourceSnapshotEdit(ctx context.Context, d *schema.ResourceData, m interfa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceSnapshotRollback(d *schema.ResourceData, m interface{}) error {
|
func resourceSnapshotRollback(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
urlValues.Add("label", d.Get("label").(string))
|
urlValues.Add("label", d.Get("label").(string))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", snapshotRollbackAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", snapshotRollbackAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,6 @@ func ResourceSnapshot() *schema.Resource {
|
|||||||
ReadContext: resourceSnapshotRead,
|
ReadContext: resourceSnapshotRead,
|
||||||
UpdateContext: resourceSnapshotEdit,
|
UpdateContext: resourceSnapshotEdit,
|
||||||
DeleteContext: resourceSnapshotDelete,
|
DeleteContext: resourceSnapshotDelete,
|
||||||
Exists: resourceSnapshotExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package snapshot
|
package snapshot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilitySnapshotCheckPresence(d *schema.ResourceData, m interface{}) (*Snapshot, error) {
|
func utilitySnapshotCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Snapshot, error) {
|
||||||
snapShotList, err := utilitySnapshotListCheckPresence(d, m)
|
snapShotList, err := utilitySnapshotListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package snapshot
|
package snapshot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -40,12 +41,12 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilitySnapshotListCheckPresence(d *schema.ResourceData, m interface{}) (SnapshotList, error) {
|
func utilitySnapshotListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (SnapshotList, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
urlValues.Add("computeId", strconv.Itoa(d.Get("compute_id").(int)))
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", snapshotListAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", snapshotListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceVGPURead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
vgpu, err := utilityVGPUCheckPresence(d, m)
|
vgpu, err := utilityVGPUCheckPresence(ctx, d, m)
|
||||||
if vgpu == nil {
|
if vgpu == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package vgpu
|
package vgpu
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -40,7 +41,7 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, error) {
|
func utilityVGPUCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*VGPU, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("size", "50")
|
urlValues.Add("size", "50")
|
||||||
@@ -59,7 +60,7 @@ func utilityVGPUCheckPresence(d *schema.ResourceData, m interface{}) (*VGPU, err
|
|||||||
|
|
||||||
for page := 1; ; page++ {
|
for page := 1; ; page++ {
|
||||||
urlValues.Set("page", strconv.Itoa(page))
|
urlValues.Set("page", strconv.Itoa(page))
|
||||||
resp, err := c.DecortAPICall("POST", vgpuListAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", vgpuListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func flattenVins(d *schema.ResourceData, vins_facts string) diag.Diagnostics {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
vinsFacts, err := utilityVinsCheckPresence(d, m)
|
vinsFacts, err := utilityVinsCheckPresence(ctx, d, m)
|
||||||
if vinsFacts == "" {
|
if vinsFacts == "" {
|
||||||
// if empty string is returned from utilityVinsCheckPresence then there is no
|
// if empty string is returned from utilityVinsCheckPresence then there is no
|
||||||
// such ViNS and err tells so - just return it to the calling party
|
// such ViNS and err tells so - just return it to the calling party
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func flattenVinsList(vl VinsList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceVinsListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
vinsList, err := utilityVinsListCheckPresence(d, m)
|
vinsList, err := utilityVinsListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
urlValues.Add("desc", argVal.(string))
|
urlValues.Add("desc", argVal.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
apiResp, err := c.DecortAPICall("POST", apiToCall, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", apiToCall, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -133,7 +133,7 @@ func resourceVinsCreate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceVinsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
vinsFacts, err := utilityVinsCheckPresence(d, m)
|
vinsFacts, err := utilityVinsCheckPresence(ctx, d, m)
|
||||||
if vinsFacts == "" {
|
if vinsFacts == "" {
|
||||||
// if empty string is returned from utilityVinsCheckPresence then there is no
|
// if empty string is returned from utilityVinsCheckPresence then there is no
|
||||||
// such ViNS and err tells so - just return it to the calling party
|
// such ViNS and err tells so - just return it to the calling party
|
||||||
@@ -161,7 +161,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
|
|
||||||
if oldExtNetId.(int) > 0 {
|
if oldExtNetId.(int) > 0 {
|
||||||
// there was preexisting external net connection - disconnect ViNS
|
// there was preexisting external net connection - disconnect ViNS
|
||||||
_, err := c.DecortAPICall("POST", VinsExtNetDisconnectAPI, extnetParams)
|
_, err := c.DecortAPICall(ctx, "POST", VinsExtNetDisconnectAPI, extnetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ func resourceVinsUpdate(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
if newExtNedId.(int) > 0 {
|
if newExtNedId.(int) > 0 {
|
||||||
// new external network connection requested - connect ViNS
|
// new external network connection requested - connect ViNS
|
||||||
extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int)))
|
extnetParams.Add("netId", fmt.Sprintf("%d", newExtNedId.(int)))
|
||||||
_, err := c.DecortAPICall("POST", VinsExtNetConnectAPI, extnetParams)
|
_, err := c.DecortAPICall(ctx, "POST", VinsExtNetConnectAPI, extnetParams)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -186,7 +186,7 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
log.Debugf("resourceVinsDelete: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d",
|
log.Debugf("resourceVinsDelete: called for ViNS ID / name %s / %s, Account ID %d, RG ID %d",
|
||||||
d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
d.Id(), d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||||
|
|
||||||
vinsFacts, err := utilityVinsCheckPresence(d, m)
|
vinsFacts, err := utilityVinsCheckPresence(ctx, d, m)
|
||||||
if vinsFacts == "" {
|
if vinsFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -202,7 +202,7 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
params.Add("permanently", "1") // delete ViNS immediately bypassing recycle bin
|
params.Add("permanently", "1") // delete ViNS immediately bypassing recycle bin
|
||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
_, err = c.DecortAPICall("POST", VinsDeleteAPI, params)
|
_, err = c.DecortAPICall(ctx, "POST", VinsDeleteAPI, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -210,12 +210,12 @@ func resourceVinsDelete(ctx context.Context, d *schema.ResourceData, m interface
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceVinsExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceVinsExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
// Reminder: according to Terraform rules, this function should not modify its ResourceData argument
|
||||||
log.Debugf("resourceVinsExists: called for ViNS name %s, Account ID %d, RG ID %d",
|
log.Debugf("resourceVinsExists: called for ViNS name %s, Account ID %d, RG ID %d",
|
||||||
d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
d.Get("name").(string), d.Get("account_id").(int), d.Get("rg_id").(int))
|
||||||
|
|
||||||
vinsFacts, err := utilityVinsCheckPresence(d, m)
|
vinsFacts, err := utilityVinsCheckPresence(ctx, d, m)
|
||||||
if vinsFacts == "" {
|
if vinsFacts == "" {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -305,7 +305,6 @@ func ResourceVins() *schema.Resource {
|
|||||||
ReadContext: resourceVinsRead,
|
ReadContext: resourceVinsRead,
|
||||||
UpdateContext: resourceVinsUpdate,
|
UpdateContext: resourceVinsUpdate,
|
||||||
DeleteContext: resourceVinsDelete,
|
DeleteContext: resourceVinsDelete,
|
||||||
Exists: resourceVinsExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package vins
|
package vins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -45,7 +46,7 @@ import (
|
|||||||
|
|
||||||
// On success this function returns a string, as returned by API vins/get, which could be unmarshalled
|
// On success this function returns a string, as returned by API vins/get, which could be unmarshalled
|
||||||
// into VinsGetResp structure
|
// into VinsGetResp structure
|
||||||
func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
func utilityVinsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (string, error) {
|
||||||
// This function tries to locate ViNS by one of the following algorithms depending
|
// This function tries to locate ViNS by one of the following algorithms depending
|
||||||
// on the parameters passed:
|
// on the parameters passed:
|
||||||
// - if resource group ID is specified -> it looks for a ViNS at the RG level
|
// - if resource group ID is specified -> it looks for a ViNS at the RG level
|
||||||
@@ -80,7 +81,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
|||||||
// ViNS ID is specified, try to get compute instance straight by this ID
|
// ViNS ID is specified, try to get compute instance straight by this ID
|
||||||
log.Debugf("utilityVinsCheckPresence: locating ViNS by its ID %d", theId)
|
log.Debugf("utilityVinsCheckPresence: locating ViNS by its ID %d", theId)
|
||||||
urlValues.Add("vinsId", fmt.Sprintf("%d", theId))
|
urlValues.Add("vinsId", fmt.Sprintf("%d", theId))
|
||||||
vinsFacts, err := c.DecortAPICall("POST", VinsGetAPI, urlValues)
|
vinsFacts, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
|||||||
urlValues.Add("accountId", fmt.Sprintf("%d", accountId.(int)))
|
urlValues.Add("accountId", fmt.Sprintf("%d", accountId.(int)))
|
||||||
}
|
}
|
||||||
|
|
||||||
apiResp, err := c.DecortAPICall("POST", VinsSearchAPI, urlValues)
|
apiResp, err := c.DecortAPICall(ctx, "POST", VinsSearchAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@@ -140,7 +141,7 @@ func utilityVinsCheckPresence(d *schema.ResourceData, m interface{}) (string, er
|
|||||||
// manage ViNS, so we have to get detailed info by calling API vins/get
|
// manage ViNS, so we have to get detailed info by calling API vins/get
|
||||||
rqValues := &url.Values{}
|
rqValues := &url.Values{}
|
||||||
rqValues.Add("vinsId", fmt.Sprintf("%d", item.ID))
|
rqValues.Add("vinsId", fmt.Sprintf("%d", item.ID))
|
||||||
vinsGetResp, err := c.DecortAPICall("POST", VinsGetAPI, rqValues)
|
vinsGetResp, err := c.DecortAPICall(ctx, "POST", VinsGetAPI, rqValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package vins
|
package vins
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsList, error) {
|
func utilityVinsListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (VinsList, error) {
|
||||||
vinsList := VinsList{}
|
vinsList := VinsList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -58,7 +59,7 @@ func utilityVinsListCheckPresence(d *schema.ResourceData, m interface{}) (VinsLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityVinsListCheckPresence")
|
log.Debugf("utilityVinsListCheckPresence")
|
||||||
vinsListRaw, err := c.DecortAPICall("POST", VinsListAPI, urlValues)
|
vinsListRaw, err := c.DecortAPICall(ctx, "POST", VinsListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ func flattenGrid(d *schema.ResourceData, grid *Grid) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceGridRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
grid, err := utilityGridCheckPresence(d, m)
|
grid, err := utilityGridCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ func flattenGridList(gl GridList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceGridListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
gridList, err := utilityGridListCheckPresence(d, m)
|
gridList, err := utilityGridListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package grid
|
package grid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -43,7 +44,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, error) {
|
func utilityGridCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Grid, error) {
|
||||||
grid := &Grid{}
|
grid := &Grid{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -55,7 +56,7 @@ func utilityGridCheckPresence(d *schema.ResourceData, m interface{}) (*Grid, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityGridCheckPresence: load grid")
|
log.Debugf("utilityGridCheckPresence: load grid")
|
||||||
gridRaw, err := c.DecortAPICall("POST", GridGetAPI, urlValues)
|
gridRaw, err := c.DecortAPICall(ctx, "POST", GridGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package grid
|
package grid
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridList, error) {
|
func utilityGridListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (GridList, error) {
|
||||||
gridList := GridList{}
|
gridList := GridList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -55,7 +56,7 @@ func utilityGridListCheckPresence(d *schema.ResourceData, m interface{}) (GridLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityGridListCheckPresence: load grid list")
|
log.Debugf("utilityGridListCheckPresence: load grid list")
|
||||||
gridListRaw, err := c.DecortAPICall("POST", GridListGetAPI, urlValues)
|
gridListRaw, err := c.DecortAPICall(ctx, "POST", GridListGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ func flattenImage(d *schema.ResourceData, image *Image) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ func flattenImageList(il ImageList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceImageListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
imageList, err := utilityImageListCheckPresence(d, m)
|
imageList, err := utilityImageListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func flattenImageListStacks(_ *schema.ResourceData, stack ImageListStacks) []map
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourceImageListStacksRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
imageListStacks, err := utilityImageListStacksCheckPresence(d, m)
|
imageListStacks, err := utilityImageListStacksCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
urlValues.Add("architecture", architecture.(string))
|
urlValues.Add("architecture", architecture.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
imageId, err := c.DecortAPICall("POST", imageCreateCDROMAPI, urlValues)
|
imageId, err := c.DecortAPICall(ctx, "POST", imageCreateCDROMAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -98,7 +98,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
d.SetId(imageId)
|
d.SetId(imageId)
|
||||||
d.Set("image_id", imageId)
|
d.Set("image_id", imageId)
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ func resourceCDROMImageCreate(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceCDROMImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceCDROMImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if image == nil {
|
if image == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -134,7 +134,7 @@ func resourceCDROMImageDelete(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", imageDeleteCDROMAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", imageDeleteCDROMAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,6 @@ func ResourceCDROMImage() *schema.Resource {
|
|||||||
ReadContext: resourceImageRead,
|
ReadContext: resourceImageRead,
|
||||||
UpdateContext: resourceImageEdit,
|
UpdateContext: resourceImageEdit,
|
||||||
DeleteContext: resourceCDROMImageDelete,
|
DeleteContext: resourceCDROMImageDelete,
|
||||||
Exists: resourceImageExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ func resourceDeleteListImages(ctx context.Context, d *schema.ResourceData, m int
|
|||||||
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
urlValues.Add("permanently", strconv.FormatBool(d.Get("permanently").(bool)))
|
||||||
urlValues.Add("imageIds", temp)
|
urlValues.Add("imageIds", temp)
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", imageDeleteImagesAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageDeleteImagesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
} else {
|
} else {
|
||||||
api = imageSyncCreateAPI
|
api = imageSyncCreateAPI
|
||||||
}
|
}
|
||||||
imageId, err := c.DecortAPICall("POST", api, urlValues)
|
imageId, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
d.SetId(imageId)
|
d.SetId(imageId)
|
||||||
d.Set("image_id", imageId)
|
d.Set("image_id", imageId)
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ func resourceImageCreate(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageRead: called for %s id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if image == nil {
|
if image == nil {
|
||||||
d.SetId("")
|
d.SetId("")
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -182,7 +182,7 @@ func resourceImageRead(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageDelete: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if image == nil {
|
if image == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
@@ -202,7 +202,7 @@ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
urlValues.Add("permanently", strconv.FormatBool(permanently.(bool)))
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = c.DecortAPICall("POST", imageDeleteAPI, urlValues)
|
_, err = c.DecortAPICall(ctx, "POST", imageDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -211,10 +211,10 @@ func resourceImageDelete(ctx context.Context, d *schema.ResourceData, m interfac
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourceImageExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
log.Debugf("resourceImageExists: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageExists: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if image == nil {
|
if image == nil {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
@@ -225,13 +225,13 @@ func resourceImageExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
|||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageEditName(d *schema.ResourceData, m interface{}) error {
|
func resourceImageEditName(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageEditName: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||||
urlValues.Add("name", d.Get("name").(string))
|
urlValues.Add("name", d.Get("name").(string))
|
||||||
_, err := c.DecortAPICall("POST", imageEditNameAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageEditNameAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -245,7 +245,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
if d.HasChange("enabled") {
|
if d.HasChange("enabled") {
|
||||||
err := resourceImageChangeEnabled(d, m)
|
err := resourceImageChangeEnabled(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("name") {
|
if d.HasChange("name") {
|
||||||
err := resourceImageEditName(d, m)
|
err := resourceImageEditName(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -261,14 +261,14 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("shared_with") {
|
if d.HasChange("shared_with") {
|
||||||
err := resourceImageShare(d, m)
|
err := resourceImageShare(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
urlValues = &url.Values{}
|
urlValues = &url.Values{}
|
||||||
}
|
}
|
||||||
if d.HasChange("computeci_id") {
|
if d.HasChange("computeci_id") {
|
||||||
err := resourceImageChangeComputeci(d, m)
|
err := resourceImageChangeComputeci(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -276,7 +276,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("enabled_stacks") {
|
if d.HasChange("enabled_stacks") {
|
||||||
err := resourceImageUpdateNodes(d, m)
|
err := resourceImageUpdateNodes(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -284,7 +284,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if d.HasChange("link_to") {
|
if d.HasChange("link_to") {
|
||||||
err := resourceImageLink(d, m)
|
err := resourceImageLink(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -302,7 +302,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool)))
|
urlValues.Add("bootable", strconv.FormatBool(d.Get("bootable").(bool)))
|
||||||
urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool)))
|
urlValues.Add("hotresize", strconv.FormatBool(d.Get("hot_resize").(bool)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", imageEditAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageEditAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -311,7 +311,7 @@ func resourceImageEdit(ctx context.Context, d *schema.ResourceData, m interface{
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error {
|
func resourceImageChangeEnabled(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
var api string
|
var api string
|
||||||
|
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
@@ -322,7 +322,7 @@ func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error {
|
|||||||
} else {
|
} else {
|
||||||
api = imageDisableAPI
|
api = imageDisableAPI
|
||||||
}
|
}
|
||||||
resp, err := c.DecortAPICall("POST", api, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -336,13 +336,13 @@ func resourceImageChangeEnabled(d *schema.ResourceData, m interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageLink(d *schema.ResourceData, m interface{}) error {
|
func resourceImageLink(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceVirtualImageLink: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||||
urlValues.Add("targetId", strconv.Itoa(d.Get("link_to").(int)))
|
urlValues.Add("targetId", strconv.Itoa(d.Get("link_to").(int)))
|
||||||
_, err := c.DecortAPICall("POST", imageLinkAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageLinkAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -350,7 +350,7 @@ func resourceImageLink(d *schema.ResourceData, m interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageShare(d *schema.ResourceData, m interface{}) error {
|
func resourceImageShare(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageShare: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -369,7 +369,7 @@ func resourceImageShare(d *schema.ResourceData, m interface{}) error {
|
|||||||
}
|
}
|
||||||
temp = "[" + temp + "]"
|
temp = "[" + temp + "]"
|
||||||
urlValues.Add("accounts", temp)
|
urlValues.Add("accounts", temp)
|
||||||
_, err := c.DecortAPICall("POST", imageShareAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageShareAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -377,7 +377,7 @@ func resourceImageShare(d *schema.ResourceData, m interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error {
|
func resourceImageChangeComputeci(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error {
|
|||||||
api = imageComputeciSetAPI
|
api = imageComputeciSetAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -401,7 +401,7 @@ func resourceImageChangeComputeci(d *schema.ResourceData, m interface{}) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceImageUpdateNodes(d *schema.ResourceData, m interface{}) error {
|
func resourceImageUpdateNodes(ctx context.Context, d *schema.ResourceData, m interface{}) error {
|
||||||
log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id())
|
log.Debugf("resourceImageUpdateNodes: called for %s, id: %s", d.Get("name").(string), d.Id())
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -418,7 +418,7 @@ func resourceImageUpdateNodes(d *schema.ResourceData, m interface{}) error {
|
|||||||
}
|
}
|
||||||
temp = "[" + temp + "]"
|
temp = "[" + temp + "]"
|
||||||
urlValues.Add("enabledStacks", temp)
|
urlValues.Add("enabledStacks", temp)
|
||||||
_, err := c.DecortAPICall("POST", imageUpdateNodesAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", imageUpdateNodesAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -677,7 +677,6 @@ func ResourceImage() *schema.Resource {
|
|||||||
ReadContext: resourceImageRead,
|
ReadContext: resourceImageRead,
|
||||||
UpdateContext: resourceImageEdit,
|
UpdateContext: resourceImageEdit,
|
||||||
DeleteContext: resourceImageDelete,
|
DeleteContext: resourceImageDelete,
|
||||||
Exists: resourceImageExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
urlValues.Add("name", d.Get("name").(string))
|
urlValues.Add("name", d.Get("name").(string))
|
||||||
urlValues.Add("targetId", strconv.Itoa(d.Get("target_id").(int)))
|
urlValues.Add("targetId", strconv.Itoa(d.Get("target_id").(int)))
|
||||||
|
|
||||||
imageId, err := c.DecortAPICall("POST", imageCreateVirtualAPI, urlValues)
|
imageId, err := c.DecortAPICall(ctx, "POST", imageCreateVirtualAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func resourceVirtualImageCreate(ctx context.Context, d *schema.ResourceData, m i
|
|||||||
d.SetId(imageId)
|
d.SetId(imageId)
|
||||||
d.Set("image_id", imageId)
|
d.Set("image_id", imageId)
|
||||||
|
|
||||||
image, err := utilityImageCheckPresence(d, m)
|
image, err := utilityImageCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -326,7 +326,6 @@ func ResourceVirtualImage() *schema.Resource {
|
|||||||
ReadContext: resourceImageRead,
|
ReadContext: resourceImageRead,
|
||||||
UpdateContext: resourceImageEdit,
|
UpdateContext: resourceImageEdit,
|
||||||
DeleteContext: resourceImageDelete,
|
DeleteContext: resourceImageDelete,
|
||||||
Exists: resourceImageExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, error) {
|
func utilityImageCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Image, error) {
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
@@ -52,7 +53,7 @@ func utilityImageCheckPresence(d *schema.ResourceData, m interface{}) (*Image, e
|
|||||||
urlValues.Add("imageId", d.Id())
|
urlValues.Add("imageId", d.Id())
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := c.DecortAPICall("POST", imageGetAPI, urlValues)
|
resp, err := c.DecortAPICall(ctx, "POST", imageGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (ImageList, error) {
|
func utilityImageListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ImageList, error) {
|
||||||
imageList := ImageList{}
|
imageList := ImageList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -62,7 +63,7 @@ func utilityImageListCheckPresence(d *schema.ResourceData, m interface{}) (Image
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Debugf("utilityImageListCheckPresence: load image list")
|
log.Debugf("utilityImageListCheckPresence: load image list")
|
||||||
imageListRaw, err := c.DecortAPICall("POST", imageListGetAPI, urlValues)
|
imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListGetAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package image
|
package image
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -42,7 +43,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{}) (ImageListStacks, error) {
|
func utilityImageListStacksCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (ImageListStacks, error) {
|
||||||
imageListStacks := ImageListStacks{}
|
imageListStacks := ImageListStacks{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
@@ -50,7 +51,7 @@ func utilityImageListStacksCheckPresence(d *schema.ResourceData, m interface{})
|
|||||||
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
urlValues.Add("imageId", strconv.Itoa(d.Get("image_id").(int)))
|
||||||
|
|
||||||
log.Debugf("utilityImageListStacksCheckPresence: load image list")
|
log.Debugf("utilityImageListStacksCheckPresence: load image list")
|
||||||
imageListRaw, err := c.DecortAPICall("POST", imageListStacksApi, urlValues)
|
imageListRaw, err := c.DecortAPICall(ctx, "POST", imageListStacksApi, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ func flattenPcideviceList(pl PcideviceList) []map[string]interface{} {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func dataSourcePcideviceListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
pcideviceList, err := utilityPcideviceListCheckPresence(d, m)
|
pcideviceList, err := utilityPcideviceListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte
|
|||||||
log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string))
|
log.Debugf("resourcePcideviceCreate: called for pcidevice %s", d.Get("name").(string))
|
||||||
|
|
||||||
if deviceId, ok := d.GetOk("device_id"); ok {
|
if deviceId, ok := d.GetOk("device_id"); ok {
|
||||||
if exists, err := resourcePcideviceExists(d, m); exists {
|
if exists, err := resourcePcideviceExists(ctx, d, m); exists {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -74,7 +74,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte
|
|||||||
urlValues.Add("description", description.(string))
|
urlValues.Add("description", description.(string))
|
||||||
}
|
}
|
||||||
|
|
||||||
pcideviceId, err := c.DecortAPICall("POST", pcideviceCreateAPI, urlValues)
|
pcideviceId, err := c.DecortAPICall(ctx, "POST", pcideviceCreateAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ func resourcePcideviceCreate(ctx context.Context, d *schema.ResourceData, m inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
func resourcePcideviceRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
|
||||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -121,7 +121,7 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte
|
|||||||
urlValues.Add("deviceId", d.Id())
|
urlValues.Add("deviceId", d.Id())
|
||||||
urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool)))
|
urlValues.Add("force", strconv.FormatBool(d.Get("force").(bool)))
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", pcideviceDeleteAPI, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", pcideviceDeleteAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -131,8 +131,8 @@ func resourcePcideviceDelete(ctx context.Context, d *schema.ResourceData, m inte
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourcePcideviceExists(d *schema.ResourceData, m interface{}) (bool, error) {
|
func resourcePcideviceExists(ctx context.Context, d *schema.ResourceData, m interface{}) (bool, error) {
|
||||||
pcidevice, err := utilityPcideviceCheckPresence(d, m)
|
pcidevice, err := utilityPcideviceCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ func resourcePcideviceEdit(ctx context.Context, d *schema.ResourceData, m interf
|
|||||||
api = pcideviceDisableAPI
|
api = pcideviceDisableAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.DecortAPICall("POST", api, urlValues)
|
_, err := c.DecortAPICall(ctx, "POST", api, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return diag.FromErr(err)
|
return diag.FromErr(err)
|
||||||
}
|
}
|
||||||
@@ -255,7 +255,6 @@ func ResourcePcidevice() *schema.Resource {
|
|||||||
ReadContext: resourcePcideviceRead,
|
ReadContext: resourcePcideviceRead,
|
||||||
UpdateContext: resourcePcideviceEdit,
|
UpdateContext: resourcePcideviceEdit,
|
||||||
DeleteContext: resourcePcideviceDelete,
|
DeleteContext: resourcePcideviceDelete,
|
||||||
Exists: resourcePcideviceExists,
|
|
||||||
|
|
||||||
Importer: &schema.ResourceImporter{
|
Importer: &schema.ResourceImporter{
|
||||||
State: schema.ImportStatePassthrough,
|
State: schema.ImportStatePassthrough,
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package pcidevice
|
package pcidevice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityPcideviceCheckPresence(d *schema.ResourceData, m interface{}) (*Pcidevice, error) {
|
func utilityPcideviceCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*Pcidevice, error) {
|
||||||
pcideviceList, err := utilityPcideviceListCheckPresence(d, m)
|
pcideviceList, err := utilityPcideviceListCheckPresence(ctx, d, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ Documentation: https://github.com/rudecs/terraform-provider-decort/wiki
|
|||||||
package pcidevice
|
package pcidevice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ import (
|
|||||||
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
"github.com/rudecs/terraform-provider-decort/internal/controller"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityPcideviceListCheckPresence(_ *schema.ResourceData, m interface{}) (PcideviceList, error) {
|
func utilityPcideviceListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (PcideviceList, error) {
|
||||||
pcideviceList := PcideviceList{}
|
pcideviceList := PcideviceList{}
|
||||||
c := m.(*controller.ControllerCfg)
|
c := m.(*controller.ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
pcideviceListRaw, err := c.DecortAPICall("POST", pcideviceListAPI, urlValues)
|
pcideviceListRaw, err := c.DecortAPICall(ctx, "POST", pcideviceListAPI, urlValues)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user