From e0e9eaad374b694200f12958e4ba43d35c1d5da3 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 6 Jun 2023 11:30:40 +0200 Subject: [PATCH 1/3] bump go-azure-sdk to v0.20230606.1092251 --- go.mod | 2 +- go.sum | 4 +-- .../2020-10-01/deploymentscripts/constants.go | 25 -------------- .../deploymentscripts/model_azurecliscript.go | 15 +++++---- .../model_azurepowershellscript.go | 15 +++++---- .../model_managedserviceidentity.go | 10 ------ .../model_userassignedidentity.go | 9 ----- .../sdk/client/resourcemanager/errors.go | 3 ++ .../sdk/client/resourcemanager/poller_lro.go | 33 ++++++++++++++++--- vendor/modules.txt | 2 +- 10 files changed, 52 insertions(+), 66 deletions(-) delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_managedserviceidentity.go delete mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_userassignedidentity.go diff --git a/go.mod b/go.mod index 9db626ad91f0..def94853300f 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/google/go-cmp v0.5.9 github.com/google/uuid v1.1.2 github.com/hashicorp/go-azure-helpers v0.56.0 - github.com/hashicorp/go-azure-sdk v0.20230523.1140858 + github.com/hashicorp/go-azure-sdk v0.20230606.1092251 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-uuid v1.0.3 github.com/hashicorp/go-version v1.6.0 diff --git a/go.sum b/go.sum index d47e267f7c9a..2e0c0a65886a 100644 --- a/go.sum +++ b/go.sum @@ -141,8 +141,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg= github.com/hashicorp/go-azure-helpers v0.56.0 h1:KxDXISHwWe4PKEz6FSSPG8vCXNrFGsCcCn/AI94ccig= github.com/hashicorp/go-azure-helpers v0.56.0/go.mod h1:MbnCV9jPmlkbdH7VsoBK8IbCHvo3pLWRbRvq+F6u9sI= -github.com/hashicorp/go-azure-sdk v0.20230523.1140858 h1:pstzTqIYBr2XnthdjCen/1DefYSGls6hSfQqYGWMuZo= -github.com/hashicorp/go-azure-sdk v0.20230523.1140858/go.mod h1:x2r7/U5MKlTHUO6/hFHRNO03qkRLBYyeQOuEUHkZmEg= +github.com/hashicorp/go-azure-sdk v0.20230606.1092251 h1:8A7dj8V+gQxumfncEDzmHEM9RnKyMWDu+jXjqOV8/II= +github.com/hashicorp/go-azure-sdk v0.20230606.1092251/go.mod h1:x2r7/U5MKlTHUO6/hFHRNO03qkRLBYyeQOuEUHkZmEg= github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuDrwkBuEQsVcpCOgg= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/constants.go index 44ec0934c106..3824982c71d5 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/constants.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/constants.go @@ -36,31 +36,6 @@ func parseCleanupOptions(input string) (*CleanupOptions, error) { return &out, nil } -type ManagedServiceIdentityType string - -const ( - ManagedServiceIdentityTypeUserAssigned ManagedServiceIdentityType = "UserAssigned" -) - -func PossibleValuesForManagedServiceIdentityType() []string { - return []string{ - string(ManagedServiceIdentityTypeUserAssigned), - } -} - -func parseManagedServiceIdentityType(input string) (*ManagedServiceIdentityType, error) { - vals := map[string]ManagedServiceIdentityType{ - "userassigned": ManagedServiceIdentityTypeUserAssigned, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := ManagedServiceIdentityType(input) - return &out, nil -} - type ScriptProvisioningState string const ( diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurecliscript.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurecliscript.go index 53db80795674..dee5017e10ce 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurecliscript.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurecliscript.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" ) @@ -16,13 +17,13 @@ type AzureCliScript struct { Properties AzureCliScriptProperties `json:"properties"` // Fields inherited from DeploymentScript - Id *string `json:"id,omitempty"` - Identity *ManagedServiceIdentity `json:"identity,omitempty"` - Location string `json:"location"` - Name *string `json:"name,omitempty"` - SystemData *systemdata.SystemData `json:"systemData,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` - Type *string `json:"type,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.UserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` } var _ json.Marshaler = AzureCliScript{} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurepowershellscript.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurepowershellscript.go index e20c5ce60303..d6847b26436a 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurepowershellscript.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_azurepowershellscript.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" ) @@ -16,13 +17,13 @@ type AzurePowerShellScript struct { Properties AzurePowerShellScriptProperties `json:"properties"` // Fields inherited from DeploymentScript - Id *string `json:"id,omitempty"` - Identity *ManagedServiceIdentity `json:"identity,omitempty"` - Location string `json:"location"` - Name *string `json:"name,omitempty"` - SystemData *systemdata.SystemData `json:"systemData,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` - Type *string `json:"type,omitempty"` + Id *string `json:"id,omitempty"` + Identity *identity.UserAssignedMap `json:"identity,omitempty"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` } var _ json.Marshaler = AzurePowerShellScript{} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_managedserviceidentity.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_managedserviceidentity.go deleted file mode 100644 index 5433d7608df4..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_managedserviceidentity.go +++ /dev/null @@ -1,10 +0,0 @@ -package deploymentscripts - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type ManagedServiceIdentity struct { - TenantId *string `json:"tenantId,omitempty"` - Type *ManagedServiceIdentityType `json:"type,omitempty"` - UserAssignedIdentities *map[string]UserAssignedIdentity `json:"userAssignedIdentities,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_userassignedidentity.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_userassignedidentity.go deleted file mode 100644 index 672adb8c3c80..000000000000 --- a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts/model_userassignedidentity.go +++ /dev/null @@ -1,9 +0,0 @@ -package deploymentscripts - -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. See NOTICE.txt in the project root for license information. - -type UserAssignedIdentity struct { - ClientId *string `json:"clientId,omitempty"` - PrincipalId *string `json:"principalId,omitempty"` -} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/errors.go b/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/errors.go index 9fa713b8c615..e756aa165a0e 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/errors.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/errors.go @@ -1,3 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + package resourcemanager import ( diff --git a/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/poller_lro.go b/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/poller_lro.go index b1e34d6b0bae..926fcbda9ed1 100644 --- a/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/poller_lro.go +++ b/vendor/github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager/poller_lro.go @@ -4,6 +4,7 @@ package resourcemanager import ( + "bytes" "context" "encoding/json" "fmt" @@ -117,6 +118,8 @@ func (p *longRunningOperationPoller) Poll(ctx context.Context) (result *pollers. } result.HttpResponse.Body.Close() + result.HttpResponse.Body = io.NopCloser(bytes.NewReader(respBody)) + // update the poll interval if a Retry-After header is returned if s, ok := result.HttpResponse.Header["Retry-After"]; ok { if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil { @@ -146,8 +149,6 @@ func (p *longRunningOperationPoller) Poll(ctx context.Context) (result *pollers. return nil, fmt.Errorf("expected either `provisioningState` or `status` to be returned from the LRO API but both were empty") } - // TODO: raising an error if this is Cancelled or Failed - statuses := map[status]pollers.PollingStatus{ statusCanceled: pollers.PollingStatusCancelled, statusCancelled: pollers.PollingStatusCancelled, @@ -170,11 +171,35 @@ func (p *longRunningOperationPoller) Poll(ctx context.Context) (result *pollers. for k, v := range statuses { if strings.EqualFold(string(op.Properties.ProvisioningState), string(k)) { result.Status = v - return + break } if strings.EqualFold(string(op.Status), string(k)) { result.Status = v - return + break + } + } + + if result.Status == pollers.PollingStatusFailed { + lroError, parseError := parseErrorFromApiResponse(*result.HttpResponse.Response) + if parseError != nil { + return nil, parseError + } + + err = pollers.PollingFailedError{ + HttpResponse: result.HttpResponse, + Message: lroError.Error(), + } + } + + if result.Status == pollers.PollingStatusCancelled { + lroError, parseError := parseErrorFromApiResponse(*result.HttpResponse.Response) + if parseError != nil { + return nil, parseError + } + + err = pollers.PollingCancelledError{ + HttpResponse: result.HttpResponse, + Message: lroError.Error(), } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 0d151f241c79..bd343af23edc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -136,7 +136,7 @@ github.com/hashicorp/go-azure-helpers/resourcemanager/tags github.com/hashicorp/go-azure-helpers/resourcemanager/zones github.com/hashicorp/go-azure-helpers/sender github.com/hashicorp/go-azure-helpers/storage -# github.com/hashicorp/go-azure-sdk v0.20230523.1140858 +# github.com/hashicorp/go-azure-sdk v0.20230606.1092251 ## explicit; go 1.19 github.com/hashicorp/go-azure-sdk/resource-manager/aad/2021-05-01/domainservices github.com/hashicorp/go-azure-sdk/resource-manager/aadb2c/2021-04-01-preview From b1aa97b1dea86d95a8aaa98b1ecd228880966bbf Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 6 Jun 2023 11:45:08 +0200 Subject: [PATCH 2/3] use expand and flatten for user assigned identity map --- ...ce_deployment_script_azure_cli_resource.go | 5 +- ...yment_script_azure_power_shell_resource.go | 5 +- .../resource_deployment_script_common.go | 54 ------------------- 3 files changed, 6 insertions(+), 58 deletions(-) diff --git a/internal/services/resource/resource_deployment_script_azure_cli_resource.go b/internal/services/resource/resource_deployment_script_azure_cli_resource.go index 77ba29c001c3..4956dfd88116 100644 --- a/internal/services/resource/resource_deployment_script_azure_cli_resource.go +++ b/internal/services/resource/resource_deployment_script_azure_cli_resource.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -73,7 +74,7 @@ func (r ResourceDeploymentScriptAzureCliResource) Create() sdk.ResourceFunc { }, } - identityValue, err := expandManagedServiceIdentityModel(metadata.ResourceData.Get("identity").([]interface{})) + identityValue, err := identity.ExpandUserAssignedMap(metadata.ResourceData.Get("identity").([]interface{})) if err != nil { return err } @@ -149,7 +150,7 @@ func (r ResourceDeploymentScriptAzureCliResource) Read() sdk.ResourceFunc { Location: location.Normalize(model.Location), } - identityValue, err := flattenManagedServiceIdentityModel(model.Identity) + identityValue, err := identity.FlattenUserAssignedMap(model.Identity) if err != nil { return err } diff --git a/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go b/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go index 751f96da1a53..d52b5920bfcf 100644 --- a/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go +++ b/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -73,7 +74,7 @@ func (r ResourceDeploymentScriptAzurePowerShellResource) Create() sdk.ResourceFu }, } - identityValue, err := expandManagedServiceIdentityModel(metadata.ResourceData.Get("identity").([]interface{})) + identityValue, err := identity.ExpandUserAssignedMap(metadata.ResourceData.Get("identity").([]interface{})) if err != nil { return err } @@ -149,7 +150,7 @@ func (r ResourceDeploymentScriptAzurePowerShellResource) Read() sdk.ResourceFunc Location: location.Normalize(model.Location), } - identityValue, err := flattenManagedServiceIdentityModel(model.Identity) + identityValue, err := identity.FlattenUserAssignedMap(model.Identity) if err != nil { return err } diff --git a/internal/services/resource/resource_deployment_script_common.go b/internal/services/resource/resource_deployment_script_common.go index e62f3685aead..c767892811c1 100644 --- a/internal/services/resource/resource_deployment_script_common.go +++ b/internal/services/resource/resource_deployment_script_common.go @@ -9,7 +9,6 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts" "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" @@ -455,33 +454,6 @@ func expandEnvironmentVariableModelArray(inputList []EnvironmentVariableModel) * return &outputList } -func expandManagedServiceIdentityModel(inputList []interface{}) (*deploymentscripts.ManagedServiceIdentity, error) { - if len(inputList) == 0 { - return nil, nil - } - - identityValue, err := identity.ExpandUserAssignedMap(inputList) - if err != nil { - return nil, fmt.Errorf("expanding `identity`: %+v", err) - } - - userAssignedIdentities := make(map[string]deploymentscripts.UserAssignedIdentity) - for k, v := range identityValue.IdentityIds { - userAssignedIdentities[k] = deploymentscripts.UserAssignedIdentity{ - ClientId: v.ClientId, - PrincipalId: v.PrincipalId, - } - } - - identityType := deploymentscripts.ManagedServiceIdentityType(identityValue.Type) - output := deploymentscripts.ManagedServiceIdentity{ - Type: &identityType, - UserAssignedIdentities: &userAssignedIdentities, - } - - return &output, nil -} - func expandStorageAccountConfigurationModel(inputList []StorageAccountConfigurationModel) *deploymentscripts.StorageAccountConfiguration { if len(inputList) == 0 { return nil @@ -551,32 +523,6 @@ func flattenEnvironmentVariableModelArray(inputList *[]deploymentscripts.Environ return outputList } -func flattenManagedServiceIdentityModel(input *deploymentscripts.ManagedServiceIdentity) (*[]interface{}, error) { - var transform *identity.UserAssignedMap - - if input != nil { - transform = &identity.UserAssignedMap{ - Type: identity.TypeNone, - IdentityIds: make(map[string]identity.UserAssignedIdentityDetails), - } - - if input.Type != nil { - transform.Type = identity.Type(*input.Type) - } - - if input.UserAssignedIdentities != nil { - for k, v := range *input.UserAssignedIdentities { - transform.IdentityIds[k] = identity.UserAssignedIdentityDetails{ - ClientId: v.ClientId, - PrincipalId: v.PrincipalId, - } - } - } - } - - return identity.FlattenUserAssignedMap(transform) -} - func flattenStorageAccountConfigurationModel(input *deploymentscripts.StorageAccountConfiguration, originalList []StorageAccountConfigurationModel) []StorageAccountConfigurationModel { var outputList []StorageAccountConfigurationModel if input == nil { From cf007c7b0777ef1bfbc57178f9d2d8af9439422e Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 6 Jun 2023 11:52:08 +0200 Subject: [PATCH 3/3] goimports --- .../resource/resource_deployment_script_azure_cli_resource.go | 2 +- .../resource_deployment_script_azure_power_shell_resource.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/services/resource/resource_deployment_script_azure_cli_resource.go b/internal/services/resource/resource_deployment_script_azure_cli_resource.go index 4956dfd88116..20006a24c009 100644 --- a/internal/services/resource/resource_deployment_script_azure_cli_resource.go +++ b/internal/services/resource/resource_deployment_script_azure_cli_resource.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" "fmt" - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "time" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" diff --git a/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go b/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go index d52b5920bfcf..05a14d4358b8 100644 --- a/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go +++ b/internal/services/resource/resource_deployment_script_azure_power_shell_resource.go @@ -4,10 +4,10 @@ import ( "context" "encoding/json" "fmt" - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "time" "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/resources/2020-10-01/deploymentscripts" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"