From 7b42329dd513d4cef313eba90e4e0e4d878c136a Mon Sep 17 00:00:00 2001 From: Bruce Harrison Date: Thu, 4 Jan 2024 18:45:32 -0600 Subject: [PATCH] New Resource: `azurerm_data_factory_credential_user_managed_identity` (#24307) --- go.mod | 2 +- go.sum | 4 +- .../services/datafactory/client/client.go | 9 + ...user_assigned_managed_identity_resource.go | 269 ++++++++++++++++++ ...assigned_managed_identity_resource_test.go | 132 +++++++++ internal/services/datafactory/registration.go | 1 + .../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 +- ...er_assigned_managed_identity.html.markdown | 87 ++++++ 22 files changed, 1338 insertions(+), 4 deletions(-) create mode 100644 internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go create mode 100644 internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.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 create mode 100644 website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown diff --git a/go.mod b/go.mod index a860a56e3832..10fc30adc08f 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 1c651e54733b..26f687338bb9 100644 --- a/go.sum +++ b/go.sum @@ -113,8 +113,8 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg= github.com/hashicorp/go-azure-helpers v0.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= 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..809802bc9b37 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 @@ -34,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) @@ -67,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_resource.go b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go new file mode 100644 index 000000000000..b3cf081f3460 --- /dev/null +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource.go @@ -0,0 +1,269 @@ +package datafactory + +import ( + "context" + "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" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type DataFactoryCredentialUserAssignedManagedIdentityResource struct{} + +// user managed identities only have one type +const IDENTITY_TYPE = "ManagedIdentity" + +var _ sdk.Resource = DataFactoryCredentialUserAssignedManagedIdentityResource{} +var _ sdk.ResourceWithUpdate = DataFactoryCredentialUserAssignedManagedIdentityResource{} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) ResourceType() string { + return "azurerm_data_factory_credential_user_managed_identity" +} + +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": { // this property is not visible in the azure portal + Description: "(Optional) List of string annotations.", + Type: pluginsdk.TypeList, + Optional: true, + Elem: &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + }, + }, + } +} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) Attributes() map[string]*pluginsdk.Schema { + return map[string]*pluginsdk.Schema{} +} + +func (DataFactoryCredentialUserAssignedManagedIdentityResource) ModelObject() interface{} { + return &DataFactoryCredentialUserAssignedManagedIdentityResourceSchema{} +} + +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 && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", d.Id(), err) + } + + state.Name = credentialId.CredentialName + + if existing.Model != nil { + if existing.Model.Properties.Description != nil { + state.Description = *existing.Model.Properties.Description + } + + 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() + state.Annotations = flattenDataFactoryAnnotations(existing.Model.Properties.Annotations) + + return metadata.Encode(&state) + }, + } +} + +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, + } + + existing, err := client.CredentialOperationsGet(ctx, id, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil && !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for presence of existing %s: %+v", id, err) + } + + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_data_factory_dataset_http", id.ID()) + } + + credential := credentials.ManagedIdentityCredentialResource{ + Type: utils.String(IDENTITY_TYPE), + Properties: credentials.ManagedIdentityCredential{ + TypeProperties: &credentials.ManagedIdentityTypeProperties{ + ResourceId: &data.IdentityId, + }, + }, + } + + 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 + } + + _, err = client.CredentialOperationsCreateOrUpdate(ctx, id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) + if err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil + }, + } +} + +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 + } + + var data DataFactoryCredentialUserAssignedManagedIdentityResourceSchema + if err := metadata.Decode(&data); err != nil { + return fmt.Errorf("decoding: %+v", err) + } + + existing, err := client.CredentialOperationsGet(ctx, *id, credentials.CredentialOperationsGetOperationOptions{}) + if err != nil { + return fmt.Errorf("checking for presence of existing %s: %+v", id.ID(), err) + } + + if existing.Model == nil { + return fmt.Errorf("model was nil for %s", id) + } + + credential := *existing.Model + + if metadata.ResourceData.HasChange("description") { + credential.Properties.Description = &data.Description + } + + 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 + } + } + + _, err = client.CredentialOperationsCreateOrUpdate(ctx, *id, credential, credentials.CredentialOperationsCreateOrUpdateOperationOptions{}) + if err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + metadata.SetID(id) + + return nil + }, + } +} + +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 + } + + _, err = client.CredentialOperationsDelete(ctx, *credentialId) + if err != nil { + return err + } + + return nil + }, + } +} 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 new file mode 100644 index 000000000000..352e0e5c0495 --- /dev/null +++ b/internal/services/datafactory/data_factory_credential_user_assigned_managed_identity_resource_test.go @@ -0,0 +1,132 @@ +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_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"), + ), + }, + 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 { + 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 templateBase(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-df-%d" + location = "%s" +} + +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" "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] + } +}`, 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 = "UPDATED DESCRIPTION" + data_factory_id = azurerm_data_factory.test.id + identity_id = azurerm_user_assigned_identity.test.id + annotations = ["1", "2"] +} +`, base, data.RandomInteger) +} diff --git a/internal/services/datafactory/registration.go b/internal/services/datafactory/registration.go index f83da8a69c5a..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{}, } } 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 48102a58f33d..a03179d594e5 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 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..bdfb99c694a7 --- /dev/null +++ b/website/docs/r/data_factory_credential_user_assigned_managed_identity.html.markdown @@ -0,0 +1,87 @@ +--- +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 credential resource +--- + +# azurerm_data_factory_credential_user_managed_identity + +Manage a Data Factory User Assigned Managed Identity credential resource. These resources are used by Data Factory to access data sources. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "westus" +} + +resource "azurerm_data_factory" "example" { + name = "example" + 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:** 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 Credential. + +~> **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. + +--- + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `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 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 5 minutes) Used when deleting the Data Factory Credential. + +## 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/example/credentials/credential1 +```