From 72af71710a5a9d199b4c50122b5995e55b3b2b69 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 20 Dec 2023 17:02:48 -0600 Subject: [PATCH 01/25] scaffold out credentials --- go.mod | 2 +- go.sum | 2 + .../services/datafactory/client/client.go | 2 + ...dentials_user_assigned_managed_identity.go | 111 +++++++++++++++ .../services/datafactory/parse/credential.go | 79 +++++++++++ .../2018-06-01/credentials/README.md | 90 ++++++++++++ .../2018-06-01/credentials/client.go | 26 ++++ .../2018-06-01/credentials/id_credential.go | 134 ++++++++++++++++++ .../2018-06-01/credentials/id_factory.go | 125 ++++++++++++++++ ...thod_credentialoperationscreateorupdate.go | 84 +++++++++++ .../method_credentialoperationsdelete.go | 47 ++++++ .../method_credentialoperationsget.go | 80 +++++++++++ ...ethod_credentialoperationslistbyfactory.go | 89 ++++++++++++ .../credentials/model_credential.go | 53 +++++++ .../model_managedidentitycredential.go | 43 ++++++ ...model_managedidentitycredentialresource.go | 12 ++ .../model_managedidentitytypeproperties.go | 8 ++ .../2018-06-01/credentials/predicates.go | 32 +++++ .../2018-06-01/credentials/version.go | 12 ++ vendor/modules.txt | 3 +- 20 files changed, 1032 insertions(+), 2 deletions(-) create mode 100644 internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go create mode 100644 internal/services/datafactory/parse/credential.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_credential.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_factory.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationscreateorupdate.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsdelete.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsget.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationslistbyfactory.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_credential.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredential.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredentialresource.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitytypeproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/version.go diff --git a/go.mod b/go.mod index 4091da3c01ab..7ac88f929e28 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/google/go-cmp v0.5.9 github.com/google/uuid v1.3.1 github.com/hashicorp/go-azure-helpers v0.65.0 - github.com/hashicorp/go-azure-sdk v0.20231215.1114251 + github.com/hashicorp/go-azure-sdk v0.20231220.1220246 github.com/hashicorp/go-hclog v1.5.0 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-uuid v1.0.3 diff --git a/go.sum b/go.sum index 60b1a2da3a36..7c1b79b71350 100644 --- a/go.sum +++ b/go.sum @@ -115,6 +115,8 @@ github.com/hashicorp/go-azure-helpers v0.65.0 h1:aOZV7HcxvqAlnaWJ/Fhfu321dXLs++T github.com/hashicorp/go-azure-helpers v0.65.0/go.mod h1:ELmZ65vzHJNTk6ml4jsPD+xq2gZb7t78D35s+XN02Kk= github.com/hashicorp/go-azure-sdk v0.20231215.1114251 h1:SxPZYo5UrS1HcGOkTvz9k+ymHn4EFB3I1gbBiU3DksI= github.com/hashicorp/go-azure-sdk v0.20231215.1114251/go.mod h1:69DSA+VMovHYJyQkRuUP3BCgwlEFrKvzeIHKi9m5xzY= +github.com/hashicorp/go-azure-sdk v0.20231220.1220246 h1:weUUUjjYMiz0rcgYhVPOr8wGutQQpWrE5RlboFddsyg= +github.com/hashicorp/go-azure-sdk v0.20231220.1220246/go.mod h1:69DSA+VMovHYJyQkRuUP3BCgwlEFrKvzeIHKi9m5xzY= 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/internal/services/datafactory/client/client.go b/internal/services/datafactory/client/client.go index ebe2545547cf..1b071ac08670 100644 --- a/internal/services/datafactory/client/client.go +++ b/internal/services/datafactory/client/client.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" // nolint: staticcheck + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedprivateendpoints" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedvirtualnetworks" @@ -15,6 +16,7 @@ import ( type Client struct { Factories *factories.FactoriesClient + Credentials *credentials.CredentialsClient ManagedPrivateEndpoints *managedprivateendpoints.ManagedPrivateEndpointsClient ManagedVirtualNetworks *managedvirtualnetworks.ManagedVirtualNetworksClient diff --git a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go new file mode 100644 index 000000000000..33dd2e46a483 --- /dev/null +++ b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go @@ -0,0 +1,111 @@ +package datafactory + +import ( + "fmt" + "time" + + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/parse" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, + // Read: resourceDataFactoryCustomDatasetRead, + // Update: resourceDataFactoryCustomDatasetCreateUpdate, + // Delete: resourceDataFactoryCustomDatasetDelete, + + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := parse.DataSetID(id) + return err + }), + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*pluginsdk.Schema{ + "annotations": { + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + "data_factory_id": { + Description: "ID of the Data Factory", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: factories.ValidateFactoryID, + }, + "description": { + Description: "Text description of the credential", + Type: pluginsdk.TypeString, + Optional: true, + }, + "identity_id": { + Description: "Resource ID of a User-Assigned Managed Identity", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + "name": { + Description: "Credential Name", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, // TODO: figure out whats required + }, + }, + } +} + +func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.Credentials + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + dataFactoryId, err := factories.ParseFactoryID(d.Get("data_factory_id").(string)) + if err != nil { + return err + } + + id := parse.NewCredentialId(dataFactoryId.SubscriptionId, dataFactoryId.ResourceGroupName, dataFactoryId.FactoryName, d.Get("name").(string)) + + if d.IsNewResource() { + existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + if existing.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + } + + if existing.HttpResponse.Status == "404" { + return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID()) + } + } + + credential := credentials.ManagedIdentityCredentialResource{ + Type: utils.String("ManagedIdentity"), + Properties: credentials.ManagedIdentityCredential{ + Description: utils.String(d.Get("description").(string)), + Annotations: d.Get("annotations").(*[]interface{}), + TypeProperties: &credentials.ManagedIdentityTypeProperties{ + ResourceId: utils.String(d.Get("identity_id").(string)), + }, + }, + } + + if _, err := client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } +} diff --git a/internal/services/datafactory/parse/credential.go b/internal/services/datafactory/parse/credential.go new file mode 100644 index 000000000000..1e496bbed3ba --- /dev/null +++ b/internal/services/datafactory/parse/credential.go @@ -0,0 +1,79 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package parse + +// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" +) + +type CredentialId struct { + SubscriptionId string + ResourceGroup string + FactoryName string + Name string +} + +func NewCredentialId(subscriptionId, resourceGroup, factoryName, name string) credentials.CredentialId { + return credentials.CredentialId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroup, + FactoryName: factoryName, + CredentialName: name, + } +} + +func (id CredentialId) String() string { + segments := []string{ + fmt.Sprintf("Name %q", id.Name), + fmt.Sprintf("Factory Name %q", id.FactoryName), + fmt.Sprintf("Resource Group %q", id.ResourceGroup), + } + segmentsStr := strings.Join(segments, " / ") + return fmt.Sprintf("%s: (%s)", "Credential", segmentsStr) +} + +func (id CredentialId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataFactory/factories/%s/credentials/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.FactoryName, id.Name) +} + +// CredentialId parses a Credential ID into an CredentialId struct +func CredentialID(input string) (*CredentialId, error) { + id, err := resourceids.ParseAzureResourceID(input) + if err != nil { + return nil, fmt.Errorf("parsing %q as a Credential ID: %+v", input, err) + } + + resourceId := CredentialId{ + SubscriptionId: id.SubscriptionID, + ResourceGroup: id.ResourceGroup, + } + + if resourceId.SubscriptionId == "" { + return nil, fmt.Errorf("ID was missing the 'subscriptions' element") + } + + if resourceId.ResourceGroup == "" { + return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") + } + + if resourceId.FactoryName, err = id.PopSegment("factories"); err != nil { + return nil, err + } + if resourceId.Name, err = id.PopSegment("credentials"); err != nil { + return nil, err + } + + if err := id.ValidateNoEmptySegments(input); err != nil { + return nil, err + } + + return &resourceId, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/README.md new file mode 100644 index 000000000000..91660d2118df --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/README.md @@ -0,0 +1,90 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials` Documentation + +The `credentials` SDK allows for interaction with the Azure Resource Manager Service `datafactory` (API Version `2018-06-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" +``` + + +### Client Initialization + +```go +client := credentials.NewCredentialsClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `CredentialsClient.CredentialOperationsCreateOrUpdate` + +```go +ctx := context.TODO() +id := credentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "factoryValue", "credentialValue") + +payload := credentials.ManagedIdentityCredentialResource{ + // ... +} + + +read, err := client.CredentialOperationsCreateOrUpdate(ctx, id, payload, credentials.DefaultCredentialOperationsCreateOrUpdateOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CredentialsClient.CredentialOperationsDelete` + +```go +ctx := context.TODO() +id := credentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "factoryValue", "credentialValue") + +read, err := client.CredentialOperationsDelete(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CredentialsClient.CredentialOperationsGet` + +```go +ctx := context.TODO() +id := credentials.NewCredentialID("12345678-1234-9876-4563-123456789012", "example-resource-group", "factoryValue", "credentialValue") + +read, err := client.CredentialOperationsGet(ctx, id, credentials.DefaultCredentialOperationsGetOperationOptions()) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `CredentialsClient.CredentialOperationsListByFactory` + +```go +ctx := context.TODO() +id := credentials.NewFactoryID("12345678-1234-9876-4563-123456789012", "example-resource-group", "factoryValue") + +// alternatively `client.CredentialOperationsListByFactory(ctx, id)` can be used to do batched pagination +items, err := client.CredentialOperationsListByFactoryComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/client.go new file mode 100644 index 000000000000..47d62cef53e3 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/client.go @@ -0,0 +1,26 @@ +package credentials + +import ( + "fmt" + + "github.com/hashicorp/go-azure-sdk/sdk/client/resourcemanager" + sdkEnv "github.com/hashicorp/go-azure-sdk/sdk/environments" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialsClient struct { + Client *resourcemanager.Client +} + +func NewCredentialsClientWithBaseURI(sdkApi sdkEnv.Api) (*CredentialsClient, error) { + client, err := resourcemanager.NewResourceManagerClient(sdkApi, "credentials", defaultApiVersion) + if err != nil { + return nil, fmt.Errorf("instantiating CredentialsClient: %+v", err) + } + + return &CredentialsClient{ + Client: client, + }, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_credential.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_credential.go new file mode 100644 index 000000000000..97469b0a6be2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_credential.go @@ -0,0 +1,134 @@ +package credentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = CredentialId{} + +// CredentialId is a struct representing the Resource ID for a Credential +type CredentialId struct { + SubscriptionId string + ResourceGroupName string + FactoryName string + CredentialName string +} + +// NewCredentialID returns a new CredentialId struct +func NewCredentialID(subscriptionId string, resourceGroupName string, factoryName string, credentialName string) CredentialId { + return CredentialId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + FactoryName: factoryName, + CredentialName: credentialName, + } +} + +// ParseCredentialID parses 'input' into a CredentialId +func ParseCredentialID(input string) (*CredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(CredentialId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseCredentialIDInsensitively parses 'input' case-insensitively into a CredentialId +// note: this method should only be used for API response data and not user input +func ParseCredentialIDInsensitively(input string) (*CredentialId, error) { + parser := resourceids.NewParserFromResourceIdType(CredentialId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := CredentialId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *CredentialId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.FactoryName, ok = input.Parsed["factoryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "factoryName", input) + } + + if id.CredentialName, ok = input.Parsed["credentialName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "credentialName", input) + } + + return nil +} + +// ValidateCredentialID checks that 'input' can be parsed as a Credential ID +func ValidateCredentialID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseCredentialID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Credential ID +func (id CredentialId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataFactory/factories/%s/credentials/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.FactoryName, id.CredentialName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Credential ID +func (id CredentialId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDataFactory", "Microsoft.DataFactory", "Microsoft.DataFactory"), + resourceids.StaticSegment("staticFactories", "factories", "factories"), + resourceids.UserSpecifiedSegment("factoryName", "factoryValue"), + resourceids.StaticSegment("staticCredentials", "credentials", "credentials"), + resourceids.UserSpecifiedSegment("credentialName", "credentialValue"), + } +} + +// String returns a human-readable description of this Credential ID +func (id CredentialId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Factory Name: %q", id.FactoryName), + fmt.Sprintf("Credential Name: %q", id.CredentialName), + } + return fmt.Sprintf("Credential (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_factory.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_factory.go new file mode 100644 index 000000000000..13d718f7fa01 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/id_factory.go @@ -0,0 +1,125 @@ +package credentials + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = FactoryId{} + +// FactoryId is a struct representing the Resource ID for a Factory +type FactoryId struct { + SubscriptionId string + ResourceGroupName string + FactoryName string +} + +// NewFactoryID returns a new FactoryId struct +func NewFactoryID(subscriptionId string, resourceGroupName string, factoryName string) FactoryId { + return FactoryId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + FactoryName: factoryName, + } +} + +// ParseFactoryID parses 'input' into a FactoryId +func ParseFactoryID(input string) (*FactoryId, error) { + parser := resourceids.NewParserFromResourceIdType(FactoryId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FactoryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +// ParseFactoryIDInsensitively parses 'input' case-insensitively into a FactoryId +// note: this method should only be used for API response data and not user input +func ParseFactoryIDInsensitively(input string) (*FactoryId, error) { + parser := resourceids.NewParserFromResourceIdType(FactoryId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + id := FactoryId{} + if err := id.FromParseResult(*parsed); err != nil { + return nil, err + } + + return &id, nil +} + +func (id *FactoryId) FromParseResult(input resourceids.ParseResult) error { + var ok bool + + if id.SubscriptionId, ok = input.Parsed["subscriptionId"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "subscriptionId", input) + } + + if id.ResourceGroupName, ok = input.Parsed["resourceGroupName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "resourceGroupName", input) + } + + if id.FactoryName, ok = input.Parsed["factoryName"]; !ok { + return resourceids.NewSegmentNotSpecifiedError(id, "factoryName", input) + } + + return nil +} + +// ValidateFactoryID checks that 'input' can be parsed as a Factory ID +func ValidateFactoryID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseFactoryID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Factory ID +func (id FactoryId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataFactory/factories/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.FactoryName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Factory ID +func (id FactoryId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftDataFactory", "Microsoft.DataFactory", "Microsoft.DataFactory"), + resourceids.StaticSegment("staticFactories", "factories", "factories"), + resourceids.UserSpecifiedSegment("factoryName", "factoryValue"), + } +} + +// String returns a human-readable description of this Factory ID +func (id FactoryId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Factory Name: %q", id.FactoryName), + } + return fmt.Sprintf("Factory (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationscreateorupdate.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationscreateorupdate.go new file mode 100644 index 000000000000..95c4a639d8f1 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationscreateorupdate.go @@ -0,0 +1,84 @@ +package credentials + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialOperationsCreateOrUpdateOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedIdentityCredentialResource +} + +type CredentialOperationsCreateOrUpdateOperationOptions struct { + IfMatch *string +} + +func DefaultCredentialOperationsCreateOrUpdateOperationOptions() CredentialOperationsCreateOrUpdateOperationOptions { + return CredentialOperationsCreateOrUpdateOperationOptions{} +} + +func (o CredentialOperationsCreateOrUpdateOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfMatch != nil { + out.Append("If-Match", fmt.Sprintf("%v", *o.IfMatch)) + } + return &out +} + +func (o CredentialOperationsCreateOrUpdateOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CredentialOperationsCreateOrUpdateOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CredentialOperationsCreateOrUpdate ... +func (c CredentialsClient) CredentialOperationsCreateOrUpdate(ctx context.Context, id CredentialId, input ManagedIdentityCredentialResource, options CredentialOperationsCreateOrUpdateOperationOptions) (result CredentialOperationsCreateOrUpdateOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodPut, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + if err = req.Marshal(input); err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsdelete.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsdelete.go new file mode 100644 index 000000000000..ad7d54f0dbee --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsdelete.go @@ -0,0 +1,47 @@ +package credentials + +import ( + "context" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialOperationsDeleteOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData +} + +// CredentialOperationsDelete ... +func (c CredentialsClient) CredentialOperationsDelete(ctx context.Context, id CredentialId) (result CredentialOperationsDeleteOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusNoContent, + http.StatusOK, + }, + HttpMethod: http.MethodDelete, + Path: id.ID(), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsget.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsget.go new file mode 100644 index 000000000000..976dde1f10d0 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationsget.go @@ -0,0 +1,80 @@ +package credentials + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialOperationsGetOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *ManagedIdentityCredentialResource +} + +type CredentialOperationsGetOperationOptions struct { + IfNoneMatch *string +} + +func DefaultCredentialOperationsGetOperationOptions() CredentialOperationsGetOperationOptions { + return CredentialOperationsGetOperationOptions{} +} + +func (o CredentialOperationsGetOperationOptions) ToHeaders() *client.Headers { + out := client.Headers{} + if o.IfNoneMatch != nil { + out.Append("If-None-Match", fmt.Sprintf("%v", *o.IfNoneMatch)) + } + return &out +} + +func (o CredentialOperationsGetOperationOptions) ToOData() *odata.Query { + out := odata.Query{} + return &out +} + +func (o CredentialOperationsGetOperationOptions) ToQuery() *client.QueryParams { + out := client.QueryParams{} + + return &out +} + +// CredentialOperationsGet ... +func (c CredentialsClient) CredentialOperationsGet(ctx context.Context, id CredentialId, options CredentialOperationsGetOperationOptions) (result CredentialOperationsGetOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: id.ID(), + OptionsObject: options, + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.Execute(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + if err = resp.Unmarshal(&result.Model); err != nil { + return + } + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationslistbyfactory.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationslistbyfactory.go new file mode 100644 index 000000000000..e9cc94b04111 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/method_credentialoperationslistbyfactory.go @@ -0,0 +1,89 @@ +package credentials + +import ( + "context" + "fmt" + "net/http" + + "github.com/hashicorp/go-azure-sdk/sdk/client" + "github.com/hashicorp/go-azure-sdk/sdk/odata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialOperationsListByFactoryOperationResponse struct { + HttpResponse *http.Response + OData *odata.OData + Model *[]ManagedIdentityCredentialResource +} + +type CredentialOperationsListByFactoryCompleteResult struct { + Items []ManagedIdentityCredentialResource +} + +// CredentialOperationsListByFactory ... +func (c CredentialsClient) CredentialOperationsListByFactory(ctx context.Context, id FactoryId) (result CredentialOperationsListByFactoryOperationResponse, err error) { + opts := client.RequestOptions{ + ContentType: "application/json; charset=utf-8", + ExpectedStatusCodes: []int{ + http.StatusOK, + }, + HttpMethod: http.MethodGet, + Path: fmt.Sprintf("%s/credentials", id.ID()), + } + + req, err := c.Client.NewRequest(ctx, opts) + if err != nil { + return + } + + var resp *client.Response + resp, err = req.ExecutePaged(ctx) + if resp != nil { + result.OData = resp.OData + result.HttpResponse = resp.Response + } + if err != nil { + return + } + + var values struct { + Values *[]ManagedIdentityCredentialResource `json:"value"` + } + if err = resp.Unmarshal(&values); err != nil { + return + } + + result.Model = values.Values + + return +} + +// CredentialOperationsListByFactoryComplete retrieves all the results into a single object +func (c CredentialsClient) CredentialOperationsListByFactoryComplete(ctx context.Context, id FactoryId) (CredentialOperationsListByFactoryCompleteResult, error) { + return c.CredentialOperationsListByFactoryCompleteMatchingPredicate(ctx, id, ManagedIdentityCredentialResourceOperationPredicate{}) +} + +// CredentialOperationsListByFactoryCompleteMatchingPredicate retrieves all the results and then applies the predicate +func (c CredentialsClient) CredentialOperationsListByFactoryCompleteMatchingPredicate(ctx context.Context, id FactoryId, predicate ManagedIdentityCredentialResourceOperationPredicate) (result CredentialOperationsListByFactoryCompleteResult, err error) { + items := make([]ManagedIdentityCredentialResource, 0) + + resp, err := c.CredentialOperationsListByFactory(ctx, id) + if err != nil { + err = fmt.Errorf("loading results: %+v", err) + return + } + if resp.Model != nil { + for _, v := range *resp.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + result = CredentialOperationsListByFactoryCompleteResult{ + Items: items, + } + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_credential.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_credential.go new file mode 100644 index 000000000000..24c0af8199e5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_credential.go @@ -0,0 +1,53 @@ +package credentials + +import ( + "encoding/json" + "fmt" + "strings" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type Credential interface { +} + +// RawCredentialImpl is returned when the Discriminated Value +// doesn't match any of the defined types +// NOTE: this should only be used when a type isn't defined for this type of Object (as a workaround) +// and is used only for Deserialization (e.g. this cannot be used as a Request Payload). +type RawCredentialImpl struct { + Type string + Values map[string]interface{} +} + +func unmarshalCredentialImplementation(input []byte) (Credential, error) { + if input == nil { + return nil, nil + } + + var temp map[string]interface{} + if err := json.Unmarshal(input, &temp); err != nil { + return nil, fmt.Errorf("unmarshaling Credential into map[string]interface: %+v", err) + } + + value, ok := temp["type"].(string) + if !ok { + return nil, nil + } + + if strings.EqualFold(value, "ManagedIdentity") { + var out ManagedIdentityCredential + if err := json.Unmarshal(input, &out); err != nil { + return nil, fmt.Errorf("unmarshaling into ManagedIdentityCredential: %+v", err) + } + return out, nil + } + + out := RawCredentialImpl{ + Type: value, + Values: temp, + } + return out, nil + +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredential.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredential.go new file mode 100644 index 000000000000..e17dc212836f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredential.go @@ -0,0 +1,43 @@ +package credentials + +import ( + "encoding/json" + "fmt" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ Credential = ManagedIdentityCredential{} + +type ManagedIdentityCredential struct { + TypeProperties *ManagedIdentityTypeProperties `json:"typeProperties,omitempty"` + + // Fields inherited from Credential + Annotations *[]interface{} `json:"annotations,omitempty"` + Description *string `json:"description,omitempty"` +} + +var _ json.Marshaler = ManagedIdentityCredential{} + +func (s ManagedIdentityCredential) MarshalJSON() ([]byte, error) { + type wrapper ManagedIdentityCredential + wrapped := wrapper(s) + encoded, err := json.Marshal(wrapped) + if err != nil { + return nil, fmt.Errorf("marshaling ManagedIdentityCredential: %+v", err) + } + + var decoded map[string]interface{} + if err := json.Unmarshal(encoded, &decoded); err != nil { + return nil, fmt.Errorf("unmarshaling ManagedIdentityCredential: %+v", err) + } + decoded["type"] = "ManagedIdentity" + + encoded, err = json.Marshal(decoded) + if err != nil { + return nil, fmt.Errorf("re-marshaling ManagedIdentityCredential: %+v", err) + } + + return encoded, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredentialresource.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredentialresource.go new file mode 100644 index 000000000000..d25df590a8ca --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitycredentialresource.go @@ -0,0 +1,12 @@ +package credentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentityCredentialResource struct { + Etag *string `json:"etag,omitempty"` + Id *string `json:"id,omitempty"` + Name *string `json:"name,omitempty"` + Properties ManagedIdentityCredential `json:"properties"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitytypeproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitytypeproperties.go new file mode 100644 index 000000000000..d2a070612f48 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/model_managedidentitytypeproperties.go @@ -0,0 +1,8 @@ +package credentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentityTypeProperties struct { + ResourceId *string `json:"resourceId,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/predicates.go new file mode 100644 index 000000000000..b0f15d4d51bb --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/predicates.go @@ -0,0 +1,32 @@ +package credentials + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ManagedIdentityCredentialResourceOperationPredicate struct { + Etag *string + Id *string + Name *string + Type *string +} + +func (p ManagedIdentityCredentialResourceOperationPredicate) Matches(input ManagedIdentityCredentialResource) bool { + + if p.Etag != nil && (input.Etag == nil || *p.Etag != *input.Etag) { + return false + } + + if p.Id != nil && (input.Id == nil || *p.Id != *input.Id) { + return false + } + + if p.Name != nil && (input.Name == nil || *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil || *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/version.go new file mode 100644 index 000000000000..c75056fd9a4b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials/version.go @@ -0,0 +1,12 @@ +package credentials + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2018-06-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/credentials/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index d3f8d7d27c08..5656b948b43a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -157,7 +157,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.20231215.1114251 +# github.com/hashicorp/go-azure-sdk v0.20231220.1220246 ## explicit; go 1.21 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 @@ -391,6 +391,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/monitorsre github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/refreshsetpasswordlink github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/rules github.com/hashicorp/go-azure-sdk/resource-manager/datadog/2021-03-01/singlesignon +github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedprivateendpoints github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/managedvirtualnetworks From 59bd5bbb63ac456e568ff69864184724ab189606 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 20 Dec 2023 22:10:11 -0600 Subject: [PATCH 02/25] wip --- ...dentials_user_assigned_managed_identity.go | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go index 33dd2e46a483..d025c8829be0 100644 --- a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go @@ -69,6 +69,9 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso } } +// user managed identities only have one type +const IDENTITY_TYPE = "ManagedIdentity" + func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).DataFactory.Credentials ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) @@ -95,17 +98,33 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl } credential := credentials.ManagedIdentityCredentialResource{ - Type: utils.String("ManagedIdentity"), - Properties: credentials.ManagedIdentityCredential{ - Description: utils.String(d.Get("description").(string)), - Annotations: d.Get("annotations").(*[]interface{}), - TypeProperties: &credentials.ManagedIdentityTypeProperties{ - ResourceId: utils.String(d.Get("identity_id").(string)), - }, - }, + Type: utils.String(IDENTITY_TYPE), + Properties: credentials.ManagedIdentityCredential{}, + } + + if v, ok := d.GetOk("annotations"); ok { + annotations := v.([]interface{}) + credential.Properties.Annotations = &annotations + } + + if v, ok := d.GetOk("description"); ok { + description := v.(string) + credential.Properties.Description = &description + } + + if v, ok := d.GetOk("identity_id"); ok { + identityId := v.(string) + credential.Properties.TypeProperties.ResourceId = &identityId } if _, err := client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}); err != nil { return fmt.Errorf("creating %s: %+v", id, err) } + + d.SetId(id.ID()) + + return resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d, meta) +} + +func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk.ResourceData, meta interface{}) error { } From 344996e74a74750cb362cd4b5e8d54430e8ed8ca Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 09:47:00 -0600 Subject: [PATCH 03/25] refactor --- ...dentials_user_assigned_managed_identity.go | 35 +++++++++++++-- .../services/datafactory/parse/credential.go | 43 ++----------------- internal/services/datafactory/registration.go | 1 + 3 files changed, 37 insertions(+), 42 deletions(-) diff --git a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go index d025c8829be0..207d24693e07 100644 --- a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go @@ -17,8 +17,8 @@ import ( func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Resource { return &pluginsdk.Resource{ Create: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, - // Read: resourceDataFactoryCustomDatasetRead, - // Update: resourceDataFactoryCustomDatasetCreateUpdate, + Read: resourceDataFactoryCredentialsUserAssignedManagedIdentityRead, + Update: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, // Delete: resourceDataFactoryCustomDatasetDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { @@ -82,7 +82,12 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl return err } - id := parse.NewCredentialId(dataFactoryId.SubscriptionId, dataFactoryId.ResourceGroupName, dataFactoryId.FactoryName, d.Get("name").(string)) + id := credentials.CredentialId{ + SubscriptionId: dataFactoryId.SubscriptionId, + ResourceGroupName: dataFactoryId.ResourceGroupName, + FactoryName: dataFactoryId.FactoryName, + CredentialName: d.Get("name").(string), + } if d.IsNewResource() { existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) @@ -127,4 +132,28 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl } func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.Credentials + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + credentialId, err := parse.CredentialID(d.Id()) + if err != nil { + return err + } + + existing, err := client.CredentialOperationsGet(ctx, *credentialId, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + if existing.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) + } + } + + d.Set("name", credentialId.CredentialName) + d.Set("data_factory_id", credentialId.FactoryName) + d.Set("description", existing.Model.Properties.Description) + if err := d.Set("annotations", flattenDataFactoryAnnotations(existing.Model.Properties.Annotations)); err != nil { + return fmt.Errorf("setting `annotations`: %+v", err) + } + + return nil } diff --git a/internal/services/datafactory/parse/credential.go b/internal/services/datafactory/parse/credential.go index 1e496bbed3ba..49708bbd0edf 100644 --- a/internal/services/datafactory/parse/credential.go +++ b/internal/services/datafactory/parse/credential.go @@ -7,67 +7,32 @@ package parse import ( "fmt" - "strings" "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" ) -type CredentialId struct { - SubscriptionId string - ResourceGroup string - FactoryName string - Name string -} - -func NewCredentialId(subscriptionId, resourceGroup, factoryName, name string) credentials.CredentialId { - return credentials.CredentialId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroup, - FactoryName: factoryName, - CredentialName: name, - } -} - -func (id CredentialId) String() string { - segments := []string{ - fmt.Sprintf("Name %q", id.Name), - fmt.Sprintf("Factory Name %q", id.FactoryName), - fmt.Sprintf("Resource Group %q", id.ResourceGroup), - } - segmentsStr := strings.Join(segments, " / ") - return fmt.Sprintf("%s: (%s)", "Credential", segmentsStr) -} - -func (id CredentialId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.DataFactory/factories/%s/credentials/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroup, id.FactoryName, id.Name) -} - // CredentialId parses a Credential ID into an CredentialId struct -func CredentialID(input string) (*CredentialId, error) { +func CredentialID(input string) (*credentials.CredentialId, error) { id, err := resourceids.ParseAzureResourceID(input) if err != nil { return nil, fmt.Errorf("parsing %q as a Credential ID: %+v", input, err) } - resourceId := CredentialId{ - SubscriptionId: id.SubscriptionID, - ResourceGroup: id.ResourceGroup, - } + resourceId := credentials.CredentialId{} if resourceId.SubscriptionId == "" { return nil, fmt.Errorf("ID was missing the 'subscriptions' element") } - if resourceId.ResourceGroup == "" { + if resourceId.ResourceGroupName == "" { return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") } if resourceId.FactoryName, err = id.PopSegment("factories"); err != nil { return nil, err } - if resourceId.Name, err = id.PopSegment("credentials"); err != nil { + if resourceId.CredentialName, err = id.PopSegment("credentials"); err != nil { return nil, err } diff --git a/internal/services/datafactory/registration.go b/internal/services/datafactory/registration.go index f83da8a69c5a..200cd1db55e7 100644 --- a/internal/services/datafactory/registration.go +++ b/internal/services/datafactory/registration.go @@ -64,6 +64,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_data_factory_dataset_snowflake": resourceDataFactoryDatasetSnowflake(), "azurerm_data_factory_dataset_sql_server_table": resourceDataFactoryDatasetSQLServerTable(), "azurerm_data_factory_custom_dataset": resourceDataFactoryCustomDataset(), + "azurerm_data_factory_credential_user_managed_identity": resourceDataFactoryCredentialsUserAssignedManagedIdentity(), "azurerm_data_factory_integration_runtime_managed": resourceDataFactoryIntegrationRuntimeManaged(), "azurerm_data_factory_integration_runtime_azure": resourceDataFactoryIntegrationRuntimeAzure(), "azurerm_data_factory_integration_runtime_azure_ssis": resourceDataFactoryIntegrationRuntimeAzureSsis(), From 4296d5ffd8cf20c0625454a4ad86b4a24b57d222 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 09:49:03 -0600 Subject: [PATCH 04/25] add delete method; --- ...dentials_user_assigned_managed_identity.go | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go index 207d24693e07..8f70dcb98273 100644 --- a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go @@ -19,7 +19,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso Create: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, Read: resourceDataFactoryCredentialsUserAssignedManagedIdentityRead, Update: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, - // Delete: resourceDataFactoryCustomDatasetDelete, + Delete: resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { _, err := parse.DataSetID(id) @@ -133,7 +133,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk.ResourceData, meta interface{}) error { client := meta.(*clients.Client).DataFactory.Credentials - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() credentialId, err := parse.CredentialID(d.Id()) @@ -157,3 +157,21 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk. return nil } + +func resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.Credentials + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + credentialId, err := parse.CredentialID(d.Id()) + if err != nil { + return err + } + + resp, err := client.CredentialOperationsDelete(ctx, *credentialId) + if err != nil { + if resp.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) + } + } +} From 29f2f4b1f9884109f7fb7d65dc3bae022d423a78 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 10:06:29 -0600 Subject: [PATCH 05/25] rename file --- ...ctory_credential_user_assigned_managed_identity.go} | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) rename internal/services/datafactory/{data_factory_credentials_user_assigned_managed_identity.go => data_factory_credential_user_assigned_managed_identity.go} (96%) diff --git a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go similarity index 96% rename from internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go rename to internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 8f70dcb98273..29dd028e47fb 100644 --- a/internal/services/datafactory/data_factory_credentials_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -22,7 +22,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso Delete: resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.DataSetID(id) + _, err := parse.CredentialID(id) return err }), @@ -168,10 +168,10 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete(d *pluginsd return err } - resp, err := client.CredentialOperationsDelete(ctx, *credentialId) + _, err = client.CredentialOperationsDelete(ctx, *credentialId) if err != nil { - if resp.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) - } + return err } + + return nil } From 8ec98386595199df9d9595b97786616412cfc53b Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 10:24:59 -0600 Subject: [PATCH 06/25] tidy --- go.sum | 2 -- ...data_factory_credential_user_assigned_managed_identity.go | 5 ++--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/go.sum b/go.sum index 7c1b79b71350..b72a092edf6e 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,6 @@ 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.65.0 h1:aOZV7HcxvqAlnaWJ/Fhfu321dXLs++TyBIVelWOb/8w= github.com/hashicorp/go-azure-helpers v0.65.0/go.mod h1:ELmZ65vzHJNTk6ml4jsPD+xq2gZb7t78D35s+XN02Kk= -github.com/hashicorp/go-azure-sdk v0.20231215.1114251 h1:SxPZYo5UrS1HcGOkTvz9k+ymHn4EFB3I1gbBiU3DksI= -github.com/hashicorp/go-azure-sdk v0.20231215.1114251/go.mod h1:69DSA+VMovHYJyQkRuUP3BCgwlEFrKvzeIHKi9m5xzY= github.com/hashicorp/go-azure-sdk v0.20231220.1220246 h1:weUUUjjYMiz0rcgYhVPOr8wGutQQpWrE5RlboFddsyg= github.com/hashicorp/go-azure-sdk v0.20231220.1220246/go.mod h1:69DSA+VMovHYJyQkRuUP3BCgwlEFrKvzeIHKi9m5xzY= github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU= diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 29dd028e47fb..1e80283e89bb 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -5,7 +5,6 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" - "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/parse" @@ -46,7 +45,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso Type: pluginsdk.TypeString, Required: true, ForceNew: true, - ValidateFunc: factories.ValidateFactoryID, + ValidateFunc: credentials.ValidateFactoryID, }, "description": { Description: "Text description of the credential", @@ -77,7 +76,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - dataFactoryId, err := factories.ParseFactoryID(d.Get("data_factory_id").(string)) + dataFactoryId, err := credentials.ParseFactoryID(d.Get("data_factory_id").(string)) if err != nil { return err } From 3b69e4d9651d32b390e038d10fd9cc4e2b1166e3 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 13:07:32 -0600 Subject: [PATCH 07/25] basic crud working --- .../services/datafactory/client/client.go | 7 +++ ...edential_user_assigned_managed_identity.go | 27 ++++++------ .../services/datafactory/parse/credential.go | 44 ------------------- 3 files changed, 21 insertions(+), 57 deletions(-) delete mode 100644 internal/services/datafactory/parse/credential.go diff --git a/internal/services/datafactory/client/client.go b/internal/services/datafactory/client/client.go index 1b071ac08670..809802bc9b37 100644 --- a/internal/services/datafactory/client/client.go +++ b/internal/services/datafactory/client/client.go @@ -36,6 +36,12 @@ func NewClient(o *common.ClientOptions) (*Client, error) { } o.Configure(factoriesClient.Client, o.Authorizers.ResourceManager) + credentialsClient, err := credentials.NewCredentialsClientWithBaseURI(o.Environment.ResourceManager) + if err != nil { + return nil, fmt.Errorf("building Factories client: %+v", err) + } + o.Configure(credentialsClient.Client, o.Authorizers.ResourceManager) + managedPrivateEndpointsClient, err := managedprivateendpoints.NewManagedPrivateEndpointsClientWithBaseURI(o.Environment.ResourceManager) if err != nil { return nil, fmt.Errorf("building ManagedPrivateEndpoints client: %+v", err) @@ -69,6 +75,7 @@ func NewClient(o *common.ClientOptions) (*Client, error) { return &Client{ Factories: factoriesClient, + Credentials: credentialsClient, ManagedPrivateEndpoints: managedPrivateEndpointsClient, ManagedVirtualNetworks: managedVirtualNetworksClient, diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 1e80283e89bb..3d5aebc570eb 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -7,7 +7,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" @@ -21,7 +20,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso Delete: resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.CredentialID(id) + _, err := credentials.ParseCredentialID(id) return err }), @@ -33,7 +32,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso }, Schema: map[string]*pluginsdk.Schema{ - "annotations": { + "annotations": { // annotations not visible in portal Type: pluginsdk.TypeList, Optional: true, Elem: &pluginsdk.Schema{ @@ -41,7 +40,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso }, }, "data_factory_id": { - Description: "ID of the Data Factory", + Description: "Resource ID of the Data Factory", Type: pluginsdk.TypeString, Required: true, ForceNew: true, @@ -56,13 +55,12 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Reso Description: "Resource ID of a User-Assigned Managed Identity", Type: pluginsdk.TypeString, Required: true, - ForceNew: true, }, "name": { Description: "Credential Name", Type: pluginsdk.TypeString, Required: true, - ForceNew: true, // TODO: figure out whats required + ForceNew: true, }, }, } @@ -102,8 +100,10 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl } credential := credentials.ManagedIdentityCredentialResource{ - Type: utils.String(IDENTITY_TYPE), - Properties: credentials.ManagedIdentityCredential{}, + Type: utils.String(IDENTITY_TYPE), + Properties: credentials.ManagedIdentityCredential{ + TypeProperties: &credentials.ManagedIdentityTypeProperties{}, + }, } if v, ok := d.GetOk("annotations"); ok { @@ -121,11 +121,12 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pl credential.Properties.TypeProperties.ResourceId = &identityId } - if _, err := client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}); err != nil { + resp, err := client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) + if err != nil { return fmt.Errorf("creating %s: %+v", id, err) } - d.SetId(id.ID()) + d.SetId(*resp.Model.Id) return resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d, meta) } @@ -135,7 +136,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk. ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - credentialId, err := parse.CredentialID(d.Id()) + credentialId, err := credentials.ParseCredentialID(d.Id()) if err != nil { return err } @@ -148,11 +149,11 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk. } d.Set("name", credentialId.CredentialName) - d.Set("data_factory_id", credentialId.FactoryName) d.Set("description", existing.Model.Properties.Description) if err := d.Set("annotations", flattenDataFactoryAnnotations(existing.Model.Properties.Annotations)); err != nil { return fmt.Errorf("setting `annotations`: %+v", err) } + d.Set("identity_id", existing.Model.Properties.TypeProperties.ResourceId) return nil } @@ -162,7 +163,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete(d *pluginsd ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - credentialId, err := parse.CredentialID(d.Id()) + credentialId, err := credentials.ParseCredentialID(d.Id()) if err != nil { return err } diff --git a/internal/services/datafactory/parse/credential.go b/internal/services/datafactory/parse/credential.go deleted file mode 100644 index 49708bbd0edf..000000000000 --- a/internal/services/datafactory/parse/credential.go +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package parse - -// NOTE: this file is generated via 'go:generate' - manual changes will be overwritten - -import ( - "fmt" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" - "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" -) - -// CredentialId parses a Credential ID into an CredentialId struct -func CredentialID(input string) (*credentials.CredentialId, error) { - id, err := resourceids.ParseAzureResourceID(input) - if err != nil { - return nil, fmt.Errorf("parsing %q as a Credential ID: %+v", input, err) - } - - resourceId := credentials.CredentialId{} - - if resourceId.SubscriptionId == "" { - return nil, fmt.Errorf("ID was missing the 'subscriptions' element") - } - - if resourceId.ResourceGroupName == "" { - return nil, fmt.Errorf("ID was missing the 'resourceGroups' element") - } - - if resourceId.FactoryName, err = id.PopSegment("factories"); err != nil { - return nil, err - } - if resourceId.CredentialName, err = id.PopSegment("credentials"); err != nil { - return nil, err - } - - if err := id.ValidateNoEmptySegments(input); err != nil { - return nil, err - } - - return &resourceId, nil -} From e995d76af2f81f56a41f79a0af46892181c6146c Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 13:29:24 -0600 Subject: [PATCH 08/25] import without causing diff --- .../data_factory_credential_user_assigned_managed_identity.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 3d5aebc570eb..bcc297a3c0d9 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -5,6 +5,7 @@ import ( "time" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -154,6 +155,7 @@ func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk. return fmt.Errorf("setting `annotations`: %+v", err) } d.Set("identity_id", existing.Model.Properties.TypeProperties.ResourceId) + d.Set("data_factory_id", factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID()) return nil } From 0e6aea0fe0600cc2544a28cbc9a5bfd2a848b9bf Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 13:41:32 -0600 Subject: [PATCH 09/25] add documentation --- ...er_assigned_managed_identity.html.markdown | 95 +++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown new file mode 100644 index 000000000000..29f77f145eae --- /dev/null +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -0,0 +1,95 @@ +--- +subcategory: "Data Factory" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_factory_credential_user_managed_identity" +description: |- + Manage a Data Factory User Assigned Managed Identity resource +--- + +# azurerm_data_factory_credential_user_managed_identity + +Manage a Data Factory User Assigned Managed Identity resource + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "westus" +} + +resource "azurerm_data_factory" "example" { + name = "bruceharrison-12334" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.example.id] + } +} + +resource "azurerm_user_assigned_identity" "example" { + location = azurerm_resource_group.example.location + name = "my-user" + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_data_factory_credential_user_managed_identity" "test" { + name = azurerm_user_assigned_identity.example.name + description = "Short description of this credential" + data_factory_id = azurerm_data_factory.example.id + identity_id = azurerm_user_assigned_identity.example.id + + annotations = ["example", "example2"] +} +``` + +## Argument Reference + +* `name` - (Required) Specifies the name of the credential. Changing this forces a new resource to be created. + +* `data_factory_id` - (Required) The Data Factory ID in which to associate the Credential with. Changing this forces a new resource. + +* `identity_id` - (Required) The Resouce ID of an existing User Assigned Managed Identity. This can be changed without recreating the resource. + +~> **Note:** The User Assigned Managed Identity must also be assigned to the parent Data Factory. Attempting to create a Credentials resource without + first doing this will result in an Azure API error. + +* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Dataset. + +* `description` - (Optional) The description for the Data Factory Dataset. + +--- + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Data Factory Dataset. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Data Factory Dataset. +* `update` - (Defaults to 30 minutes) Used when updating the Data Factory Dataset. +* `read` - (Defaults to 5 minutes) Used when retrieving the Data Factory Dataset. +* `delete` - (Defaults to 30 minutes) Used when deleting the Data Factory Dataset. + +## Import + +Data Factory Credentials can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_data_factory_credential_user_managed_identity.example /subscriptions/1f3d6e58-feed-4bb6-87e5-a52305ad3375/resourceGroups/example-resources/providers/Microsoft.DataFactory/factories/bruceharrison-12334/credentials/credential1 +``` + +HCL import blocks can also be used for import + +```hcl +import { + to = azurerm_data_factory_credential_user_managed_identity.test + id = "/subscriptions/1f3d6e58-feed-4bb6-87e5-a52305ad3375/resourceGroups/example-resources/providers/Microsoft.DataFactory/factories/bruceharrison-12334/credentials/credential1" +} +``` From 536acf7a67d89f35272174d46bfdce538d43e448 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 13:47:35 -0600 Subject: [PATCH 10/25] update docs --- ...credential_user_assigned_managed_identity.html.markdown | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown index 29f77f145eae..0d38f3d8c1d2 100644 --- a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -3,12 +3,12 @@ subcategory: "Data Factory" layout: "azurerm" page_title: "Azure Resource Manager: azurerm_data_factory_credential_user_managed_identity" description: |- - Manage a Data Factory User Assigned Managed Identity resource + Manage a Data Factory User Assigned Managed Identity credential resource --- # azurerm_data_factory_credential_user_managed_identity -Manage a Data Factory User Assigned Managed Identity resource +Manage a Data Factory User Assigned Managed Identity credential resource. These resources are used by Data Factory to access data sources. ## Example Usage @@ -53,8 +53,7 @@ resource "azurerm_data_factory_credential_user_managed_identity" "test" { * `identity_id` - (Required) The Resouce ID of an existing User Assigned Managed Identity. This can be changed without recreating the resource. -~> **Note:** The User Assigned Managed Identity must also be assigned to the parent Data Factory. Attempting to create a Credentials resource without - first doing this will result in an Azure API error. +~> **Note:** Attempting to create a credentials resource without first assigning the identity to the parent Data Factory will result in an Azure API error. * `annotations` - (Optional) List of tags that can be used for describing the Data Factory Dataset. From 795d187313545004b0b833aae7d479d8eb4decdd Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 15:18:01 -0600 Subject: [PATCH 11/25] convert to new resource format --- ...edential_user_assigned_managed_identity.go | 366 +++++++++++------- internal/services/datafactory/registration.go | 2 +- 2 files changed, 235 insertions(+), 133 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index bcc297a3c0d9..96ff85782924 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -1,179 +1,281 @@ package datafactory import ( + "context" "fmt" "time" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/utils" ) -func resourceDataFactoryCredentialsUserAssignedManagedIdentity() *pluginsdk.Resource { - return &pluginsdk.Resource{ - Create: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, - Read: resourceDataFactoryCredentialsUserAssignedManagedIdentityRead, - Update: resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate, - Delete: resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete, - - Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := credentials.ParseCredentialID(id) - return err - }), - - Timeouts: &pluginsdk.ResourceTimeout{ - Create: pluginsdk.DefaultTimeout(30 * time.Minute), - Read: pluginsdk.DefaultTimeout(5 * time.Minute), - Update: pluginsdk.DefaultTimeout(30 * time.Minute), - Delete: pluginsdk.DefaultTimeout(30 * time.Minute), - }, +var _ sdk.Resource = DataFactoryCredentialUserAssignedManagedIdentityResource{} +var _ sdk.ResourceWithUpdate = DataFactoryCredentialUserAssignedManagedIdentityResource{} - Schema: map[string]*pluginsdk.Schema{ - "annotations": { // annotations not visible in portal - Type: pluginsdk.TypeList, - Optional: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - }, - }, - "data_factory_id": { - Description: "Resource ID of the Data Factory", - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: credentials.ValidateFactoryID, - }, - "description": { - Description: "Text description of the credential", - Type: pluginsdk.TypeString, - Optional: true, - }, - "identity_id": { - Description: "Resource ID of a User-Assigned Managed Identity", - Type: pluginsdk.TypeString, - Required: true, - }, - "name": { - Description: "Credential Name", - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, +// user managed identities only have one type +const IDENTITY_TYPE = "ManagedIdentity" + +type DataFactoryCredentialUserAssignedManagedIdentityResource struct{} + +type DataFactoryCredentialUserAssignedManagedIdentityResourceSchema struct { + Name string `tfschema:"name"` + DataFactoryId string `tfschema:"data_factory_id"` + IdentityId string `tfschema:"identity_id"` + Description string `tfschema:"description"` + Annotations []string `tfschema:"annotations"` +} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) Arguments() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{ + "name": { + Description: "The desired name of the credential resource", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "data_factory_id": { + Description: "The resource ID of the parent Data Factory", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: factories.ValidateFactoryID, + }, + "identity_id": { + Description: "The resource ID of the User Assigned Managed Identity", + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: commonids.ValidateUserAssignedIdentityID, + }, + "description": { + Description: "(Optional) Short text description", + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + "annotations": { + Description: "(Optional) List of string annotations", + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, }, }, } } -// user managed identities only have one type -const IDENTITY_TYPE = "ManagedIdentity" +func (DataFactoryCredentialUserAssignedManagedIdentityResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) ModelObject() interface{} { + return &DataFactoryCredentialUserAssignedManagedIdentityResourceSchema{} +} -func resourceDataFactoryCredentialsUserAssignedManagedIdentityCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataFactory.Credentials - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() +func (DataFactoryCredentialUserAssignedManagedIdentityResource) ResourceType() string { + return "data_factory_credential_user_assigned_managed_identity" +} - dataFactoryId, err := credentials.ParseFactoryID(d.Get("data_factory_id").(string)) - if err != nil { - return err - } +func (DataFactoryCredentialUserAssignedManagedIdentityResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { + return credentials.ValidateCredentialID +} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) Read() sdk.ResourceFunc { + 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()) + if err != nil { + return err + } + + var state DataFactoryCredentialUserAssignedManagedIdentityResourceSchema + + existing, err := client.CredentialOperationsGet(ctx, *credentialId, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + if existing.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) + } + } - id := credentials.CredentialId{ - SubscriptionId: dataFactoryId.SubscriptionId, - ResourceGroupName: dataFactoryId.ResourceGroupName, - FactoryName: dataFactoryId.FactoryName, - CredentialName: d.Get("name").(string), + state.Name = credentialId.CredentialName + state.Description = *existing.Model.Properties.Description + state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId + state.DataFactoryId = factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID() + state.Annotations = flattenDataFactoryAnnotations(existing.Model.Properties.Annotations) + + return nil + }, } +} + +func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.DataFactory.Credentials + + var data DataFactoryCredentialUserAssignedManagedIdentityResourceSchema + if err := metadata.Decode(&data); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + dataFactoryId, err := credentials.ParseFactoryID(data.DataFactoryId) + if err != nil { + return err + } + + id := credentials.CredentialId{ + SubscriptionId: dataFactoryId.SubscriptionId, + ResourceGroupName: dataFactoryId.ResourceGroupName, + FactoryName: dataFactoryId.FactoryName, + CredentialName: data.Name, + } - if d.IsNewResource() { - existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) - if err != nil { + existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + if existing.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + } if existing.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID()) } - } - if existing.HttpResponse.Status == "404" { - return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID()) - } - } + credential := credentials.ManagedIdentityCredentialResource{ + Type: utils.String(IDENTITY_TYPE), + Properties: credentials.ManagedIdentityCredential{ + TypeProperties: &credentials.ManagedIdentityTypeProperties{}, + }, + } + + if len(data.Annotations) > 0 { + annotations := make([]interface{}, len(data.Annotations)) + for i, v := range data.Annotations { + annotations[i] = v + } + credential.Properties.Annotations = &annotations + } + + if data.Description != "" { + credential.Properties.Description = &data.Description + } + + if data.IdentityId != "" { + credential.Properties.TypeProperties.ResourceId = &data.IdentityId + } - credential := credentials.ManagedIdentityCredentialResource{ - Type: utils.String(IDENTITY_TYPE), - Properties: credentials.ManagedIdentityCredential{ - TypeProperties: &credentials.ManagedIdentityTypeProperties{}, + _, err = client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil }, } +} - if v, ok := d.GetOk("annotations"); ok { - annotations := v.([]interface{}) - credential.Properties.Annotations = &annotations - } +func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Update() sdk.ResourceFunc { + return sdk.ResourceFunc{ + Timeout: 5 * time.Minute, + Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { + client := metadata.Client.DataFactory.Credentials + id, err := credentials.ParseCredentialID(metadata.ResourceData.Id()) + if err != nil { + return err + } - if v, ok := d.GetOk("description"); ok { - description := v.(string) - credential.Properties.Description = &description - } + var data DataFactoryCredentialUserAssignedManagedIdentityResourceSchema + if err := metadata.Decode(&data); err != nil { + return fmt.Errorf("decoding: %+v", err) + } - if v, ok := d.GetOk("identity_id"); ok { - identityId := v.(string) - credential.Properties.TypeProperties.ResourceId = &identityId - } + existing, err := client.CredentialOperationsGet(ctx, *id, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + if existing.HttpResponse.Status == "404" { + return fmt.Errorf("checking for presence of existing %s: %+v", id.ID(), err) + } + } - resp, err := client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) - if err != nil { - return fmt.Errorf("creating %s: %+v", id, err) - } + credential := credentials.ManagedIdentityCredentialResource{ + Type: existing.Model.Type, + Name: existing.Model.Name, + Id: existing.Model.Id, + Properties: credentials.ManagedIdentityCredential{ + Annotations: existing.Model.Properties.Annotations, + Description: existing.Model.Properties.Description, + TypeProperties: &credentials.ManagedIdentityTypeProperties{ + ResourceId: existing.Model.Properties.TypeProperties.ResourceId, + }, + }, + } - d.SetId(*resp.Model.Id) + if metadata.ResourceData.HasChange("name") { + credential.Name = &data.Name + } - return resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d, meta) -} + if metadata.ResourceData.HasChange("identity_id") { + credential.Properties.TypeProperties.ResourceId = &data.IdentityId + } -func resourceDataFactoryCredentialsUserAssignedManagedIdentityRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataFactory.Credentials - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() + if metadata.ResourceData.HasChange("description") { + credential.Properties.Description = &data.Description + } - credentialId, err := credentials.ParseCredentialID(d.Id()) - if err != nil { - return err - } + if metadata.ResourceData.HasChange("annotations") { + if len(data.Annotations) > 0 { + annotations := make([]interface{}, len(data.Annotations)) + for i, v := range data.Annotations { + annotations[i] = v + } + credential.Properties.Annotations = &annotations + } else { + credential.Properties.Annotations = nil + } + } - existing, err := client.CredentialOperationsGet(ctx, *credentialId, credentials.CredentialOperationsGetOperationOptions{}) - if err != nil { - if existing.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) - } - } + _, err = client.CredentialOperationsCreateOrUpdate(ctx, *id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) + if err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } - d.Set("name", credentialId.CredentialName) - d.Set("description", existing.Model.Properties.Description) - if err := d.Set("annotations", flattenDataFactoryAnnotations(existing.Model.Properties.Annotations)); err != nil { - return fmt.Errorf("setting `annotations`: %+v", err) - } - d.Set("identity_id", existing.Model.Properties.TypeProperties.ResourceId) - d.Set("data_factory_id", factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID()) + metadata.SetID(id) - return nil + return nil + }, + } } -func resourceDataFactoryCredentialsUserAssignedManagedIdentityDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataFactory.Credentials - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() +func (DataFactoryCredentialUserAssignedManagedIdentityResource) Delete() sdk.ResourceFunc { + 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()) - if err != nil { - return err - } + credentialId, err := credentials.ParseCredentialID(d.Id()) + if err != nil { + return err + } - _, err = client.CredentialOperationsDelete(ctx, *credentialId) - if err != nil { - return err - } + _, err = client.CredentialOperationsDelete(ctx, *credentialId) + if err != nil { + return err + } - return nil + return nil + }, + } } diff --git a/internal/services/datafactory/registration.go b/internal/services/datafactory/registration.go index 200cd1db55e7..794ccb721fed 100644 --- a/internal/services/datafactory/registration.go +++ b/internal/services/datafactory/registration.go @@ -36,6 +36,7 @@ func (Registration) DataSources() []sdk.DataSource { func (Registration) Resources() []sdk.Resource { return []sdk.Resource{ DataFactoryDatasetAzureSQLTableResource{}, + DataFactoryCredentialUserAssignedManagedIdentityResource{}, } } @@ -64,7 +65,6 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_data_factory_dataset_snowflake": resourceDataFactoryDatasetSnowflake(), "azurerm_data_factory_dataset_sql_server_table": resourceDataFactoryDatasetSQLServerTable(), "azurerm_data_factory_custom_dataset": resourceDataFactoryCustomDataset(), - "azurerm_data_factory_credential_user_managed_identity": resourceDataFactoryCredentialsUserAssignedManagedIdentity(), "azurerm_data_factory_integration_runtime_managed": resourceDataFactoryIntegrationRuntimeManaged(), "azurerm_data_factory_integration_runtime_azure": resourceDataFactoryIntegrationRuntimeAzure(), "azurerm_data_factory_integration_runtime_azure_ssis": resourceDataFactoryIntegrationRuntimeAzureSsis(), From 9c87969679408ba04517a10a6e64b667962cc684 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 15:31:24 -0600 Subject: [PATCH 12/25] rename resource --- ...redential_user_assigned_managed_identity.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 96ff85782924..04e64b5ab2ef 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -15,13 +15,17 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/utils" ) -var _ sdk.Resource = DataFactoryCredentialUserAssignedManagedIdentityResource{} -var _ sdk.ResourceWithUpdate = DataFactoryCredentialUserAssignedManagedIdentityResource{} +type DataFactoryCredentialUserAssignedManagedIdentityResource struct{} // user managed identities only have one type const IDENTITY_TYPE = "ManagedIdentity" -type DataFactoryCredentialUserAssignedManagedIdentityResource struct{} +var _ sdk.Resource = DataFactoryCredentialUserAssignedManagedIdentityResource{} +var _ sdk.ResourceWithUpdate = DataFactoryCredentialUserAssignedManagedIdentityResource{} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) ResourceType() string { + return "azurerm_data_factory_credential_user_managed_identity" +} type DataFactoryCredentialUserAssignedManagedIdentityResourceSchema struct { Name string `tfschema:"name"` @@ -60,8 +64,8 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Arguments() map[ Optional: true, ValidateFunc: validation.StringIsNotEmpty, }, - "annotations": { - Description: "(Optional) List of string annotations", + "annotations": { // this property is not visible in the azure portal + Description: "(Optional) List of string annotations.", Type: pluginsdk.TypeList, Optional: true, Elem: &pluginsdk.Schema{ @@ -79,10 +83,6 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) ModelObject() in return &DataFactoryCredentialUserAssignedManagedIdentityResourceSchema{} } -func (DataFactoryCredentialUserAssignedManagedIdentityResource) ResourceType() string { - return "data_factory_credential_user_assigned_managed_identity" -} - func (DataFactoryCredentialUserAssignedManagedIdentityResource) IDValidationFunc() pluginsdk.SchemaValidateFunc { return credentials.ValidateCredentialID } From c83da54c7c81aa990d1dbbb36300bb7147ef75f7 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 15:52:15 -0600 Subject: [PATCH 13/25] update docs, fix resource import --- ...edential_user_assigned_managed_identity.go | 13 +++++++++--- ...er_assigned_managed_identity.html.markdown | 20 ++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go index 04e64b5ab2ef..bac985a0d01e 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go @@ -109,12 +109,19 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Read() sdk.Resou } state.Name = credentialId.CredentialName - state.Description = *existing.Model.Properties.Description - state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId + + if existing.Model.Properties.Description != nil { + state.Description = *existing.Model.Properties.Description + } + + if existing.Model.Properties.TypeProperties.ResourceId != nil { + state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId + } + state.DataFactoryId = factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID() state.Annotations = flattenDataFactoryAnnotations(existing.Model.Properties.Annotations) - return nil + return metadata.Encode(&state) }, } } diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown index 0d38f3d8c1d2..8a9bd35d18e8 100644 --- a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -47,17 +47,19 @@ resource "azurerm_data_factory_credential_user_managed_identity" "test" { ## Argument Reference -* `name` - (Required) Specifies the name of the credential. Changing this forces a new resource to be created. +* `name` - (Required) Specifies the name of the Credential. Changing this forces a new resource to be created. * `data_factory_id` - (Required) The Data Factory ID in which to associate the Credential with. Changing this forces a new resource. * `identity_id` - (Required) The Resouce ID of an existing User Assigned Managed Identity. This can be changed without recreating the resource. -~> **Note:** Attempting to create a credentials resource without first assigning the identity to the parent Data Factory will result in an Azure API error. +~> **Note:** Attempting to create a Credential resource without first assigning the identity to the parent Data Factory will result in an Azure API error. -* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Dataset. +* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Credential. -* `description` - (Optional) The description for the Data Factory Dataset. +~> **Note:** Manually altering a Credential resource will cause annotations to be lost, resulting in a change being detected on the next run. + +* `description` - (Optional) The description for the Data Factory Credential. --- @@ -65,16 +67,16 @@ resource "azurerm_data_factory_credential_user_managed_identity" "test" { In addition to the Arguments listed above - the following Attributes are exported: -* `id` - The ID of the Data Factory Dataset. +* `id` - The ID of the Data Factory Credential. ## Timeouts The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: -* `create` - (Defaults to 30 minutes) Used when creating the Data Factory Dataset. -* `update` - (Defaults to 30 minutes) Used when updating the Data Factory Dataset. -* `read` - (Defaults to 5 minutes) Used when retrieving the Data Factory Dataset. -* `delete` - (Defaults to 30 minutes) Used when deleting the Data Factory Dataset. +* `create` - (Defaults to 30 minutes) Used when creating the Data Factory Credential. +* `update` - (Defaults to 30 minutes) Used when updating the Data Factory Credential. +* `read` - (Defaults to 5 minutes) Used when retrieving the Data Factory Credential. +* `delete` - (Defaults to 30 minutes) Used when deleting the Data Factory Credential. ## Import From 948144895594ef6701766bf03db1e3681b950b1b Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 21 Dec 2023 16:09:03 -0600 Subject: [PATCH 14/25] add basic test --- ...ial_user_assigned_managed_identity_test.go | 78 +++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go new file mode 100644 index 000000000000..7878545c361e --- /dev/null +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go @@ -0,0 +1,78 @@ +package datafactory_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type CredentialUserAssignedManagedIdentityResource struct{} + +func TestAccDataFactoryCredentialUserAssignedManagedIdentity_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_azure_sql_table", "test") + r := CredentialUserAssignedManagedIdentityResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (t CredentialUserAssignedManagedIdentityResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := credentials.ParseCredentialID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.DataFactory.Credentials.CredentialOperationsGet(ctx, *id, credentials.DefaultCredentialOperationsGetOperationOptions()) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", *id, err) + } + + return utils.Bool(resp.Model.Id != nil), nil +} + +func (CredentialUserAssignedManagedIdentityResource) basic(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-df-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdf%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_user_assigned_identity" "test" { + location = azurerm_resource_group.test.location + name = "acctestdf%d" + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_data_factory_credential_user_managed_identity" "test" { + name = "credential%d" + description = "%s" + data_factory_id = azurerm_data_factory.test.id + identity_id = azurerm_user_assigned_identity.test.id + annotations = ["%s"] +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString) +} From 475e0d175d49d4ac362c8dc0fc6f2df1e605c57a Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Fri, 22 Dec 2023 10:43:26 -0600 Subject: [PATCH 15/25] fix acc tests --- ...ntial_user_assigned_managed_identity_test.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go index 7878545c361e..8956482df2ec 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go @@ -16,7 +16,7 @@ import ( type CredentialUserAssignedManagedIdentityResource struct{} func TestAccDataFactoryCredentialUserAssignedManagedIdentity_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_data_factory_dataset_azure_sql_table", "test") + data := acceptance.BuildTestData(t, "azurerm_data_factory_credential_user_managed_identity", "test") r := CredentialUserAssignedManagedIdentityResource{} data.ResourceTest(t, r, []acceptance.TestStep{ @@ -24,6 +24,8 @@ func TestAccDataFactoryCredentialUserAssignedManagedIdentity_basic(t *testing.T) Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("annotations.#").HasValue("1"), + check.That(data.ResourceName).Key("description").IsNotEmpty(), ), }, data.ImportStep(), @@ -55,16 +57,21 @@ resource "azurerm_resource_group" "test" { location = "%s" } -resource "azurerm_data_factory" "test" { - name = "acctestdf%d" +resource "azurerm_user_assigned_identity" "test" { location = azurerm_resource_group.test.location + name = "acctestdf%d" resource_group_name = azurerm_resource_group.test.name } -resource "azurerm_user_assigned_identity" "test" { - location = azurerm_resource_group.test.location +resource "azurerm_data_factory" "test" { name = "acctestdf%d" + location = azurerm_resource_group.test.location resource_group_name = azurerm_resource_group.test.name + + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.test.id] + } } resource "azurerm_data_factory_credential_user_managed_identity" "test" { From 2c9e86b3d60fc1e920ea27793ae00f8aea4fc003 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Fri, 22 Dec 2023 10:50:55 -0600 Subject: [PATCH 16/25] change default timeout in docs --- ..._credential_user_assigned_managed_identity.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown index 8a9bd35d18e8..ed3dfd9c373f 100644 --- a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -73,10 +73,10 @@ In addition to the Arguments listed above - the following Attributes are exporte The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions: -* `create` - (Defaults to 30 minutes) Used when creating the Data Factory Credential. -* `update` - (Defaults to 30 minutes) Used when updating the Data Factory Credential. +* `create` - (Defaults to 5 minutes) Used when creating the Data Factory Credential. +* `update` - (Defaults to 5 minutes) Used when updating the Data Factory Credential. * `read` - (Defaults to 5 minutes) Used when retrieving the Data Factory Credential. -* `delete` - (Defaults to 30 minutes) Used when deleting the Data Factory Credential. +* `delete` - (Defaults to 5 minutes) Used when deleting the Data Factory Credential. ## Import From 14de1579b4adc97d53ce1db62243fa23b12bd005 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 09:37:56 -0600 Subject: [PATCH 17/25] rename files --- ...factory_credential_user_assigned_managed_identity_resource.go} | 0 ...ry_credential_user_assigned_managed_identity_resource_test.go} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename internal/services/datafactory/{data_factory_credential_user_assigned_managed_identity.go => data_factory_credential_user_assigned_managed_identity_resource.go} (100%) rename internal/services/datafactory/{data_factory_credential_user_assigned_managed_identity_test.go => data_factory_credential_user_assigned_managed_identity_resource_test.go} (100%) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go similarity index 100% rename from internal/services/datafactory/data_factory_credential_user_assigned_managed_identity.go rename to internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go similarity index 100% rename from internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_test.go rename to internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go From 2de98d9795e6210695c72e5fc1ac15f5345dcdaf Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 09:45:10 -0600 Subject: [PATCH 18/25] dont update forcenew props --- ..._credential_user_assigned_managed_identity_resource.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go index bac985a0d01e..0107214856c9 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -229,14 +229,6 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Update() sdk.R }, } - if metadata.ResourceData.HasChange("name") { - credential.Name = &data.Name - } - - if metadata.ResourceData.HasChange("identity_id") { - credential.Properties.TypeProperties.ResourceId = &data.IdentityId - } - if metadata.ResourceData.HasChange("description") { credential.Properties.Description = &data.Description } From 15cec54f9417aaa65d71548b66f126b6114dd95b Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 09:46:35 -0600 Subject: [PATCH 19/25] use generic name in docs --- ...tory_credential_user_assigned_managed_identity.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown index ed3dfd9c373f..8f0e9b9ee112 100644 --- a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -19,7 +19,7 @@ resource "azurerm_resource_group" "example" { } resource "azurerm_data_factory" "example" { - name = "bruceharrison-12334" + name = "example" location = azurerm_resource_group.example.location resource_group_name = azurerm_resource_group.example.name From 6a1f29aa479d68b39f5494e478909355c19f165a Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 09:47:34 -0600 Subject: [PATCH 20/25] fix more docs issues --- ...ntial_user_assigned_managed_identity.html.markdown | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown index 8f0e9b9ee112..bdfb99c694a7 100644 --- a/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -83,14 +83,5 @@ The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/l Data Factory Credentials can be imported using the `resource id`, e.g. ```shell -terraform import azurerm_data_factory_credential_user_managed_identity.example /subscriptions/1f3d6e58-feed-4bb6-87e5-a52305ad3375/resourceGroups/example-resources/providers/Microsoft.DataFactory/factories/bruceharrison-12334/credentials/credential1 -``` - -HCL import blocks can also be used for import - -```hcl -import { - to = azurerm_data_factory_credential_user_managed_identity.test - id = "/subscriptions/1f3d6e58-feed-4bb6-87e5-a52305ad3375/resourceGroups/example-resources/providers/Microsoft.DataFactory/factories/bruceharrison-12334/credentials/credential1" -} +terraform import azurerm_data_factory_credential_user_managed_identity.example /subscriptions/1f3d6e58-feed-4bb6-87e5-a52305ad3375/resourceGroups/example-resources/providers/Microsoft.DataFactory/factories/example/credentials/credential1 ``` From ebe85605c80f010eb60cc5548b27de75b13d081e Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 09:56:16 -0600 Subject: [PATCH 21/25] add nil checks --- ...ential_user_assigned_managed_identity_resource.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go index 0107214856c9..1f3469b7c34d 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -110,12 +110,14 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Read() sdk.Resou state.Name = credentialId.CredentialName - if existing.Model.Properties.Description != nil { - state.Description = *existing.Model.Properties.Description - } + if existing.Model != nil { + if existing.Model.Properties.Description != nil { + state.Description = *existing.Model.Properties.Description + } - if existing.Model.Properties.TypeProperties.ResourceId != nil { - state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId + if existing.Model.Properties.TypeProperties != nil && existing.Model.Properties.TypeProperties.ResourceId != nil { + state.IdentityId = *existing.Model.Properties.TypeProperties.ResourceId + } } state.DataFactoryId = factories.NewFactoryID(credentialId.SubscriptionId, credentialId.ResourceGroupName, credentialId.FactoryName).ID() From e9d333b1e7beb7f0a503fe2e573ad5a17ea1c290 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 10:00:49 -0600 Subject: [PATCH 22/25] simplify update --- ...user_assigned_managed_identity_resource.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go index 1f3469b7c34d..c22ba79e867b 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -213,24 +213,15 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Update() sdk.R existing, err := client.CredentialOperationsGet(ctx, *id, credentials.CredentialOperationsGetOperationOptions{}) if err != nil { - if existing.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", id.ID(), err) - } + return fmt.Errorf("checking for presence of existing %s: %+v", id.ID(), err) } - credential := credentials.ManagedIdentityCredentialResource{ - Type: existing.Model.Type, - Name: existing.Model.Name, - Id: existing.Model.Id, - Properties: credentials.ManagedIdentityCredential{ - Annotations: existing.Model.Properties.Annotations, - Description: existing.Model.Properties.Description, - TypeProperties: &credentials.ManagedIdentityTypeProperties{ - ResourceId: existing.Model.Properties.TypeProperties.ResourceId, - }, - }, + if existing.Model == nil { + return fmt.Errorf("model was nil for %s", id) } + credential := *existing.Model + if metadata.ResourceData.HasChange("description") { credential.Properties.Description = &data.Description } From 2880d6ae1773739c68fc6e14a1a21d44f26a15d5 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 10:06:10 -0600 Subject: [PATCH 23/25] use existing method to check for 404s --- ...al_user_assigned_managed_identity_resource.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go index c22ba79e867b..cf94138412c6 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/credentials" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" @@ -102,10 +103,8 @@ func (DataFactoryCredentialUserAssignedManagedIdentityResource) Read() sdk.Resou var state DataFactoryCredentialUserAssignedManagedIdentityResourceSchema existing, err := client.CredentialOperationsGet(ctx, *credentialId, credentials.CredentialOperationsGetOperationOptions{}) - if err != nil { - if existing.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) - } + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) } state.Name = credentialId.CredentialName @@ -152,12 +151,11 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.R } existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) - if err != nil { - if existing.HttpResponse.Status == "404" { - return fmt.Errorf("checking for presence of existing %s: %+v", id, err) - } + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) } - if existing.HttpResponse.Status == "404" { + + if !response.WasNotFound(existing.HttpResponse) { return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID()) } From eafd70832ff956cb8cedf7d1e1db8398a30f74d0 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 10:15:10 -0600 Subject: [PATCH 24/25] instantiate with known value --- ..._credential_user_assigned_managed_identity_resource.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go index cf94138412c6..b3cf081f3460 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -162,7 +162,9 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.R credential := credentials.ManagedIdentityCredentialResource{ Type: utils.String(IDENTITY_TYPE), Properties: credentials.ManagedIdentityCredential{ - TypeProperties: &credentials.ManagedIdentityTypeProperties{}, + TypeProperties: &credentials.ManagedIdentityTypeProperties{ + ResourceId: &data.IdentityId, + }, }, } @@ -178,10 +180,6 @@ func (r DataFactoryCredentialUserAssignedManagedIdentityResource) Create() sdk.R credential.Properties.Description = &data.Description } - if data.IdentityId != "" { - credential.Properties.TypeProperties.ResourceId = &data.IdentityId - } - _, err = client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) if err != nil { return fmt.Errorf("creating %s: %+v", id, err) From 1826bc1314acc4a9fc47fe10d813e348a5084201 Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Wed, 3 Jan 2024 14:01:54 -0600 Subject: [PATCH 25/25] add test for resource update --- ...assigned_managed_identity_resource_test.go | 57 +++++++++++++++++-- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go index 8956482df2ec..352e0e5c0495 100644 --- a/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go @@ -25,13 +25,37 @@ func TestAccDataFactoryCredentialUserAssignedManagedIdentity_basic(t *testing.T) Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("annotations.#").HasValue("1"), - check.That(data.ResourceName).Key("description").IsNotEmpty(), + check.That(data.ResourceName).Key("description").HasValue("ORIGINAL DESCRIPTION"), ), }, data.ImportStep(), }) } +func TestAccDataFactoryCredentialUserAssignedManagedIdentity_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_factory_credential_user_managed_identity", "test") + r := CredentialUserAssignedManagedIdentityResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("annotations.#").HasValue("1"), + check.That(data.ResourceName).Key("description").HasValue("ORIGINAL DESCRIPTION"), + ), + }, + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("annotations.#").HasValue("2"), + check.That(data.ResourceName).Key("description").HasValue("UPDATED DESCRIPTION"), + ), + }, + }) +} + func (t CredentialUserAssignedManagedIdentityResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { id, err := credentials.ParseCredentialID(state.ID) if err != nil { @@ -46,7 +70,7 @@ func (t CredentialUserAssignedManagedIdentityResource) Exists(ctx context.Contex return utils.Bool(resp.Model.Id != nil), nil } -func (CredentialUserAssignedManagedIdentityResource) basic(data acceptance.TestData) string { +func templateBase(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -72,14 +96,37 @@ resource "azurerm_data_factory" "test" { type = "UserAssigned" identity_ids = [azurerm_user_assigned_identity.test.id] } +}`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func (r CredentialUserAssignedManagedIdentityResource) basic(data acceptance.TestData) string { + base := templateBase(data) + + return fmt.Sprintf(` +%s + +resource "azurerm_data_factory_credential_user_managed_identity" "test" { + name = "credential%d" + description = "ORIGINAL DESCRIPTION" + data_factory_id = azurerm_data_factory.test.id + identity_id = azurerm_user_assigned_identity.test.id + annotations = ["1"] } +`, base, data.RandomInteger) +} + +func (r CredentialUserAssignedManagedIdentityResource) update(data acceptance.TestData) string { + base := templateBase(data) + + return fmt.Sprintf(` +%s resource "azurerm_data_factory_credential_user_managed_identity" "test" { name = "credential%d" - description = "%s" + description = "UPDATED DESCRIPTION" data_factory_id = azurerm_data_factory.test.id identity_id = azurerm_user_assigned_identity.test.id - annotations = ["%s"] + annotations = ["1", "2"] } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger, data.RandomString, data.RandomString) +`, base, data.RandomInteger) }