Skip to content

Commit

Permalink
Merge pull request #25332 from hashicorp/deps/bump-go-azure-sdk-to-v0…
Browse files Browse the repository at this point in the history
….20240320.1144505

dependencies: bump `go-azure-sdk` to `v0.20240320.1144505`
  • Loading branch information
tombuildsstuff authored Mar 21, 2024
2 parents 23c66f8 + d9bf877 commit a6de371
Show file tree
Hide file tree
Showing 24 changed files with 441 additions and 112 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ require (
github.com/google/go-cmp v0.5.9
github.com/google/uuid v1.4.0
github.com/hashicorp/go-azure-helpers v0.66.2
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240315.1103122
github.com/hashicorp/go-azure-sdk/sdk v0.20240315.1103122
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240321.1145953
github.com/hashicorp/go-azure-sdk/sdk v0.20240321.1145953
github.com/hashicorp/go-hclog v1.5.0
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-uuid v1.0.3
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-azure-helpers v0.66.2 h1:+Pzuo7pdKl0hBXXr5ymmhs4Q40tHAo2nAvHq4WgSjx8=
github.com/hashicorp/go-azure-helpers v0.66.2/go.mod h1:kJxXrFtJKJdOEqvad8pllAe7dhP4DbN8J6sqFZe47+4=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240315.1103122 h1:cBuhqUvm59V6Na2GvC2WhuW2exShMy7mlYfJq5RdiKo=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240315.1103122/go.mod h1:Bqyftfx+hmU/CAUixSsO6JG8iAnYZfZCsTplJxWVkVE=
github.com/hashicorp/go-azure-sdk/sdk v0.20240315.1103122 h1:Ufy2m3h4a0kAiVHzffpuqLEYNFiE+rFbTfOPXd6m7YI=
github.com/hashicorp/go-azure-sdk/sdk v0.20240315.1103122/go.mod h1:POOjeoqNp+mvlLBuibJTziUAkBZ7FxXGeGestwemL/w=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240321.1145953 h1:eoU9iMmWgufB441trZJ45TsZ+0vJ79vGKdBuVVYUXwI=
github.com/hashicorp/go-azure-sdk/resource-manager v0.20240321.1145953/go.mod h1:zvsDltRIRr58vA0EpSmY+a6NcgGirQE/u02Ag+D8jmM=
github.com/hashicorp/go-azure-sdk/sdk v0.20240321.1145953 h1:WAcSZL5+H9Z/DjUZ0x0sluNoEno/mD4b+NWpY04vJrw=
github.com/hashicorp/go-azure-sdk/sdk v0.20240321.1145953/go.mod h1:POOjeoqNp+mvlLBuibJTziUAkBZ7FxXGeGestwemL/w=
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=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,10 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
"github.com/hashicorp/terraform-provider-azurerm/utils"
)

type DataFactoryCredentialUserAssignedManagedIdentityResource struct{}

// user managed identities only have one type
const IDENTITY_TYPE = "ManagedIdentity"

var _ sdk.Resource = DataFactoryCredentialUserAssignedManagedIdentityResource{}
var _ sdk.ResourceWithUpdate = DataFactoryCredentialUserAssignedManagedIdentityResource{}

Expand Down Expand Up @@ -98,35 +94,41 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Read() sdk.Resou
d := metadata.ResourceData
client := metadata.Client.DataFactory.Credentials

credentialId, err := credentials.ParseCredentialID(d.Id())
id, err := credentials.ParseCredentialID(d.Id())
if err != nil {
return err
}

var state DataFactoryCredentialUserAssignedManagedIdentityResourceSchema
existing, err := client.CredentialOperationsGet(ctx, *id, credentials.DefaultCredentialOperationsGetOperationOptions())
if err != nil {
if response.WasNotFound(existing.HttpResponse) {
return metadata.MarkAsGone(id)
}

existing, err := client.CredentialOperationsGet(ctx, *credentialId, credentials.CredentialOperationsGetOperationOptions{})
if err != nil && !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err)
return fmt.Errorf("retrieving %s: %+v", *id, err)
}

state.Name = credentialId.CredentialName
state := DataFactoryCredentialUserAssignedManagedIdentityResourceSchema{
Name: id.CredentialName,
DataFactoryId: factories.NewFactoryID(id.SubscriptionId, id.ResourceGroupName, id.FactoryName).ID(),
}

if existing.Model != nil {
if existing.Model.Properties.Description != nil {
state.Description = *existing.Model.Properties.Description
if model := existing.Model; model != nil {
props, ok := model.Properties.(credentials.ManagedIdentityCredential)
if !ok {
return fmt.Errorf("retrieving %s: expected `credentials.ManagedIdentityCredential` but got %+v", id, model.Properties)
}

if existing.Model.Properties.TypeProperties != nil && existing.Model.Properties.TypeProperties.ResourceId != nil {
state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId
if props.Description != nil {
state.Description = *props.Description
}

if existing.Model.Properties.Annotations != nil {
state.Annotations = flattenDataFactoryAnnotations(existing.Model.Properties.Annotations)
if props.TypeProperties.ResourceId != nil {
state.IdentityId = *props.TypeProperties.ResourceId
}
}

state.DataFactoryId = factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID()
state.Annotations = flattenDataFactoryAnnotations(props.Annotations)
}

return metadata.Encode(&state)
},
Expand All @@ -149,14 +151,8 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.R
return err
}

id := credentials.CredentialId{
SubscriptionId: dataFactoryId.SubscriptionId,
ResourceGroupName: dataFactoryId.ResourceGroupName,
FactoryName: dataFactoryId.FactoryName,
CredentialName: data.Name,
}

existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{})
id := credentials.NewCredentialID(dataFactoryId.SubscriptionId, dataFactoryId.ResourceGroupName, dataFactoryId.FactoryName, data.Name)
existing, err := client.CredentialOperationsGet(ctx, id, credentials.DefaultCredentialOperationsGetOperationOptions())
if err != nil && !response.WasNotFound(existing.HttpResponse) {
return fmt.Errorf("checking for presence of existing %s: %+v", id, err)
}
Expand All @@ -165,29 +161,26 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.R
return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID())
}

credential := credentials.ManagedIdentityCredentialResource{
Type: utils.String(IDENTITY_TYPE),
Properties: credentials.ManagedIdentityCredential{
TypeProperties: &credentials.ManagedIdentityTypeProperties{
ResourceId: &data.IdentityId,
},
props := credentials.ManagedIdentityCredential{
TypeProperties: credentials.ManagedIdentityTypeProperties{
ResourceId: &data.IdentityId,
},
}

if len(data.Annotations) > 0 {
annotations := make([]interface{}, len(data.Annotations))
for i, v := range data.Annotations {
annotations[i] = v
}
credential.Properties.Annotations = &annotations
props.Annotations = &annotations
}

if data.Description != "" {
credential.Properties.Description = &data.Description
props.Description = &data.Description
}

_, err = client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{})
if err != nil {
payload := credentials.CredentialResource{
Properties: props,
}
if _, err = client.CredentialOperationsCreateOrUpdate(ctx, id, payload, credentials.DefaultCredentialOperationsCreateOrUpdateOperationOptions()); err != nil {
return fmt.Errorf("creating %s: %+v", id, err)
}

Expand All @@ -213,19 +206,22 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Update() sdk.R
return fmt.Errorf("decoding: %+v", err)
}

existing, err := client.CredentialOperationsGet(ctx, *id, credentials.CredentialOperationsGetOperationOptions{})
existing, err := client.CredentialOperationsGet(ctx, *id, credentials.DefaultCredentialOperationsGetOperationOptions())
if err != nil {
return fmt.Errorf("checking for presence of existing %s: %+v", id.ID(), err)
}

if existing.Model == nil {
return fmt.Errorf("model was nil for %s", id)
return fmt.Errorf("retrieving %s: `model` was nil", *id)
}

credential := *existing.Model
props, ok := existing.Model.Properties.(credentials.ManagedIdentityCredential)
if !ok {
return fmt.Errorf("retrieving %s: expected `credentials.ManagedIdentityCredential` but got %+v", id, existing.Model.Properties)
}

if metadata.ResourceData.HasChange("description") {
credential.Properties.Description = &data.Description
props.Description = &data.Description
}

if metadata.ResourceData.HasChange("annotations") {
Expand All @@ -234,14 +230,16 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Update() sdk.R
for i, v := range data.Annotations {
annotations[i] = v
}
credential.Properties.Annotations = &annotations
props.Annotations = &annotations
} else {
credential.Properties.Annotations = nil
props.Annotations = nil
}
}

_, err = client.CredentialOperationsCreateOrUpdate(ctx, *id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{})
if err != nil {
payload := credentials.CredentialResource{
Properties: props,
}
if _, err = client.CredentialOperationsCreateOrUpdate(ctx, *id, payload, credentials.DefaultCredentialOperationsCreateOrUpdateOperationOptions()); err != nil {
return fmt.Errorf("updating %s: %+v", id, err)
}

Expand All @@ -256,17 +254,15 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Delete() sdk.Res
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
d := metadata.ResourceData
client := metadata.Client.DataFactory.Credentials

credentialId, err := credentials.ParseCredentialID(d.Id())
id, err := credentials.ParseCredentialID(metadata.ResourceData.Id())
if err != nil {
return err
}

_, err = client.CredentialOperationsDelete(ctx, *credentialId)
if err != nil {
return err
if _, err = client.CredentialOperationsDelete(ctx, *id); err != nil {
return fmt.Errorf("deleting %s: %+v", *id, err)
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (t CredentialUserAssignedManagedIdentityResource) Exists(ctx context.Contex
return nil, fmt.Errorf("retrieving %s: %+v", *id, err)
}

return utils.Bool(resp.Model.Id != nil), nil
return utils.Bool(resp.Model != nil), nil
}

func templateBase(data acceptance.TestData) string {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6de371

Please sign in to comment.