diff --git a/go.mod b/go.mod index 068716f7e8b0..8fd2bb25b8a1 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/google/go-cmp v0.5.6 github.com/google/uuid v1.1.2 github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/hashicorp/go-azure-helpers v0.19.1 + github.com/hashicorp/go-azure-helpers v0.21.0 github.com/hashicorp/go-getter v1.5.4 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/go-plugin v1.4.2 // indirect diff --git a/go.sum b/go.sum index 1c8bfc809606..de65b2f9d433 100644 --- a/go.sum +++ b/go.sum @@ -252,8 +252,8 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-azure-helpers v0.12.0/go.mod h1:Zc3v4DNeX6PDdy7NljlYpnrdac1++qNW0I4U+ofGwpg= -github.com/hashicorp/go-azure-helpers v0.19.1 h1:wDVQGxpXXVdzgkkdG09Me1ZnIOQGGu+qntgPJVrA2GM= -github.com/hashicorp/go-azure-helpers v0.19.1/go.mod h1:lZo52hYeyEoo4qpUUruaEec13bFyu8ldjX2zTFzVzss= +github.com/hashicorp/go-azure-helpers v0.21.0 h1:wp8IIrpYBln+MaMqySsSVqpoe2te+19sI1xmSIsATxo= +github.com/hashicorp/go-azure-helpers v0.21.0/go.mod h1:Z2IvHhrwmpdDU5Mdld+vETChcenndWcY1bws4Hsn+Wk= 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= @@ -357,8 +357,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/manicminer/hamilton v0.35.0 h1:K72BHXLhlO+H/evI5iburLDfVe19bDaXO+hEIQEVkdg= -github.com/manicminer/hamilton v0.35.0/go.mod h1:IOYn2Dc9SUiZ7Ryw6c8Ay795vPPMnrCZe3MktS447dc= +github.com/manicminer/hamilton v0.37.0 h1:lQ+7Whyr4dG3SkfEmc4Rm2pM6KRbNa1e3O9RWVE+eD8= +github.com/manicminer/hamilton v0.37.0/go.mod h1:IOYn2Dc9SUiZ7Ryw6c8Ay795vPPMnrCZe3MktS447dc= github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= diff --git a/internal/clients/builder.go b/internal/clients/builder.go index d1194d8d5694..09289374342c 100644 --- a/internal/clients/builder.go +++ b/internal/clients/builder.go @@ -110,7 +110,7 @@ func Build(ctx context.Context, builder ClientBuilder) (*Client, error) { } // Key Vault Endpoints - keyVaultAuth := builder.AuthConfig.BearerAuthorizerCallback(ctx, sender, oauthConfig) + keyVaultAuth := builder.AuthConfig.ADALBearerAuthorizerCallback(ctx, sender, oauthConfig) // Batch Management Endpoints batchManagementAuth, err := builder.AuthConfig.GetADALToken(ctx, sender, oauthConfig, env.BatchManagementEndpoint) diff --git a/internal/services/analysisservices/analysis_services_server_resource.go b/internal/services/analysisservices/analysis_services_server_resource.go index 5bb6039c7180..aa9b8c845b10 100644 --- a/internal/services/analysisservices/analysis_services_server_resource.go +++ b/internal/services/analysisservices/analysis_services_server_resource.go @@ -8,7 +8,8 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" @@ -16,7 +17,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/analysisservices/sdk/2017-08-01/servers" "github.com/hashicorp/terraform-provider-azurerm/internal/services/analysisservices/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -128,7 +128,7 @@ func resourceAnalysisServicesServer() *pluginsdk.Resource { Computed: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -162,7 +162,7 @@ func resourceAnalysisServicesServerCreate(d *pluginsdk.ResourceData, meta interf Name: d.Get("sku").(string), }, Properties: serverProperties, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if err := client.CreateThenPoll(ctx, id, analysisServicesServer); err != nil { @@ -225,7 +225,7 @@ func resourceAnalysisServicesServerRead(d *pluginsdk.ResourceData, meta interfac } } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } @@ -278,7 +278,7 @@ func resourceAnalysisServicesServerUpdate(d *pluginsdk.ResourceData, meta interf Sku: &servers.ResourceSku{ Name: sku, }, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), Properties: serverProperties, } diff --git a/internal/services/appconfiguration/app_configuration_data_source.go b/internal/services/appconfiguration/app_configuration_data_source.go index a7538274c3ff..d4dc81ca707e 100644 --- a/internal/services/appconfiguration/app_configuration_data_source.go +++ b/internal/services/appconfiguration/app_configuration_data_source.go @@ -5,13 +5,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/sdk/2020-06-01/configurationstores" "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -141,7 +141,7 @@ func dataSourceAppConfiguration() *pluginsdk.Resource { }, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -186,7 +186,7 @@ func dataSourceAppConfigurationRead(d *pluginsdk.ResourceData, meta interface{}) d.Set("secondary_read_key", accessKeys.secondaryReadKey) d.Set("secondary_write_key", accessKeys.secondaryWriteKey) - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil diff --git a/internal/services/appconfiguration/app_configuration_resource.go b/internal/services/appconfiguration/app_configuration_resource.go index 61e5fd2c9de4..7600da55991a 100644 --- a/internal/services/appconfiguration/app_configuration_resource.go +++ b/internal/services/appconfiguration/app_configuration_resource.go @@ -7,7 +7,8 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -15,7 +16,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/sdk/2020-06-01/configurationstores" "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -169,7 +169,7 @@ func resourceAppConfiguration() *pluginsdk.Resource { }, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -200,7 +200,7 @@ func resourceAppConfigurationCreate(d *pluginsdk.ResourceData, meta interface{}) Sku: configurationstores.Sku{ Name: d.Get("sku").(string), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } identity, err := expandAppConfigurationIdentity(d.Get("identity").([]interface{})) @@ -232,7 +232,7 @@ func resourceAppConfigurationUpdate(d *pluginsdk.ResourceData, meta interface{}) Sku: &configurationstores.Sku{ Name: d.Get("sku").(string), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if d.HasChange("identity") { @@ -296,7 +296,7 @@ func resourceAppConfigurationRead(d *pluginsdk.ResourceData, meta interface{}) e return fmt.Errorf("setting `identity`: %+v", err) } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil diff --git a/internal/services/attestation/attestation_provider_data_source.go b/internal/services/attestation/attestation_provider_data_source.go index ed8d42e8e00d..120ecc51972c 100644 --- a/internal/services/attestation/attestation_provider_data_source.go +++ b/internal/services/attestation/attestation_provider_data_source.go @@ -5,13 +5,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/sdk/2020-10-01/attestationproviders" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -44,7 +44,7 @@ func dataSourceAttestationProvider() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -79,7 +79,7 @@ func dataSourceArmAttestationProviderRead(d *pluginsdk.ResourceData, meta interf d.Set("attestation_uri", props.AttestUri) d.Set("trust_model", props.TrustModel) } - return tags.FlattenAndSet(d, tagsHelper.Flatten(resp.Model.Tags)) + return tags.FlattenAndSet(d, resp.Model.Tags) } return nil diff --git a/internal/services/attestation/attestation_provider_resource.go b/internal/services/attestation/attestation_provider_resource.go index 8f5fdc0d4447..9eb28868f703 100644 --- a/internal/services/attestation/attestation_provider_resource.go +++ b/internal/services/attestation/attestation_provider_resource.go @@ -8,7 +8,8 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -16,7 +17,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/sdk/2020-10-01/attestationproviders" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -59,7 +59,7 @@ func resourceAttestationProvider() *pluginsdk.Resource { ValidateFunc: validate.IsCert, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), "attestation_uri": { Type: pluginsdk.TypeString, @@ -99,7 +99,7 @@ func resourceAttestationProviderCreate(d *pluginsdk.ResourceData, meta interface Properties: attestationproviders.AttestationServiceCreationSpecificParams{ // AttestationPolicy was deprecated in October of 2019 }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } // NOTE: This maybe an slice in a future release or even a slice of slices @@ -155,7 +155,7 @@ func resourceAttestationProviderRead(d *pluginsdk.ResourceData, meta interface{} d.Set("attestation_uri", props.AttestUri) d.Set("trust_model", props.TrustModel) } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil @@ -173,7 +173,7 @@ func resourceAttestationProviderUpdate(d *pluginsdk.ResourceData, meta interface updateParams := attestationproviders.AttestationServicePatchParams{} if d.HasChange("tags") { - updateParams.Tags = tagsHelper.Expand(d.Get("tags").(map[string]interface{})) + updateParams.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } if _, err := client.Update(ctx, *id, updateParams); err != nil { diff --git a/internal/services/databricks/databricks_workspace_data_source.go b/internal/services/databricks/databricks_workspace_data_source.go index 5d3b813ae942..9a1eb2089c2f 100644 --- a/internal/services/databricks/databricks_workspace_data_source.go +++ b/internal/services/databricks/databricks_workspace_data_source.go @@ -5,11 +5,10 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/databricks/sdk/2021-04-01-preview/workspaces" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -28,7 +27,7 @@ func dataSourceDatabricksWorkspace() *pluginsdk.Resource { Required: true, }, - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), "sku": { Type: pluginsdk.TypeString, @@ -45,7 +44,7 @@ func dataSourceDatabricksWorkspace() *pluginsdk.Resource { Computed: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -76,7 +75,7 @@ func dataSourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface d.Set("workspace_id", model.Properties.WorkspaceId) d.Set("workspace_url", model.Properties.WorkspaceUrl) - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil } diff --git a/internal/services/databricks/databricks_workspace_resource.go b/internal/services/databricks/databricks_workspace_resource.go index 369a2b30210b..3e653073b6b7 100644 --- a/internal/services/databricks/databricks_workspace_resource.go +++ b/internal/services/databricks/databricks_workspace_resource.go @@ -8,7 +8,9 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -21,7 +23,6 @@ import ( loadBalancerParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/parse" resourcesParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/resource/parse" storageValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -55,9 +56,9 @@ func resourceDatabricksWorkspace() *pluginsdk.Resource { ValidateFunc: validate.WorkspaceName, }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "sku": { Type: pluginsdk.TypeString, @@ -267,7 +268,7 @@ func resourceDatabricksWorkspace() *pluginsdk.Resource { }, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error { @@ -336,9 +337,9 @@ func resourceDatabricksWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta int var backendPoolName, loadBalancerId string skuName := d.Get("sku").(string) managedResourceGroupName := d.Get("managed_resource_group_name").(string) - location := azure.NormalizeLocation(d.Get("location").(string)) + location := location.Normalize(d.Get("location").(string)) backendPool := d.Get("load_balancer_backend_address_pool_id").(string) - expandedTags := tagsHelper.Expand(d.Get("tags").(map[string]interface{})) + expandedTags := tags.Expand(d.Get("tags").(map[string]interface{})) if backendPool != "" { backendPoolId, err := loadBalancerParse.LoadBalancerBackendAddressPoolID(backendPool) @@ -447,7 +448,7 @@ func resourceDatabricksWorkspaceCreateUpdate(d *pluginsdk.ResourceData, meta int ManagedResourceGroupId: managedResourceGroupID, Parameters: customParams, }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if requireNsgRules != "" { @@ -601,7 +602,7 @@ func resourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface{} d.Set("managed_services_cmk_key_vault_key_id", key.ID()) } } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil diff --git a/internal/services/datalake/data_lake_analytics_account_resource.go b/internal/services/datalake/data_lake_analytics_account_resource.go index c845907bfc14..53744687ed0b 100644 --- a/internal/services/datalake/data_lake_analytics_account_resource.go +++ b/internal/services/datalake/data_lake_analytics_account_resource.go @@ -6,14 +6,15 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakeanalytics/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -47,9 +48,9 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource { ValidateFunc: validate.AccountName(), }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "tier": { Type: pluginsdk.TypeString, @@ -76,7 +77,7 @@ func resourceDataLakeAnalyticsAccount() *pluginsdk.Resource { ValidateFunc: validate.AccountName(), }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -109,7 +110,7 @@ func resourceArmDateLakeAnalyticsAccountCreate(d *pluginsdk.ResourceData, meta i dateLakeAnalyticsAccount := accounts.CreateDataLakeAnalyticsAccountParameters{ Location: location, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), Properties: accounts.CreateDataLakeAnalyticsAccountProperties{ NewTier: &tier, DefaultDataLakeStoreAccount: storeAccountName, @@ -145,7 +146,7 @@ func resourceArmDateLakeAnalyticsAccountUpdate(d *pluginsdk.ResourceData, meta i newTags := d.Get("tags").(map[string]interface{}) props := accounts.UpdateDataLakeAnalyticsAccountParameters{ - Tags: tagsHelper.Expand(newTags), + Tags: tags.Expand(newTags), Properties: &accounts.UpdateDataLakeAnalyticsAccountProperties{ NewTier: &newTier, DataLakeStoreAccounts: &[]accounts.UpdateDataLakeStoreWithAccountParameters{ @@ -187,9 +188,7 @@ func resourceArmDateLakeAnalyticsAccountRead(d *pluginsdk.ResourceData, meta int d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { - if location := model.Location; location != nil { - d.Set("location", azure.NormalizeLocation(*location)) - } + d.Set("location", location.NormalizeNilable(model.Location)) if properties := model.Properties; properties != nil { tier := "" @@ -200,7 +199,7 @@ func resourceArmDateLakeAnalyticsAccountRead(d *pluginsdk.ResourceData, meta int d.Set("default_store_account_name", properties.DefaultDataLakeStoreAccount) } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil } diff --git a/internal/services/datalake/data_lake_store_data_source.go b/internal/services/datalake/data_lake_store_data_source.go index 611483ac40be..ee6941c978f4 100644 --- a/internal/services/datalake/data_lake_store_data_source.go +++ b/internal/services/datalake/data_lake_store_data_source.go @@ -5,11 +5,11 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -28,9 +28,9 @@ func dataSourceDataLakeStoreAccount() *pluginsdk.Resource { Required: true, }, - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), - "location": azure.SchemaLocationForDataSource(), + "location": commonschema.LocationComputed(), "tier": { Type: pluginsdk.TypeString, @@ -57,7 +57,7 @@ func dataSourceDataLakeStoreAccount() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -118,7 +118,8 @@ func dataSourceArmDateLakeStoreAccountRead(d *pluginsdk.ResourceData, meta inter } } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } + return nil } diff --git a/internal/services/datalake/data_lake_store_resource.go b/internal/services/datalake/data_lake_store_resource.go index 34289735fb9c..6fddc436eefb 100644 --- a/internal/services/datalake/data_lake_store_resource.go +++ b/internal/services/datalake/data_lake_store_resource.go @@ -9,14 +9,13 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/sdk/datalakestore/2016-11-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datalake/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -50,9 +49,9 @@ func resourceDataLakeStore() *pluginsdk.Resource { ValidateFunc: validate.AccountName(), }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "tier": { Type: pluginsdk.TypeString, @@ -122,7 +121,7 @@ func resourceDataLakeStore() *pluginsdk.Resource { "identity": commonschema.SystemAssignedIdentity(), - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -172,7 +171,7 @@ func resourceArmDateLakeStoreCreate(d *pluginsdk.ResourceData, meta interface{}) dateLakeStore := accounts.CreateDataLakeStoreAccountParameters{ Location: location, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), Identity: identity, Properties: &accounts.CreateDataLakeStoreAccountProperties{ NewTier: &tier, @@ -215,7 +214,7 @@ func resourceArmDateLakeStoreUpdate(d *pluginsdk.ResourceData, meta interface{}) FirewallState: &firewallState, FirewallAllowAzureIps: &firewallAllowAzureIPs, }, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), } if err := client.UpdateThenPoll(ctx, *id, props); err != nil { @@ -290,7 +289,7 @@ func resourceArmDateLakeStoreRead(d *pluginsdk.ResourceData, meta interface{}) e d.Set("endpoint", properties.Endpoint) } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil } diff --git a/internal/services/eventhub/eventhub_cluster_resource.go b/internal/services/eventhub/eventhub_cluster_resource.go index 8eea24d16cfd..bb1d61d55e41 100644 --- a/internal/services/eventhub/eventhub_cluster_resource.go +++ b/internal/services/eventhub/eventhub_cluster_resource.go @@ -8,13 +8,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/eventhubsclusters" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -51,9 +51,9 @@ func resourceEventHubCluster() *pluginsdk.Resource { ), }, - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), - "location": azure.SchemaLocation(), + "location": commonschema.Location(), "sku_name": { Type: pluginsdk.TypeString, @@ -65,7 +65,7 @@ func resourceEventHubCluster() *pluginsdk.Resource { ), }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -93,7 +93,7 @@ func resourceEventHubClusterCreateUpdate(d *pluginsdk.ResourceData, meta interfa cluster := eventhubsclusters.Cluster{ Location: utils.String(azure.NormalizeLocation(d.Get("location").(string))), - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), Sku: expandEventHubClusterSkuName(d.Get("sku_name").(string)), } @@ -133,7 +133,7 @@ func resourceEventHubClusterRead(d *pluginsdk.ResourceData, meta interface{}) er d.Set("sku_name", flattenEventHubClusterSkuName(model.Sku)) d.Set("location", location.NormalizeNilable(model.Location)) - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil diff --git a/internal/services/eventhub/eventhub_namespace_data_source.go b/internal/services/eventhub/eventhub_namespace_data_source.go index 501f01421b0d..d9091c394848 100644 --- a/internal/services/eventhub/eventhub_namespace_data_source.go +++ b/internal/services/eventhub/eventhub_namespace_data_source.go @@ -6,13 +6,12 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2017-04-01/authorizationrulesnamespaces" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -31,9 +30,9 @@ func EventHubNamespaceDataSource() *pluginsdk.Resource { Required: true, }, - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), - "location": azure.SchemaLocationForDataSource(), + "location": commonschema.LocationComputed(), "default_primary_connection_string_alias": { Type: pluginsdk.TypeString, @@ -106,7 +105,7 @@ func EventHubNamespaceDataSource() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -148,8 +147,8 @@ func EventHubNamespaceDataSourceRead(d *pluginsdk.ResourceData, meta interface{} d.Set("dedicated_cluster_id", props.ClusterArmId) } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { - return fmt.Errorf("setting `tags`: %+v", err) + if err := tags.FlattenAndSet(d, model.Tags); err != nil { + return err } } diff --git a/internal/services/eventhub/eventhub_namespace_resource.go b/internal/services/eventhub/eventhub_namespace_resource.go index 9214739d522b..b834bafce89f 100644 --- a/internal/services/eventhub/eventhub_namespace_resource.go +++ b/internal/services/eventhub/eventhub_namespace_resource.go @@ -9,7 +9,8 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" @@ -20,7 +21,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2018-01-01-preview/networkrulesets" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/sdk/2021-01-01-preview/namespaces" "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -64,9 +64,9 @@ func resourceEventHubNamespace() *pluginsdk.Resource { ValidateFunc: validate.ValidateEventHubNamespaceName(), }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "sku": { Type: pluginsdk.TypeString, @@ -226,7 +226,7 @@ func resourceEventHubNamespace() *pluginsdk.Resource { Sensitive: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, CustomizeDiff: pluginsdk.CustomizeDiffShim(func(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error { oldSku, newSku := d.GetChange("sku") @@ -295,7 +295,7 @@ func resourceEventHubNamespaceCreateUpdate(d *pluginsdk.ResourceData, meta inter IsAutoInflateEnabled: utils.Bool(autoInflateEnabled), ZoneRedundant: utils.Bool(zoneRedundant), }, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), } if v := d.Get("dedicated_cluster_id").(string); v != "" { @@ -391,8 +391,8 @@ func resourceEventHubNamespaceRead(d *pluginsdk.ResourceData, meta interface{}) d.Set("dedicated_cluster_id", props.ClusterArmId) } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { - return fmt.Errorf("setting `tags`: %+v", err) + if err := tags.FlattenAndSet(d, model.Tags); err != nil { + return err } } diff --git a/internal/services/frontdoor/frontdoor_firewall_policy_resource.go b/internal/services/frontdoor/frontdoor_firewall_policy_resource.go index 68241f777805..d58756b68c1e 100644 --- a/internal/services/frontdoor/frontdoor_firewall_policy_resource.go +++ b/internal/services/frontdoor/frontdoor_firewall_policy_resource.go @@ -6,16 +6,15 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/sdk/2020-04-01/webapplicationfirewallpolicies" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -54,9 +53,9 @@ func resourceFrontDoorFirewallPolicy() *pluginsdk.Resource { ValidateFunc: validate.FrontDoorWAFName, }, - "location": location.SchemaComputed(), + "location": commonschema.LocationComputed(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "enabled": { Type: pluginsdk.TypeBool, @@ -427,7 +426,7 @@ func resourceFrontDoorFirewallPolicy() *pluginsdk.Resource { }, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -481,7 +480,7 @@ func resourceFrontDoorFirewallPolicyCreateUpdate(d *pluginsdk.ResourceData, meta CustomRules: expandFrontDoorFirewallCustomRules(customRules), ManagedRules: expandFrontDoorFirewallManagedRules(managedRules), }, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), } if redirectUrl != "" { @@ -555,7 +554,7 @@ func resourceFrontDoorFirewallPolicyRead(d *pluginsdk.ResourceData, meta interfa } } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil } diff --git a/internal/services/frontdoor/frontdoor_resource.go b/internal/services/frontdoor/frontdoor_resource.go index db96642ba3a2..5dd440282f9d 100644 --- a/internal/services/frontdoor/frontdoor_resource.go +++ b/internal/services/frontdoor/frontdoor_resource.go @@ -8,7 +8,8 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" @@ -17,7 +18,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/sdk/2020-05-01/frontdoors" azValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/frontdoor/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -101,7 +101,7 @@ func resourceFrontDoor() *pluginsdk.Resource { Deprecated: "Due to the service's API changing 'location' must now always be set to 'Global' for new resources, however if the Front Door service was created prior 2020/03/10 it may continue to exist in a specific current location", }, - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.Location(), "routing_rule": { Type: pluginsdk.TypeList, @@ -543,7 +543,7 @@ func resourceFrontDoor() *pluginsdk.Resource { }, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, CustomizeDiff: pluginsdk.CustomizeDiffShim(frontDoorCustomizeDiff), @@ -618,7 +618,7 @@ func resourceFrontDoorCreate(d *pluginsdk.ResourceData, meta interface{}) error LoadBalancingSettings: expandFrontDoorLoadBalancingSettingsModel(loadBalancingSettings, id), EnabledState: &enabledState, }, - Tags: tagsHelper.Expand(t), + Tags: tags.Expand(t), } if err := client.CreateOrUpdateThenPoll(ctx, id, frontDoorParameters); err != nil { @@ -711,7 +711,7 @@ func resourceFrontDoorUpdate(d *pluginsdk.ResourceData, meta interface{}) error } if d.HasChanges("tags") { - existingModel.Tags = tagsHelper.Expand(d.Get("tags").(map[string]interface{})) + existingModel.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } // If the explicitResourceOrder is empty and it's not a new resource set the mapping table to the state file and return an error. @@ -905,7 +905,7 @@ func resourceFrontDoorRead(d *pluginsdk.ResourceData, meta interface{}) error { } } - return tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)) + return tags.FlattenAndSet(d, model.Tags) } return nil diff --git a/internal/services/maps/maps_creator_resource.go b/internal/services/maps/maps_creator_resource.go index 6e9a3432eca5..bc266ca5fac8 100644 --- a/internal/services/maps/maps_creator_resource.go +++ b/internal/services/maps/maps_creator_resource.go @@ -5,14 +5,14 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/maps/sdk/2021-02-01/accounts" "github.com/hashicorp/terraform-provider-azurerm/internal/services/maps/sdk/2021-02-01/creators" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -51,7 +51,7 @@ func resourceMapsCreator() *pluginsdk.Resource { ValidateFunc: accounts.ValidateAccountID, }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), "storage_units": { Type: pluginsdk.TypeInt, @@ -59,7 +59,7 @@ func resourceMapsCreator() *pluginsdk.Resource { ValidateFunc: validation.IntBetween(1, 100), }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -95,7 +95,7 @@ func resourceMapsCreatorCreateUpdate(d *pluginsdk.ResourceData, meta interface{} Properties: creators.CreatorProperties{ StorageUnits: int64(d.Get("storage_units").(int)), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if _, err := client.CreateOrUpdate(ctx, id, props); err != nil { return fmt.Errorf("creating/updating %s: %+v", id, err) @@ -131,7 +131,7 @@ func resourceMapsCreatorRead(d *pluginsdk.ResourceData, meta interface{}) error d.Set("location", location.Normalize(model.Location)) props := model.Properties d.Set("storage_units", props.StorageUnits) - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } @@ -153,7 +153,7 @@ func resourceMapsCreatorUpdate(d *pluginsdk.ResourceData, meta interface{}) erro Properties: &creators.CreatorProperties{ StorageUnits: int64(d.Get("storage_units").(int)), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if _, err := client.Update(ctx, *id, props); err != nil { diff --git a/internal/services/powerbi/powerbi_embedded_resource.go b/internal/services/powerbi/powerbi_embedded_resource.go index 484489a11ab7..031fb9427587 100644 --- a/internal/services/powerbi/powerbi_embedded_resource.go +++ b/internal/services/powerbi/powerbi_embedded_resource.go @@ -6,14 +6,14 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/powerbi/sdk/2021-01-01/capacities" "github.com/hashicorp/terraform-provider-azurerm/internal/services/powerbi/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -47,9 +47,9 @@ func resourcePowerBIEmbedded() *pluginsdk.Resource { ValidateFunc: validate.EmbeddedName, }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "sku_name": { Type: pluginsdk.TypeString, @@ -84,7 +84,7 @@ func resourcePowerBIEmbedded() *pluginsdk.Resource { }, false), }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -120,7 +120,7 @@ func resourcePowerBIEmbeddedCreate(d *pluginsdk.ResourceData, meta interface{}) Sku: capacities.CapacitySku{ Name: d.Get("sku_name").(string), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if err := client.CreateThenPoll(ctx, id, parameters); err != nil { @@ -175,7 +175,7 @@ func resourcePowerBIEmbeddedRead(d *pluginsdk.ResourceData, meta interface{}) er d.Set("sku_name", model.Sku.Name) - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } @@ -214,7 +214,7 @@ func resourcePowerBIEmbeddedUpdate(d *pluginsdk.ResourceData, meta interface{}) } if d.HasChange("tags") { - parameters.Tags = tagsHelper.Expand(d.Get("tags").(map[string]interface{})) + parameters.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } if err := client.UpdateThenPoll(ctx, *id, parameters); err != nil { diff --git a/internal/services/relay/relay_namespace_resource.go b/internal/services/relay/relay_namespace_resource.go index 6ee00f5aadf9..1e3d0fb29af6 100644 --- a/internal/services/relay/relay_namespace_resource.go +++ b/internal/services/relay/relay_namespace_resource.go @@ -7,13 +7,13 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/relay/sdk/2017-04-01/namespaces" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -45,9 +45,9 @@ func resourceRelayNamespace() *pluginsdk.Resource { ValidateFunc: validation.StringLenBetween(6, 50), }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "sku_name": { Type: pluginsdk.TypeString, @@ -86,7 +86,7 @@ func resourceRelayNamespace() *pluginsdk.Resource { Sensitive: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -121,7 +121,7 @@ func resourceRelayNamespaceCreateUpdate(d *pluginsdk.ResourceData, meta interfac Tier: &skuTier, }, Properties: &namespaces.RelayNamespaceProperties{}, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if err := client.CreateOrUpdateThenPoll(ctx, id, parameters); err != nil { @@ -172,7 +172,7 @@ func resourceRelayNamespaceRead(d *pluginsdk.ResourceData, meta interface{}) err d.Set("metric_id", props.MetricId) } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } diff --git a/internal/services/signalr/signalr_service_data_source.go b/internal/services/signalr/signalr_service_data_source.go index 1d067681a2cb..29fd21c7a4f6 100644 --- a/internal/services/signalr/signalr_service_data_source.go +++ b/internal/services/signalr/signalr_service_data_source.go @@ -5,12 +5,11 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr/sdk/2020-05-01/signalr" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -29,7 +28,7 @@ func dataSourceArmSignalRService() *pluginsdk.Resource { Required: true, }, - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), "hostname": { Type: pluginsdk.TypeString, @@ -80,7 +79,7 @@ func dataSourceArmSignalRService() *pluginsdk.Resource { Sensitive: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -120,7 +119,7 @@ func dataSourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{} d.Set("server_port", props.ServerPort) } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } diff --git a/internal/services/signalr/signalr_service_resource.go b/internal/services/signalr/signalr_service_resource.go index a9fb4cd4db84..4d93e9bf7743 100644 --- a/internal/services/signalr/signalr_service_resource.go +++ b/internal/services/signalr/signalr_service_resource.go @@ -8,15 +8,15 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr/sdk/2020-05-01/signalr" signalrValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/signalr/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -55,9 +55,9 @@ func resourceArmSignalRService() *pluginsdk.Resource { ValidateFunc: validation.NoZeroValues, }, - "location": azure.SchemaLocation(), + "location": commonschema.Location(), - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "sku": { Type: pluginsdk.TypeList, @@ -256,7 +256,7 @@ func resourceArmSignalRService() *pluginsdk.Resource { Sensitive: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -318,7 +318,7 @@ func resourceArmSignalRServiceCreate(d *pluginsdk.ResourceData, meta interface{} Upstream: expandUpstreamSettings(upstreamSettings), }, Sku: expandSignalRServiceSku(sku), - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if err := client.CreateOrUpdateThenPoll(ctx, id, resourceType); err != nil { @@ -406,7 +406,7 @@ func resourceArmSignalRServiceRead(d *pluginsdk.ResourceData, meta interface{}) return fmt.Errorf("setting `upstream_endpoint`: %+v", err) } - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } @@ -484,7 +484,7 @@ func resourceArmSignalRServiceUpdate(d *pluginsdk.ResourceData, meta interface{} if d.HasChange("tags") { tagsRaw := d.Get("tags").(map[string]interface{}) - resourceType.Tags = tagsHelper.Expand(tagsRaw) + resourceType.Tags = tags.Expand(tagsRaw) } if err := client.UpdateThenPoll(ctx, *id, resourceType); err != nil { diff --git a/internal/services/vmware/vmware_private_cloud_data_source.go b/internal/services/vmware/vmware_private_cloud_data_source.go index ce8d526dea34..973da5fefc59 100644 --- a/internal/services/vmware/vmware_private_cloud_data_source.go +++ b/internal/services/vmware/vmware_private_cloud_data_source.go @@ -5,12 +5,11 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) @@ -29,9 +28,9 @@ func dataSourceVmwarePrivateCloud() *pluginsdk.Resource { Required: true, }, - "resource_group_name": azure.SchemaResourceGroupNameForDataSource(), + "resource_group_name": commonschema.ResourceGroupNameForDataSource(), - "location": azure.SchemaLocationForDataSource(), + "location": commonschema.LocationComputed(), "sku_name": { Type: pluginsdk.TypeString, @@ -142,7 +141,7 @@ func dataSourceVmwarePrivateCloud() *pluginsdk.Resource { Computed: true, }, - "tags": tags.SchemaDataSource(), + "tags": commonschema.TagsDataSource(), }, } } @@ -198,7 +197,7 @@ func dataSourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{ d.Set("sku_name", model.Sku.Name) - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } diff --git a/internal/services/vmware/vmware_private_cloud_resource.go b/internal/services/vmware/vmware_private_cloud_resource.go index c01ba06a8dd3..0a64fe96ecb5 100644 --- a/internal/services/vmware/vmware_private_cloud_resource.go +++ b/internal/services/vmware/vmware_private_cloud_resource.go @@ -6,13 +6,12 @@ import ( "time" "github.com/hashicorp/go-azure-helpers/lang/response" - tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" + "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" "github.com/hashicorp/terraform-provider-azurerm/internal/services/vmware/sdk/2020-03-20/privateclouds" - "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -46,9 +45,9 @@ func resourceVmwarePrivateCloud() *pluginsdk.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), - "location": azure.SchemaLocation(), + "location": commonschema.Location(), "sku_name": { Type: pluginsdk.TypeString, @@ -186,7 +185,7 @@ func resourceVmwarePrivateCloud() *pluginsdk.Resource { Computed: true, }, - "tags": tags.Schema(), + "tags": commonschema.Tags(), }, } } @@ -227,7 +226,7 @@ func resourceVmwarePrivateCloudCreate(d *pluginsdk.ResourceData, meta interface{ NsxtPassword: utils.String(d.Get("nsxt_password").(string)), VcenterPassword: utils.String(d.Get("vcenter_password").(string)), }, - Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } if err := client.CreateOrUpdateThenPoll(ctx, id, privateCloud); err != nil { @@ -290,7 +289,7 @@ func resourceVmwarePrivateCloudRead(d *pluginsdk.ResourceData, meta interface{}) d.Set("sku_name", model.Sku.Name) - if err := tags.FlattenAndSet(d, tagsHelper.Flatten(model.Tags)); err != nil { + if err := tags.FlattenAndSet(d, model.Tags); err != nil { return err } } @@ -331,7 +330,7 @@ func resourceVmwarePrivateCloudUpdate(d *pluginsdk.ResourceData, meta interface{ } if d.HasChange("tags") { - privateCloudUpdate.Tags = tagsHelper.Expand(d.Get("tags").(map[string]interface{})) + privateCloudUpdate.Tags = tags.Expand(d.Get("tags").(map[string]interface{})) } if err := client.UpdateThenPoll(ctx, *id, privateCloudUpdate); err != nil { diff --git a/vendor/github.com/hashicorp/go-azure-helpers/authentication/azure_sp_objectid.go b/vendor/github.com/hashicorp/go-azure-helpers/authentication/azure_sp_objectid.go index aa230abaa9f2..1376a79b64da 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/authentication/azure_sp_objectid.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/authentication/azure_sp_objectid.go @@ -8,6 +8,7 @@ import ( "net/http/httputil" "github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac" + "github.com/Azure/go-autorest/autorest" "github.com/manicminer/hamilton/auth" "github.com/manicminer/hamilton/environments" "github.com/manicminer/hamilton/msgraph" @@ -19,13 +20,94 @@ import ( func buildServicePrincipalObjectIDFunc(c *Config) func(ctx context.Context) (*string, error) { return func(ctx context.Context) (*string, error) { if c.UseMicrosoftGraph { - return objectIdFromMsGraph(ctx, c) + objectId, err := objectIdFromMSALTokenClaims(ctx, c) + if err != nil { + log.Printf("could not parse objectId from claims, retrying via Microsoft Graph: %v", err) + return objectIdFromMsGraph(ctx, c) + } + + return objectId, err } else { - return objectIdFromAadGraph(ctx, c) + objectId, err := objectIdFromADALTokenClaims(ctx, c) + if err != nil { + log.Printf("could not parse objectId from claims, retrying via Azure Active Directory Graph: %v", err) + return objectIdFromAadGraph(ctx, c) + } + + return objectId, err } } } +func claimsFromAutorestAuthorizer(authorizer autorest.Authorizer) (*auth.Claims, error) { + wrapper, err := auth.NewAutorestAuthorizerWrapper(authorizer) + if err != nil { + return nil, fmt.Errorf("wrapping autorest.Authorizer: %v", err) + } + + token, err := wrapper.Token() + if err != nil { + return nil, fmt.Errorf("acquiring access token: %v", err) + } + + claims, err := auth.ParseClaims(token) + if err != nil { + return nil, fmt.Errorf("parsing claims from access token: %v", err) + } + + return &claims, nil +} + +func objectIdFromADALTokenClaims(ctx context.Context, c *Config) (*string, error) { + env, err := AzureEnvironmentByNameFromEndpoint(ctx, c.MetadataHost, c.Environment) + if err != nil { + return nil, fmt.Errorf("determining environment: %v", err) + } + + s := sender.BuildSender("GoAzureHelpers") + + oauthConfig, err := c.BuildOAuthConfig(env.ActiveDirectoryEndpoint) + if err != nil { + return nil, fmt.Errorf("building oauthConfig: %v", err) + } + + authorizer, err := c.GetADALToken(ctx, s, oauthConfig, env.GraphEndpoint) + if err != nil { + return nil, fmt.Errorf("configuring Authorizer: %v", err) + } + + claims, err := claimsFromAutorestAuthorizer(authorizer) + if err != nil { + return nil, err + } + + return &claims.ObjectId, nil +} + +func objectIdFromMSALTokenClaims(ctx context.Context, c *Config) (*string, error) { + env, err := environments.EnvironmentFromString(c.Environment) + if err != nil { + return nil, fmt.Errorf("determining environment: %v", err) + } + + oauthConfig, err := c.BuildOAuthConfig(string(env.AzureADEndpoint)) + if err != nil { + return nil, fmt.Errorf("building oauthConfig: %v", err) + } + + authorizer, err := c.GetMSALToken(ctx, env.MsGraph, sender.BuildSender("GoAzureHelpers"), oauthConfig, string(env.MsGraph.Endpoint)) + if err != nil { + return nil, fmt.Errorf("configuring Authorizer: %v", err) + } + + claims, err := claimsFromAutorestAuthorizer(authorizer) + if err != nil { + return nil, err + } + + return &claims.ObjectId, nil +} + func objectIdFromAadGraph(ctx context.Context, c *Config) (*string, error) { env, err := AzureEnvironmentByNameFromEndpoint(ctx, c.MetadataHost, c.Environment) if err != nil { diff --git a/vendor/github.com/hashicorp/go-azure-helpers/authentication/config.go b/vendor/github.com/hashicorp/go-azure-helpers/authentication/config.go index ce58a2b13cc6..eaff361ec837 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/authentication/config.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/authentication/config.go @@ -8,6 +8,7 @@ import ( "github.com/Azure/go-autorest/autorest" "github.com/Azure/go-autorest/autorest/adal" + "github.com/manicminer/hamilton/auth" "github.com/manicminer/hamilton/environments" ) @@ -100,9 +101,9 @@ func (c Config) BuildOAuthConfig(activeDirectoryEndpoint string) (*OAuthConfig, return &multiAuth, nil } -// BearerAuthorizerCallback returns a BearerAuthorizer valid only for the Primary Tenant +// ADALBearerAuthorizerCallback returns a BearerAuthorizer valid only for the Primary Tenant // this signs a request using the AccessToken returned from the primary Resource Manager authorizer -func (c Config) BearerAuthorizerCallback(ctx context.Context, sender autorest.Sender, oauthConfig *OAuthConfig) *autorest.BearerAuthorizerCallback { +func (c Config) ADALBearerAuthorizerCallback(ctx context.Context, sender autorest.Sender, oauthConfig *OAuthConfig) *autorest.BearerAuthorizerCallback { return autorest.NewBearerAuthorizerCallback(sender, func(tenantID, resource string) (*autorest.BearerAuthorizer, error) { // a BearerAuthorizer is only valid for the primary tenant newAuthConfig := &OAuthConfig{ @@ -123,6 +124,26 @@ func (c Config) BearerAuthorizerCallback(ctx context.Context, sender autorest.Se }) } +// MSALBearerAuthorizerCallback returns a BearerAuthorizer valid only for the Primary Tenant +// this signs a request using the AccessToken returned from the primary Resource Manager authorizer +func (c Config) MSALBearerAuthorizerCallback(ctx context.Context, api environments.Api, sender autorest.Sender, oauthConfig *OAuthConfig, endpoint string) *autorest.BearerAuthorizerCallback { + authorizer, err := c.GetMSALToken(ctx, api, sender, oauthConfig, endpoint) + if err != nil { + return autorest.NewBearerAuthorizerCallback(nil, func(_, _ string) (*autorest.BearerAuthorizer, error) { + return nil, fmt.Errorf("failed to acquire MSAL token for %s", api.Endpoint) + }) + } + + cast, ok := authorizer.(*auth.CachedAuthorizer) + if !ok { + return autorest.NewBearerAuthorizerCallback(nil, func(_, _ string) (*autorest.BearerAuthorizer, error) { + return nil, fmt.Errorf("authorizer was not an auth.CachedAuthorizer for %s", api.Endpoint) + }) + } + + return cast.BearerAuthorizerCallback() +} + // GetADALToken returns an autorest.Authorizer using an ADAL token via the authentication method defined in the Config func (c Config) GetADALToken(ctx context.Context, sender autorest.Sender, oauth *OAuthConfig, endpoint string) (autorest.Authorizer, error) { return c.authMethod.getADALToken(ctx, sender, oauth, endpoint) diff --git a/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/from.go b/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/from.go deleted file mode 100644 index e0067ffb2c04..000000000000 --- a/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/from.go +++ /dev/null @@ -1,41 +0,0 @@ -package pointer - -// FromBool turns a boolean into a pointer to a boolean -func FromBool(input bool) *bool { - return &input -} - -// FromFloat64 turns a float64 into a pointer to a float64 -func FromFloat64(input float64) *float64 { - return &input -} - -// FromInt turns a int into a pointer to a int -func FromInt(input int) *int { - return &input -} - -// FromInt64 turns a int64 into a pointer to a int64 -func FromInt64(input int64) *int64 { - return &input -} - -// FromMapOfStringInterfaces turns a map[string]interface{} into a pointer to a map[string]interface{} -func FromMapOfStringInterfaces(input map[string]interface{}) *map[string]interface{} { - return &input -} - -// FromMapOfStringStrings turns a map[string]string into a pointer to a map[string]string -func FromMapOfStringStrings(input map[string]string) *map[string]string { - return &input -} - -// FromSliceOfStrings turns a slice of stirngs into a pointer to a slice of strings -func FromSliceOfStrings(input []string) *[]string { - return &input -} - -// FromString turns a string into a pointer to a string -func FromString(input string) *string { - return &input -} diff --git a/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/to.go b/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/to.go deleted file mode 100644 index 7f607dc20010..000000000000 --- a/vendor/github.com/hashicorp/go-azure-helpers/lang/pointer/to.go +++ /dev/null @@ -1,76 +0,0 @@ -package pointer - -// ToBool turns a pointer to a bool into a bool, returning the default value for a bool if it's nil -func ToBool(input *bool) bool { - if input != nil { - return *input - } - - return false -} - -// ToFloat64 turns a pointer to a float64 into a float64, returning the default value for a float64 if it's nil -func ToFloat64(input *float64) float64 { - if input != nil { - return *input - } - - return 0.0 -} - -// ToInt turns a pointer to an int into an int, returning the default value for an int if it's nil -func ToInt(input *int) int { - if input != nil { - return *input - } - - return 0 -} - -// ToInt64 turns a pointer to an int64 into an int64, returning the default value for an int64 if it's nil -func ToInt64(input *int64) int64 { - if input != nil { - return *input - } - - return 0 -} - -// ToMapOfStringInterfaces turns a pointer to a map[string]interface{} into a map[string]interface{} -// returning an empty map[string]interface{} if it's nil -func ToMapOfStringInterfaces(input *map[string]interface{}) map[string]interface{} { - if input != nil { - return *input - } - - return map[string]interface{}{} -} - -// ToMapOfStringStrings turns a pointer to a map[string]string into a map[string]string returning -// an empty map[string]string if it's nil -func ToMapOfStringStrings(input *map[string]string) map[string]string { - if input != nil { - return *input - } - - return map[string]string{} -} - -// ToSliceOfStrings turns a pointer to a slice of strings into a slice of strings returning -// an empty slice of strings if it's nil -func ToSliceOfStrings(input *[]string) []string { - if input != nil { - return *input - } - - return []string{} -} - -// ToString turns a pointer to a string into a string, returning an empty string if it's nil -func ToString(input *string) string { - if input != nil { - return *input - } - - return "" -} diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/management_group.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/management_group.go index 40d0cddc81fd..6ac466559443 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/management_group.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/management_group.go @@ -9,16 +9,19 @@ import ( var _ resourceids.ResourceId = ManagementGroupId{} +// ManagementGroupId is a struct representing the Resource ID for a Management Group type ManagementGroupId struct { GroupId string } +// NewManagementGroupID returns a new ManagementGroupId struct func NewManagementGroupID(groupId string) ManagementGroupId { return ManagementGroupId{ GroupId: groupId, } } +// ParseManagementGroupID parses 'input' into a ManagementGroupId func ParseManagementGroupID(input string) (*ManagementGroupId, error) { parser := resourceids.NewParserFromResourceIdType(ManagementGroupId{}) parsed, err := parser.Parse(input, false) @@ -36,6 +39,8 @@ func ParseManagementGroupID(input string) (*ManagementGroupId, error) { return &id, nil } +// ParseManagementGroupIDInsensitively parses 'input' case-insensitively into a ManagementGroupId +// note: this method should only be used for API response data and not user input func ParseManagementGroupIDInsensitively(input string) (*ManagementGroupId, error) { parser := resourceids.NewParserFromResourceIdType(ManagementGroupId{}) parsed, err := parser.Parse(input, true) @@ -53,20 +58,38 @@ func ParseManagementGroupIDInsensitively(input string) (*ManagementGroupId, erro return &id, nil } +// ValidateManagementGroupID checks that 'input' can be parsed as a Management Group ID +func ValidateManagementGroupID(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 := ParseManagementGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Management Group ID func (id ManagementGroupId) ID() string { fmtString := "/providers/Microsoft.Management/managementGroups/%s" return fmt.Sprintf(fmtString, id.GroupId) } +// Segments returns a slice of Resource ID Segments which comprise this Management Group ID func (id ManagementGroupId) Segments() []resourceids.Segment { return []resourceids.Segment{ resourceids.StaticSegment("providers", "providers", "providers"), - resourceids.ResourceProviderSegment("microsoftManagement", "Microsoft.Management", "Microsoft.Management"), + resourceids.ResourceProviderSegment("resourceProvider", "Microsoft.Management", "Microsoft.Management"), resourceids.StaticSegment("managementGroups", "managementGroups", "managementGroups"), resourceids.UserSpecifiedSegment("groupId", "groupIdValue"), } } +// String returns a human-readable description of this Management Group ID func (id ManagementGroupId) String() string { components := []string{ fmt.Sprintf("Group: %q", id.GroupId), diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/resource_group.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/resource_group.go index f93ee95a33ca..a0d4dd9b6d36 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/resource_group.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/resource_group.go @@ -9,11 +9,13 @@ import ( var _ resourceids.ResourceId = ResourceGroupId{} +// ResourceGroupId is a struct representing the Resource ID for a Resource Group type ResourceGroupId struct { SubscriptionId string ResourceGroupName string } +// NewResourceGroupID returns a new ResourceGroupId struct func NewResourceGroupID(subscriptionId string, resourceGroupName string) ResourceGroupId { return ResourceGroupId{ SubscriptionId: subscriptionId, @@ -21,6 +23,7 @@ func NewResourceGroupID(subscriptionId string, resourceGroupName string) Resourc } } +// ParseResourceGroupID parses 'input' into a ResourceGroupId func ParseResourceGroupID(input string) (*ResourceGroupId, error) { parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) parsed, err := parser.Parse(input, false) @@ -42,6 +45,8 @@ func ParseResourceGroupID(input string) (*ResourceGroupId, error) { return &id, nil } +// ParseResourceGroupIDInsensitively parses 'input' case-insensitively into a ResourceGroupId +// note: this method should only be used for API response data and not user input func ParseResourceGroupIDInsensitively(input string) (*ResourceGroupId, error) { parser := resourceids.NewParserFromResourceIdType(ResourceGroupId{}) parsed, err := parser.Parse(input, true) @@ -63,11 +68,28 @@ func ParseResourceGroupIDInsensitively(input string) (*ResourceGroupId, error) { return &id, nil } +// ValidateResourceGroupID checks that 'input' can be parsed as a Resource Group ID +func ValidateResourceGroupID(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 := ParseResourceGroupID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Resource Group ID func (id ResourceGroupId) ID() string { fmtString := "/subscriptions/%s/resourceGroups/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName) } +// Segments returns a slice of Resource ID Segments which comprise this Resource Group ID func (id ResourceGroupId) Segments() []resourceids.Segment { return []resourceids.Segment{ resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), @@ -77,6 +99,7 @@ func (id ResourceGroupId) Segments() []resourceids.Segment { } } +// String returns a human-readable description of this Resource Group ID func (id ResourceGroupId) String() string { components := []string{ fmt.Sprintf("Subscription: %q", id.SubscriptionId), diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/scope.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/scope.go new file mode 100644 index 000000000000..16fa1c2258f5 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/scope.go @@ -0,0 +1,95 @@ +package commonids + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ScopeId{} + +// ScopeId is a struct representing the Resource ID for a Scope +type ScopeId struct { + Scope string +} + +// NewScopeID returns a new ScopeId struct +func NewScopeID(scope string) ScopeId { + return ScopeId{ + Scope: scope, + } +} + +// ParseScopeID parses 'input' into a ScopeId +func ParseScopeID(input string) (*ScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopeId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopeId{} + + if id.Scope, ok = parsed.Parsed["scope"]; !ok { + return nil, fmt.Errorf("the segment 'scope' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseScopeIDInsensitively parses 'input' case-insensitively into a ScopeId +// note: this method should only be used for API response data and not user input +func ParseScopeIDInsensitively(input string) (*ScopeId, error) { + parser := resourceids.NewParserFromResourceIdType(ScopeId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ScopeId{} + + if id.Scope, ok = parsed.Parsed["scope"]; !ok { + return nil, fmt.Errorf("the segment 'scope' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateScopeID checks that 'input' can be parsed as a Scope ID +func ValidateScopeID(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 := ParseScopeID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Scope ID +func (id ScopeId) ID() string { + fmtString := "/%s" + return fmt.Sprintf(fmtString, strings.TrimPrefix(id.Scope, "/")) +} + +// Segments returns a slice of Resource ID Segments which comprise this Scope ID +func (id ScopeId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.ScopeSegment("scope", "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/some-resource-group"), + } +} + +// String returns a human-readable description of this Scope ID +func (id ScopeId) String() string { + components := []string{ + fmt.Sprintf("Scope: %q", id.Scope), + } + return fmt.Sprintf("Scope (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/subscription.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/subscription.go index 7e7b0130fe22..6309d72bbbcb 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/subscription.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/subscription.go @@ -9,16 +9,19 @@ import ( var _ resourceids.ResourceId = SubscriptionId{} +// SubscriptionId is a struct representing the Resource ID for a Subscription type SubscriptionId struct { SubscriptionId string } +// NewSubscriptionID returns a new SubscriptionId struct func NewSubscriptionID(subscriptionId string) SubscriptionId { return SubscriptionId{ SubscriptionId: subscriptionId, } } +// ParseSubscriptionID parses 'input' into a SubscriptionId func ParseSubscriptionID(input string) (*SubscriptionId, error) { parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) parsed, err := parser.Parse(input, false) @@ -36,6 +39,8 @@ func ParseSubscriptionID(input string) (*SubscriptionId, error) { return &id, nil } +// ParseSubscriptionIDInsensitively parses 'input' case-insensitively into a SubscriptionId +// note: this method should only be used for API response data and not user input func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) { parser := resourceids.NewParserFromResourceIdType(SubscriptionId{}) parsed, err := parser.Parse(input, true) @@ -53,11 +58,28 @@ func ParseSubscriptionIDInsensitively(input string) (*SubscriptionId, error) { return &id, nil } +// ValidateSubscriptionID checks that 'input' can be parsed as a Subscription ID +func ValidateSubscriptionID(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 := ParseSubscriptionID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Subscription ID func (id SubscriptionId) ID() string { fmtString := "/subscriptions/%s" return fmt.Sprintf(fmtString, id.SubscriptionId) } +// Segments returns a slice of Resource ID Segments which comprise this Subscription ID func (id SubscriptionId) Segments() []resourceids.Segment { return []resourceids.Segment{ resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), @@ -65,6 +87,7 @@ func (id SubscriptionId) Segments() []resourceids.Segment { } } +// String returns a human-readable description of this Subscription ID func (id SubscriptionId) String() string { components := []string{ fmt.Sprintf("Subscription: %q", id.SubscriptionId), diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/user_assigned_identity.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/user_assigned_identity.go index 94dd1c5e614a..55f28bf8f40b 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/user_assigned_identity.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/user_assigned_identity.go @@ -9,12 +9,14 @@ import ( var _ resourceids.ResourceId = UserAssignedIdentityId{} +// UserAssignedIdentityId is a struct representing the Resource ID for a User Assigned Identity type UserAssignedIdentityId struct { SubscriptionId string ResourceGroupName string ResourceName string } +// NewUserAssignedIdentityID returns a new UserAssignedIdentityId struct func NewUserAssignedIdentityID(subscriptionId string, resourceGroupName string, resourceName string) UserAssignedIdentityId { return UserAssignedIdentityId{ SubscriptionId: subscriptionId, @@ -23,6 +25,7 @@ func NewUserAssignedIdentityID(subscriptionId string, resourceGroupName string, } } +// ParseUserAssignedIdentityID parses 'input' into a UserAssignedIdentityId func ParseUserAssignedIdentityID(input string) (*UserAssignedIdentityId, error) { parser := resourceids.NewParserFromResourceIdType(UserAssignedIdentityId{}) parsed, err := parser.Parse(input, false) @@ -48,6 +51,8 @@ func ParseUserAssignedIdentityID(input string) (*UserAssignedIdentityId, error) return &id, nil } +// ParseUserAssignedIdentityIDInsensitively parses 'input' case-insensitively into a UserAssignedIdentityId +// note: this method should only be used for API response data and not user input func ParseUserAssignedIdentityIDInsensitively(input string) (*UserAssignedIdentityId, error) { parser := resourceids.NewParserFromResourceIdType(UserAssignedIdentityId{}) parsed, err := parser.Parse(input, true) @@ -73,11 +78,28 @@ func ParseUserAssignedIdentityIDInsensitively(input string) (*UserAssignedIdenti return &id, nil } +// ValidateUserAssignedIdentityID checks that 'input' can be parsed as a User Assigned Identity ID +func ValidateUserAssignedIdentityID(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 := ParseUserAssignedIdentityID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted User Assigned Identity ID func (id UserAssignedIdentityId) ID() string { fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities/%s" return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ResourceName) } +// Segments returns a slice of Resource ID Segments which comprise this User Assigned Identity ID func (id UserAssignedIdentityId) Segments() []resourceids.Segment { return []resourceids.Segment{ resourceids.StaticSegment("subscriptions", "subscriptions", "subscriptions"), @@ -85,17 +107,18 @@ func (id UserAssignedIdentityId) Segments() []resourceids.Segment { resourceids.StaticSegment("resourceGroups", "resourceGroups", "resourceGroups"), resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), resourceids.StaticSegment("providers", "providers", "providers"), - resourceids.ResourceProviderSegment("microsoftManagedIdentity", "Microsoft.ManagedIdentity", "Microsoft.ManagedIdentity"), + resourceids.ResourceProviderSegment("resourceProvider", "Microsoft.ManagedIdentity", "Microsoft.ManagedIdentity"), resourceids.StaticSegment("userAssignedIdentities", "userAssignedIdentities", "userAssignedIdentities"), resourceids.UserSpecifiedSegment("resourceName", "resourceValue"), } } +// String returns a human-readable description of this User Assigned Identities ID func (id UserAssignedIdentityId) String() string { components := []string{ fmt.Sprintf("Subscription: %q", id.SubscriptionId), fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), fmt.Sprintf("Resource Name: %q", id.ResourceName), } - return fmt.Sprintf("User Assigned Identities (%s)", strings.Join(components, "\n")) + return fmt.Sprintf("User Assigned Identity (%s)", strings.Join(components, "\n")) } diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/validation.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/validation.go deleted file mode 100644 index 2f9d399c17cb..000000000000 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/commonids/validation.go +++ /dev/null @@ -1,59 +0,0 @@ -package commonids - -import "fmt" - -func ValidateManagementGroupID(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 := ParseManagementGroupID(v); err != nil { - errors = append(errors, err) - } - - return -} - -func ValidateResourceGroupID(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 := ParseResourceGroupID(v); err != nil { - errors = append(errors, err) - } - - return -} - -func ValidateSubscriptionID(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 := ParseSubscriptionID(v); err != nil { - errors = append(errors, err) - } - - return -} - -func ValidateUserAssignedIdentityID(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 := ParseUserAssignedIdentityID(v); err != nil { - errors = append(errors, err) - } - - return -} diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/expand.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/expand.go index 89a25c0f046c..c745f55e4129 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/expand.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/expand.go @@ -1,10 +1,13 @@ package tags +// Expand transforms the input Tags to a `*map[string]string` func Expand(input map[string]interface{}) *map[string]string { output := make(map[string]string) for k, v := range input { - output[k] = v.(string) + tagKey := k + tagValue := v.(string) + output[tagKey] = tagValue } return &output diff --git a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/flatten.go b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/flatten.go index e8cbbfcdebf0..0acb5311697d 100644 --- a/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/flatten.go +++ b/vendor/github.com/hashicorp/go-azure-helpers/resourcemanager/tags/flatten.go @@ -1,18 +1,35 @@ package tags import ( - "github.com/hashicorp/go-azure-helpers/lang/pointer" + "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) -func Flatten(input *map[string]string) map[string]*string { - output := make(map[string]*string) +// Flatten transforms the Tags specified via `input` into a map[string]interface{} +// for compatibility with the Schema. +func Flatten(input *map[string]string) map[string]interface{} { + output := make(map[string]interface{}) if input == nil { return output } for k, v := range *input { - output[k] = pointer.FromString(v) + tagKey := k + tagValue := v + output[tagKey] = tagValue } return output } + +// FlattenAndSet first Flatten's the Tags and then sets the flattened value into +// the `tags` field in the State. +func FlattenAndSet(d *schema.ResourceData, input *map[string]string) error { + tags := Flatten(input) + + if err := d.Set("tags", tags); err != nil { + return fmt.Errorf("setting `tags`: %+v", err) + } + + return nil +} diff --git a/vendor/github.com/manicminer/hamilton/auth/cache.go b/vendor/github.com/manicminer/hamilton/auth/cache.go index 32077e5517a7..409e7ad4f1df 100644 --- a/vendor/github.com/manicminer/hamilton/auth/cache.go +++ b/vendor/github.com/manicminer/hamilton/auth/cache.go @@ -64,6 +64,7 @@ func (c *CachedAuthorizer) AuxiliaryTokens() ([]*oauth2.Token, error) { return c.auxTokens, nil } +// WithAuthorization implements the autorest.Authorizer interface func (c *CachedAuthorizer) WithAuthorization() autorest.PrepareDecorator { return func(p autorest.Preparer) autorest.Preparer { return autorest.PreparerFunc(func(req *http.Request) (*http.Request, error) { @@ -100,6 +101,21 @@ func (c *CachedAuthorizer) WithAuthorization() autorest.PrepareDecorator { } } +// BearerAuthorizerCallback is a helper that returns an *autorest.BearerAuthorizerCallback for use in data plane API clients in the Azure SDK +func (c *CachedAuthorizer) BearerAuthorizerCallback() *autorest.BearerAuthorizerCallback { + return autorest.NewBearerAuthorizerCallback(nil, func(_, resource string) (*autorest.BearerAuthorizer, error) { + token, err := c.Token() + if err != nil { + return nil, fmt.Errorf("obtaining token: %v", err) + } + + return autorest.NewBearerAuthorizer(&servicePrincipalTokenWrapper{ + tokenType: "Bearer", + tokenValue: token.AccessToken, + }), nil + }) +} + // NewCachedAuthorizer returns an Authorizer that caches an access token for the duration of its validity. // If the cached token expires, a new one is acquired and cached. func NewCachedAuthorizer(src Authorizer) Authorizer { diff --git a/vendor/github.com/manicminer/hamilton/environments/apis.go b/vendor/github.com/manicminer/hamilton/environments/apis.go index 75d2f79b1f2c..5a45a3cfbef8 100644 --- a/vendor/github.com/manicminer/hamilton/environments/apis.go +++ b/vendor/github.com/manicminer/hamilton/environments/apis.go @@ -4,6 +4,8 @@ import ( "fmt" ) +var ApiUnavailable = Api{} + // API represent an API configuration for Microsoft Graph or Azure Active Directory Graph. type Api struct { // The Application ID for the API. @@ -13,11 +15,15 @@ type Api struct { Endpoint ApiEndpoint } -func (a *Api) DefaultScope() string { +func (a Api) IsAvailable() bool { + return a != ApiUnavailable +} + +func (a Api) DefaultScope() string { return fmt.Sprintf("%s/.default", a.Endpoint) } -func (a *Api) Resource() string { +func (a Api) Resource() string { return fmt.Sprintf("%s/", a.Endpoint) } diff --git a/vendor/github.com/manicminer/hamilton/environments/endpoints.go b/vendor/github.com/manicminer/hamilton/environments/endpoints.go index 11f5961f75ff..a6922d37cd99 100644 --- a/vendor/github.com/manicminer/hamilton/environments/endpoints.go +++ b/vendor/github.com/manicminer/hamilton/environments/endpoints.go @@ -33,7 +33,7 @@ const ( KeyVaultPublicEndpoint ApiEndpoint = "https://vault.azure.net" KeyVaultChinaEndpoint ApiEndpoint = "https://vault.azure.cn" - KeyVaultUSGovEndpoint ApiEndpoint = "https://vault.microsoftazure.de" + KeyVaultUSGovEndpoint ApiEndpoint = "https://vault.microsoftazure.us" OperationalInsightsPublicEndpoint ApiEndpoint = "https://api.loganalytics.io" OperationalInsightsUSGovEndpoint ApiEndpoint = "https://api.loganalytics.us" diff --git a/vendor/github.com/manicminer/hamilton/environments/environments.go b/vendor/github.com/manicminer/hamilton/environments/environments.go index 3b090957a335..072f43311748 100644 --- a/vendor/github.com/manicminer/hamilton/environments/environments.go +++ b/vendor/github.com/manicminer/hamilton/environments/environments.go @@ -45,16 +45,19 @@ var ( } China = Environment{ - AzureADEndpoint: AzureADChina, - MsGraph: MsGraphChina, - AadGraph: AadGraphChina, - ResourceManager: ResourceManagerChina, - BatchManagement: BatchManagementChina, - KeyVault: KeyVaultChina, - OSSRDBMS: OSSRDBMSChina, - ServiceBus: ServiceBusChina, - ServiceManagement: ServiceManagementChina, - SQLDatabase: SQLDatabaseChina, + AzureADEndpoint: AzureADChina, + MsGraph: MsGraphChina, + AadGraph: AadGraphChina, + ResourceManager: ResourceManagerChina, + BatchManagement: BatchManagementChina, + KeyVault: KeyVaultChina, + OperationalInsights: ApiUnavailable, + OSSRDBMS: OSSRDBMSChina, + ServiceBus: ServiceBusChina, + ServiceManagement: ServiceManagementChina, + SQLDatabase: SQLDatabaseChina, + Storage: StoragePublic, + Synapse: SynapsePublic, } USGovernmentL4 = Environment{ @@ -63,12 +66,15 @@ var ( AadGraph: AadGraphUSGov, ResourceManager: ResourceManagerUSGov, BatchManagement: BatchManagementUSGov, + DataLake: ApiUnavailable, KeyVault: KeyVaultUSGov, OperationalInsights: OperationalInsightsUSGov, OSSRDBMS: OSSRDBMSUSGov, ServiceBus: ServiceBusUSGov, ServiceManagement: ServiceManagementUSGov, SQLDatabase: SQLDatabaseUSGov, + Storage: StoragePublic, + Synapse: ApiUnavailable, } USGovernmentL5 = Environment{ @@ -77,12 +83,15 @@ var ( AadGraph: AadGraphUSGov, ResourceManager: ResourceManagerUSGov, BatchManagement: BatchManagementUSGov, + DataLake: ApiUnavailable, KeyVault: KeyVaultUSGov, OperationalInsights: OperationalInsightsUSGov, OSSRDBMS: OSSRDBMSUSGov, ServiceBus: ServiceBusUSGov, ServiceManagement: ServiceManagementUSGov, SQLDatabase: SQLDatabaseUSGov, + Storage: StoragePublic, + Synapse: ApiUnavailable, } Canary = Environment{ diff --git a/vendor/github.com/manicminer/hamilton/msgraph/administrative_units.go b/vendor/github.com/manicminer/hamilton/msgraph/administrative_units.go new file mode 100644 index 000000000000..04b5b3008e01 --- /dev/null +++ b/vendor/github.com/manicminer/hamilton/msgraph/administrative_units.go @@ -0,0 +1,441 @@ +package msgraph + +import ( + "context" + "encoding/json" + "fmt" + "io" + "net/http" + + "github.com/manicminer/hamilton/odata" +) + +// AdministrativeUnitsClient performs operations on Administrative Units +type AdministrativeUnitsClient struct { + BaseClient Client +} + +// NewAdministrativeUnitsClient returns a new AdministrativeUnitsClient. +func NewAdministrativeUnitsClient(tenantId string) *AdministrativeUnitsClient { + return &AdministrativeUnitsClient{ + BaseClient: NewClient(VersionBeta, tenantId), + } +} + +// List returns a list of AdministrativeUnits, optionally queried using OData. +func (c *AdministrativeUnitsClient) List(ctx context.Context, query odata.Query) (*[]AdministrativeUnit, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + DisablePaging: query.Top > 0, + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: "/administrativeUnits", + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data struct { + AdministrativeUnits []AdministrativeUnit `json:"value"` + } + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data.AdministrativeUnits, status, nil +} + +// Create creates a new AdministrativeUnit. +func (c *AdministrativeUnitsClient) Create(ctx context.Context, administrativeUnit AdministrativeUnit) (*AdministrativeUnit, int, error) { + var status int + + body, err := json.Marshal(administrativeUnit) + if err != nil { + return nil, status, fmt.Errorf("json.Marshal(): %v", err) + } + + resp, status, _, err := c.BaseClient.Post(ctx, PostHttpRequestInput{ + Body: body, + OData: odata.Query{ + Metadata: odata.MetadataFull, + }, + ValidStatusCodes: []int{http.StatusCreated}, + Uri: Uri{ + Entity: "/administrativeUnits", + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Post(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var newAdministrativeUnit AdministrativeUnit + if err := json.Unmarshal(respBody, &newAdministrativeUnit); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &newAdministrativeUnit, status, nil +} + +// Get retrieves an AdministrativeUnit +func (c *AdministrativeUnitsClient) Get(ctx context.Context, id string, query odata.Query) (*AdministrativeUnit, int, error) { + query.Metadata = odata.MetadataFull + + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s", id), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var administrativeUnit AdministrativeUnit + if err := json.Unmarshal(respBody, &administrativeUnit); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &administrativeUnit, status, nil +} + +// Update amends an existing AdministrativeUnit. +func (c *AdministrativeUnitsClient) Update(ctx context.Context, administrativeUnit AdministrativeUnit) (int, error) { + var status int + + body, err := json.Marshal(administrativeUnit) + if err != nil { + return status, fmt.Errorf("json.Marshal(): %v", err) + } + + _, status, _, err = c.BaseClient.Patch(ctx, PatchHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s", *administrativeUnit.ID), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Patch(): %v", err) + } + + return status, nil +} + +// Delete removes a AdministrativeUnit. +func (c *AdministrativeUnitsClient) Delete(ctx context.Context, id string) (int, error) { + _, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s", id), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("AdministrativeUnits.BaseClient.Get(): %v", err) + } + + return status, nil +} + +// ListMembers retrieves the members of the specified AdministrativeUnit. +func (c *AdministrativeUnitsClient) ListMembers(ctx context.Context, administrativeUnitId string) (*[]string, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + OData: odata.Query{ + Select: []string{"id"}, + }, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/members", administrativeUnitId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data struct { + Members []struct { + Type string `json:"@odata.type"` + Id string `json:"id"` + } `json:"value"` + } + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + ret := make([]string, len(data.Members)) + for i, v := range data.Members { + ret[i] = v.Id + } + + return &ret, status, nil +} + +// GetMember retrieves a single member of the specified AdministrativeUnit. +func (c *AdministrativeUnitsClient) GetMember(ctx context.Context, administrativeUnitId, memberId string) (*string, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + OData: odata.Query{ + Select: []string{"id", "url"}, + }, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/members/%s/$ref", administrativeUnitId, memberId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data struct { + Context string `json:"@odata.context"` + Type string `json:"@odata.type"` + Id string `json:"id"` + Url string `json:"url"` + } + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data.Id, status, nil +} + +// AddMembers adds new members to a AdministrativeUnit. +func (c *AdministrativeUnitsClient) AddMembers(ctx context.Context, administrativeUnitId string, members *Members) (int, error) { + var status int + + if members == nil || len(*members) == 0 { + return status, fmt.Errorf("no members specified") + } + + for _, member := range *members { + // don't fail if a member already exists + checkMemberAlreadyExists := func(resp *http.Response, o *odata.OData) bool { + if resp != nil && resp.StatusCode == http.StatusBadRequest && o != nil && o.Error != nil { + return o.Error.Match(odata.ErrorAddedObjectReferencesAlreadyExist) + } + return false + } + + body, err := json.Marshal(DirectoryObject{ODataId: member.ODataId}) + if err != nil { + return status, fmt.Errorf("json.Marshal(): %v", err) + } + + _, status, _, err = c.BaseClient.Post(ctx, PostHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + ValidStatusFunc: checkMemberAlreadyExists, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/members/$ref", administrativeUnitId), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Post(): %v", err) + } + } + + return status, nil +} + +// RemoveMembers removes members from a AdministrativeUnit. +func (c *AdministrativeUnitsClient) RemoveMembers(ctx context.Context, administrativeUnitId string, memberIds *[]string) (int, error) { + var status int + + if memberIds == nil || len(*memberIds) == 0 { + return status, fmt.Errorf("no members specified") + } + + for _, memberId := range *memberIds { + // check for membership before attempting deletion + if _, status, err := c.GetMember(ctx, administrativeUnitId, memberId); err != nil { + if status == http.StatusNotFound { + continue + } + return status, err + } + + // despite the above check, sometimes members are just gone + checkMemberGone := func(resp *http.Response, o *odata.OData) bool { + if resp != nil && resp.StatusCode == http.StatusBadRequest && o != nil && o.Error != nil { + return o.Error.Match(odata.ErrorRemovedObjectReferencesDoNotExist) + } + return false + } + + var err error + _, status, _, err = c.BaseClient.Delete(ctx, DeleteHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + ValidStatusFunc: checkMemberGone, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/members/%s/$ref", administrativeUnitId, memberId), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Delete(): %v", err) + } + } + + return status, nil +} + +// ListScopedRoleMembers retrieves the members of the specified AdministrativeUnit. +func (c *AdministrativeUnitsClient) ListScopedRoleMembers(ctx context.Context, administrativeUnitId string, query odata.Query) (*[]ScopedRoleMembership, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/scopedRoleMembers", administrativeUnitId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data struct { + ScopedRoleMembers []ScopedRoleMembership `json:"value"` + } + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data.ScopedRoleMembers, status, nil +} + +// GetScopedRoleMember retrieves a single member of the specified AdministrativeUnit. +func (c *AdministrativeUnitsClient) GetScopedRoleMember(ctx context.Context, administrativeUnitId, scopedRoleMembershipId string, query odata.Query) (*ScopedRoleMembership, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/scopedRoleMembers/%s", administrativeUnitId, scopedRoleMembershipId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data ScopedRoleMembership + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data, status, nil +} + +// AddScopedRoleMember adds a new scoped role membership for a AdministrativeUnit. +func (c *AdministrativeUnitsClient) AddScopedRoleMember(ctx context.Context, administrativeUnitId string, scopedRoleMembership ScopedRoleMembership) (*ScopedRoleMembership, int, error) { + var status int + + body, err := json.Marshal(scopedRoleMembership) + if err != nil { + return nil, status, fmt.Errorf("json.Marshal(): %v", err) + } + + resp, status, _, err := c.BaseClient.Post(ctx, PostHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusCreated}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/scopedRoleMembers", administrativeUnitId), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Post(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data ScopedRoleMembership + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data, status, nil +} + +// RemoveScopedRoleMembers removes members from a AdministrativeUnit. +func (c *AdministrativeUnitsClient) RemoveScopedRoleMembers(ctx context.Context, administrativeUnitId, scopedRoleMembershipId string) (int, error) { + var status int + + var err error + _, status, _, err = c.BaseClient.Delete(ctx, DeleteHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/administrativeUnits/%s/scopedRoleMembers/%s", administrativeUnitId, scopedRoleMembershipId), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("AdministrativeUnitsClient.BaseClient.Delete(): %v", err) + } + + return status, nil +} diff --git a/vendor/github.com/manicminer/hamilton/msgraph/delegated_permission_grants_client.go b/vendor/github.com/manicminer/hamilton/msgraph/delegated_permission_grants_client.go new file mode 100644 index 000000000000..48b1c9c4c635 --- /dev/null +++ b/vendor/github.com/manicminer/hamilton/msgraph/delegated_permission_grants_client.go @@ -0,0 +1,179 @@ +package msgraph + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + + "github.com/manicminer/hamilton/odata" +) + +// DelegatedPermissionGrantsClient performs operations on DelegatedPermissionGrants. +type DelegatedPermissionGrantsClient struct { + BaseClient Client +} + +// NewDelegatedPermissionGrantsClient returns a new DelegatedPermissionGrantsClient +func NewDelegatedPermissionGrantsClient(tenantId string) *DelegatedPermissionGrantsClient { + return &DelegatedPermissionGrantsClient{ + BaseClient: NewClient(Version10, tenantId), + } +} + +// List returns a list of delegated permission grants +func (c *DelegatedPermissionGrantsClient) List(ctx context.Context, query odata.Query) (*[]DelegatedPermissionGrant, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: "/oauth2PermissionGrants", + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("DelegatedPermissionGrantsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data struct { + DelegatedPermissionGrants []DelegatedPermissionGrant `json:"value"` + } + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data.DelegatedPermissionGrants, status, nil +} + +// Create creates a new delegated permission grant +func (c *DelegatedPermissionGrantsClient) Create(ctx context.Context, delegatedPermissionGrant DelegatedPermissionGrant) (*DelegatedPermissionGrant, int, error) { + var status int + + if delegatedPermissionGrant.ClientId == nil { + return nil, status, errors.New("DelegatedPermissionGrantsClient.Create(): ClientId was nil for delegatedPermissionGrant") + } + + body, err := json.Marshal(delegatedPermissionGrant) + if err != nil { + return nil, status, fmt.Errorf("json.Marshal(): %v", err) + } + + consistencyFunc := func(resp *http.Response, o *odata.OData) bool { + if resp != nil && o != nil && o.Error != nil { + if resp.StatusCode == http.StatusNotFound { + return true + } else if resp.StatusCode == http.StatusBadRequest { + return o.Error.Match(odata.ErrorResourceDoesNotExist) + } + } + return false + } + + resp, status, _, err := c.BaseClient.Post(ctx, PostHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: consistencyFunc, + ValidStatusCodes: []int{http.StatusCreated}, + Uri: Uri{ + Entity: "/oauth2PermissionGrants", + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("DelegatedPermissionGrantsClient.BaseClient.Post(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var newDelegatedPermissionGrant DelegatedPermissionGrant + if err := json.Unmarshal(respBody, &newDelegatedPermissionGrant); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &newDelegatedPermissionGrant, status, nil +} + +// Get returns a delegated permission grant +func (c *DelegatedPermissionGrantsClient) Get(ctx context.Context, id string, query odata.Query) (*DelegatedPermissionGrant, int, error) { + resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{ + OData: query, + ValidStatusCodes: []int{http.StatusOK}, + Uri: Uri{ + Entity: fmt.Sprintf("/oauth2PermissionGrants/%s", id), + HasTenantId: true, + }, + }) + if err != nil { + return nil, status, fmt.Errorf("DelegatedPermissionGrantsClient.BaseClient.Get(): %v", err) + } + + defer resp.Body.Close() + respBody, err := io.ReadAll(resp.Body) + if err != nil { + return nil, status, fmt.Errorf("io.ReadAll(): %v", err) + } + + var data DelegatedPermissionGrant + if err := json.Unmarshal(respBody, &data); err != nil { + return nil, status, fmt.Errorf("json.Unmarshal(): %v", err) + } + + return &data, status, nil +} + +// Update amends an existing delegated permission grant +func (c *DelegatedPermissionGrantsClient) Update(ctx context.Context, delegatedPermissionGrant DelegatedPermissionGrant) (int, error) { + var status int + + if delegatedPermissionGrant.Id == nil { + return status, errors.New("cannot update delegated permission grant with nil ID") + } + + body, err := json.Marshal(delegatedPermissionGrant) + if err != nil { + return status, fmt.Errorf("json.Marshal(): %v", err) + } + + _, status, _, err = c.BaseClient.Patch(ctx, PatchHttpRequestInput{ + Body: body, + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/oauth2PermissionGrants/%s", *delegatedPermissionGrant.Id), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("DelegatedPermissionGrantsClient.BaseClient.Patch(): %v", err) + } + + return status, nil +} + +// Delete removes a delegated permission grant +func (c *DelegatedPermissionGrantsClient) Delete(ctx context.Context, id string) (int, error) { + _, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{ + ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc, + ValidStatusCodes: []int{http.StatusNoContent}, + Uri: Uri{ + Entity: fmt.Sprintf("/oauth2PermissionGrants/%s", id), + HasTenantId: true, + }, + }) + if err != nil { + return status, fmt.Errorf("DelegatedPermissionGrantsClient.BaseClient.Delete(): %v", err) + } + + return status, nil +} diff --git a/vendor/github.com/manicminer/hamilton/msgraph/models.go b/vendor/github.com/manicminer/hamilton/msgraph/models.go index 3f5eae8da55b..710403a07113 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/models.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/models.go @@ -157,6 +157,13 @@ type AddInKeyValue struct { Value *string `json:"value,omitempty"` } +type AdministrativeUnit struct { + Description *StringNullWhenEmpty `json:"description,omitempty"` + DisplayName *string `json:"displayName,omitempty"` + ID *string `json:"id,omitempty"` + Visibility *AdministrativeUnitVisibility `json:"visibility,omitempty"` +} + type ApiPreAuthorizedApplication struct { AppId *string `json:"appId,omitempty"` PermissionIds *[]string `json:"permissionIds,omitempty"` @@ -518,8 +525,8 @@ type BaseNamedLocation struct { } type CloudAppSecurityControl struct { - IsEnabled *bool `json:"isEnabled,omitempty"` - CloudAppSecurityType *string `json:"cloudAppSecurityType,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` + CloudAppSecurityType *ConditionalAccessCloudAppSecuritySessionControlType `json:"cloudAppSecurityType,omitempty"` } type ConditionalAccessApplications struct { @@ -529,20 +536,38 @@ type ConditionalAccessApplications struct { } type ConditionalAccessConditionSet struct { - Applications *ConditionalAccessApplications `json:"applications,omitempty"` - Users *ConditionalAccessUsers `json:"users,omitempty"` - ClientAppTypes *[]string `json:"clientAppTypes,omitempty"` - Locations *ConditionalAccessLocations `json:"locations,omitempty"` - Platforms *ConditionalAccessPlatforms `json:"platforms,omitempty"` - SignInRiskLevels *[]string `json:"signInRiskLevels,omitempty"` - UserRiskLevels *[]string `json:"userRiskLevels,omitempty"` + Applications *ConditionalAccessApplications `json:"applications,omitempty"` + ClientAppTypes *[]ConditionalAccessClientAppType `json:"clientAppTypes,omitempty"` + Devices *ConditionalAccessDevices `json:"devices,omitempty"` + DeviceStates *ConditionalAccessDeviceStates `json:"deviceStates,omitempty"` + Locations *ConditionalAccessLocations `json:"locations,omitempty"` + Platforms *ConditionalAccessPlatforms `json:"platforms,omitempty"` + SignInRiskLevels *[]ConditionalAccessRiskLevel `json:"signInRiskLevels,omitempty"` + UserRiskLevels *[]ConditionalAccessRiskLevel `json:"userRiskLevels,omitempty"` + Users *ConditionalAccessUsers `json:"users,omitempty"` +} + +type ConditionalAccessDevices struct { + IncludeDevices *[]string `json:"includeDevices,omitempty"` + ExcludeDevices *[]string `json:"excludeDevices,omitempty"` + DeviceFilter *ConditionalAccessFilter `json:"deviceFilter,omitempty"` +} + +type ConditionalAccessDeviceStates struct { + IncludeStates *ConditionalAccessDeviceStatesInclude `json:"includeStates,omitempty"` + ExcludeStates *ConditionalAccessDeviceStatesExclude `json:"excludeStates,omitempty"` +} + +type ConditionalAccessFilter struct { + Mode *ConditionalAccessFilterMode `json:"mode,omitempty"` + Rule *string `json:"rule,omitempty"` } type ConditionalAccessGrantControls struct { - Operator *string `json:"operator,omitempty"` - BuiltInControls *[]string `json:"builtInControls,omitempty"` - CustomAuthenticationFactors *[]string `json:"customAuthenticationFactors,omitempty"` - TermsOfUse *[]string `json:"termsOfUse,omitempty"` + Operator *string `json:"operator,omitempty"` + BuiltInControls *[]ConditionalAccessGrantControl `json:"builtInControls,omitempty"` + CustomAuthenticationFactors *[]string `json:"customAuthenticationFactors,omitempty"` + TermsOfUse *[]string `json:"termsOfUse,omitempty"` } type ConditionalAccessLocations struct { @@ -551,8 +576,8 @@ type ConditionalAccessLocations struct { } type ConditionalAccessPlatforms struct { - IncludePlatforms *[]string `json:"includePlatforms,omitempty"` - ExcludePlatforms *[]string `json:"excludePlatforms,omitempty"` + IncludePlatforms *[]ConditionalAccessDevicePlatform `json:"includePlatforms,omitempty"` + ExcludePlatforms *[]ConditionalAccessDevicePlatform `json:"excludePlatforms,omitempty"` } // ConditionalAccessPolicy describes an Conditional Access Policy object. @@ -618,6 +643,61 @@ type CredentialUserRegistrationDetails struct { UserPrincipalName *string `json:"UserPrincipalName,omitempty"` } +type DelegatedPermissionGrant struct { + Id *string `json:"id,omitempty"` + ClientId *string `json:"clientId,omitempty"` + ConsentType *DelegatedPermissionGrantConsentType `json:"consentType,omitempty"` + PrincipalId *string `json:"principalId,omitempty"` + ResourceId *string `json:"resourceId,omitempty"` + Scopes *[]string `json:"-"` +} + +func (d DelegatedPermissionGrant) MarshalJSON() ([]byte, error) { + var val *StringNullWhenEmpty + if d.Scopes != nil { + scopes := make([]string, 0) + for _, s := range *d.Scopes { + scopes = append(scopes, string(s)) + } + theScopes := StringNullWhenEmpty(strings.Join(scopes, " ")) + val = &theScopes + } + + // Local type needed to avoid recursive MarshalJSON calls + type delegatedPermissionGrant DelegatedPermissionGrant + grant := struct { + Scopes *StringNullWhenEmpty `json:"scope,omitempty"` + *delegatedPermissionGrant + }{ + Scopes: val, + delegatedPermissionGrant: (*delegatedPermissionGrant)(&d), + } + buf, err := json.Marshal(&grant) + return buf, err +} + +func (d *DelegatedPermissionGrant) UnmarshalJSON(data []byte) error { + // Local type needed to avoid recursive UnmarshalJSON calls + type delegatedPermissionGrant DelegatedPermissionGrant + grant := struct { + Scopes *string `json:"scope"` + *delegatedPermissionGrant + }{ + delegatedPermissionGrant: (*delegatedPermissionGrant)(d), + } + if err := json.Unmarshal(data, &grant); err != nil { + return err + } + if grant.Scopes != nil { + var scopes []string + for _, s := range strings.Split(*grant.Scopes, " ") { + scopes = append(scopes, strings.TrimSpace(s)) + } + d.Scopes = &scopes + } + return nil +} + type DeviceDetail struct { Browser *string `json:"browser,omitempty"` DeviceId *string `json:"deviceId,omitempty"` @@ -862,6 +942,12 @@ type GroupOnPremisesProvisioningError struct { Value *string `json:"value,omitempty"` } +type Identity struct { + DisplayName *string `json:"displayName,omitempty"` + Id *string `json:"id,omitempty"` + TenantId *string `json:"tenantId,omitempty"` +} + type IdentityProvider struct { ODataType *odata.Type `json:"@odata.type,omitempty"` ID *string `json:"id,omitempty"` @@ -1071,8 +1157,8 @@ type PermissionScope struct { } type PersistentBrowserSessionControl struct { - IsEnabled *bool `json:"isEnabled,omitempty"` - Mode *string `json:"mode,omitempty"` + IsEnabled *bool `json:"isEnabled,omitempty"` + Mode *PersistentBrowserSessionMode `json:"mode,omitempty"` } type PhoneAuthenticationMethod struct { @@ -1129,6 +1215,13 @@ func (se SchemaExtensionData) MarshalJSON() ([]byte, error) { return json.Marshal(in) } +type ScopedRoleMembership struct { + AdministrativeUnitId *string `json:"administrativeUnitId,omitempty"` + Id *string `json:"id,omitempty"` + RoleId *string `json:"roleId,omitempty"` + RoleMemberInfo *Identity `json:"roleMemberInfo"` +} + // ServicePrincipal describes a Service Principal object. type ServicePrincipal struct { DirectoryObject diff --git a/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go b/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go index eb33cb5b766d..8456b5685e93 100644 --- a/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go +++ b/vendor/github.com/manicminer/hamilton/msgraph/valuetypes.go @@ -7,6 +7,9 @@ import ( "github.com/manicminer/hamilton/odata" ) +// NullableString returns a pointer to a StringNullWhenEmpty for use in model structs +func NullableString(s StringNullWhenEmpty) *StringNullWhenEmpty { return &s } + // StringNullWhenEmpty is a string type that marshals its JSON representation as null when set to its zero value. // Can be used with a pointer reference with the `omitempty` tag to omit a field when the pointer is nil, but send a // JSON null value when the string is empty. @@ -60,6 +63,13 @@ const ( AccessPackageResourceTypeSharePointOnlineSite AccessPackageResourceType = "SharePoint Online Site" ) +type AdministrativeUnitVisibility = string + +const ( + AdministrativeUnitVisibilityHiddenMembership AdministrativeUnitVisibility = "HiddenMembership" + AdministrativeUnitVisibilityPublic AdministrativeUnitVisibility = "Public" +) + type AgeGroup = StringNullWhenEmpty const ( @@ -191,6 +201,71 @@ const ( CredentialUsageSummaryPeriod1 CredentialUsageSummaryPeriod = "D1" ) +type ConditionalAccessClientAppType = string + +const ( + ConditionalAccessClientAppTypeAll ConditionalAccessClientAppType = "all" + ConditionalAccessClientAppTypeBrowser ConditionalAccessClientAppType = "browser" + ConditionalAccessClientAppTypeEasSupported ConditionalAccessClientAppType = "easSupported" + ConditionalAccessClientAppTypeExchangeActiveSync ConditionalAccessClientAppType = "exchangeActiveSync" + ConditionalAccessClientAppTypeMobileAppsAndDesktopClients ConditionalAccessClientAppType = "mobileAppsAndDesktopClients" + ConditionalAccessClientAppTypeOther ConditionalAccessClientAppType = "other" +) + +type ConditionalAccessCloudAppSecuritySessionControlType = string + +const ( + ConditionalAccessCloudAppSecuritySessionControlTypeBlockDownloads ConditionalAccessCloudAppSecuritySessionControlType = "blockDownloads" + ConditionalAccessCloudAppSecuritySessionControlTypeMcasConfigured ConditionalAccessCloudAppSecuritySessionControlType = "mcasConfigured" + ConditionalAccessCloudAppSecuritySessionControlTypeMonitorOnly ConditionalAccessCloudAppSecuritySessionControlType = "monitorOnly" + ConditionalAccessCloudAppSecuritySessionControlTypeUnknownFutureValue ConditionalAccessCloudAppSecuritySessionControlType = "unknownFutureValue" +) + +type ConditionalAccessDevicePlatform = string + +const ( + ConditionalAccessDevicePlatformAll ConditionalAccessDevicePlatform = "all" + ConditionalAccessDevicePlatformAndroid ConditionalAccessDevicePlatform = "android" + ConditionalAccessDevicePlatformIos ConditionalAccessDevicePlatform = "iOS" + ConditionalAccessDevicePlatformMacOs ConditionalAccessDevicePlatform = "macOS" + ConditionalAccessDevicePlatformUnknownFutureValue ConditionalAccessDevicePlatform = "unknownFutureValue" + ConditionalAccessDevicePlatformWindows ConditionalAccessDevicePlatform = "windows" + ConditionalAccessDevicePlatformWindowsPhone ConditionalAccessDevicePlatform = "windowsPhone" +) + +type ConditionalAccessDeviceStatesInclude = string + +const ( + ConditionalAccessDeviceStatesIncludeAll ConditionalAccessDeviceStatesInclude = "All" +) + +type ConditionalAccessDeviceStatesExclude = string + +const ( + ConditionalAccessDeviceStatesExcludeCompliant ConditionalAccessDeviceStatesExclude = "Compliant" + ConditionalAccessDeviceStatesExcludeDomainJoined ConditionalAccessDeviceStatesExclude = "DomainJoined" +) + +type ConditionalAccessFilterMode = string + +const ( + ConditionalAccessFilterModeExclude ConditionalAccessFilterMode = "exclude" + ConditionalAccessFilterModeInclude ConditionalAccessFilterMode = "include" +) + +type ConditionalAccessGrantControl = string + +const ( + ConditionalAccessGrantControlApprovedApplication ConditionalAccessGrantControl = "approvedApplication" + ConditionalAccessGrantControlBlock ConditionalAccessGrantControl = "block" + ConditionalAccessGrantControlCompliantApplication ConditionalAccessGrantControl = "compliantApplication" + ConditionalAccessGrantControlCompliantDevice ConditionalAccessGrantControl = "compliantDevice" + ConditionalAccessGrantControlDomainJoinedDevice ConditionalAccessGrantControl = "domainJoinedDevice" + ConditionalAccessGrantControlMfa ConditionalAccessGrantControl = "mfa" + ConditionalAccessGrantControlPasswordChange ConditionalAccessGrantControl = "passwordChange" + ConditionalAccessGrantControlUnknownFutureValue ConditionalAccessGrantControl = "unknownFutureValue" +) + type ConditionalAccessPolicyState = string const ( @@ -199,6 +274,24 @@ const ( ConditionalAccessPolicyStateEnabledForReportingButNotEnforced ConditionalAccessPolicyState = "enabledForReportingButNotEnforced" ) +type ConditionalAccessRiskLevel = string + +const ( + ConditionalAccessRiskLevelHidden ConditionalAccessRiskLevel = "hidden" + ConditionalAccessRiskLevelHigh ConditionalAccessRiskLevel = "high" + ConditionalAccessRiskLevelLow ConditionalAccessRiskLevel = "low" + ConditionalAccessRiskLevelMedium ConditionalAccessRiskLevel = "medium" + ConditionalAccessRiskLevelNone ConditionalAccessRiskLevel = "none" + ConditionalAccessRiskLevelUnknownFutureValue ConditionalAccessRiskLevel = "unknownFutureValue" +) + +type DelegatedPermissionGrantConsentType = string + +const ( + DelegatedPermissionGrantConsentTypeAllPrincipals DelegatedPermissionGrantConsentType = "AllPrincipals" + DelegatedPermissionGrantConsentTypePrincipal DelegatedPermissionGrantConsentType = "Principal" +) + type ExtensionSchemaTargetType = string const ( @@ -369,6 +462,13 @@ const ( PermissionScopeTypeUser PermissionScopeType = "User" ) +type PersistentBrowserSessionMode = string + +const ( + PersistentBrowserSessionModeAlways PersistentBrowserSessionMode = "always" + PersistentBrowserSessionModeNever PersistentBrowserSessionMode = "never" +) + type PreferredSingleSignOnMode = StringNullWhenEmpty const ( diff --git a/vendor/modules.txt b/vendor/modules.txt index ecf740329740..eb0c199ed056 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -188,11 +188,10 @@ github.com/google/uuid # github.com/hashicorp/errwrap v1.1.0 ## explicit github.com/hashicorp/errwrap -# github.com/hashicorp/go-azure-helpers v0.19.1 +# github.com/hashicorp/go-azure-helpers v0.21.0 ## explicit github.com/hashicorp/go-azure-helpers/authentication github.com/hashicorp/go-azure-helpers/lang/dates -github.com/hashicorp/go-azure-helpers/lang/pointer github.com/hashicorp/go-azure-helpers/lang/response github.com/hashicorp/go-azure-helpers/polling github.com/hashicorp/go-azure-helpers/resourcemanager/commonids @@ -309,7 +308,7 @@ github.com/hashicorp/terraform-svchost github.com/hashicorp/yamux # github.com/klauspost/compress v1.13.1 ## explicit -# github.com/manicminer/hamilton v0.35.0 +# github.com/manicminer/hamilton v0.37.0 github.com/manicminer/hamilton/auth github.com/manicminer/hamilton/environments github.com/manicminer/hamilton/errors