From e18c82c13f827ef1595b3c3b105ce2d8e0cb725a Mon Sep 17 00:00:00 2001 From: kt Date: Thu, 14 Nov 2024 11:40:54 -0800 Subject: [PATCH 1/7] FourPointOh - remove from services A-I with low find counts --- .../analysis_services_server_resource.go | 49 +- .../appservice/validate/app_settings.go | 16 +- .../attestation_provider_resource.go | 28 - .../automation_certificate_resource.go | 8 - .../automation_job_schedule_resource.go | 3 +- .../services/batch/batch_account_resource.go | 19 - .../services/batch/batch_pool_resource.go | 40 -- .../cdn_frontdoor_rule_actions.go | 56 +- .../connections/api_connection_resource.go | 10 - .../container_app_job_resource.go | 48 +- .../container_app_job_resource_test.go | 117 ---- .../helpers/container_app_environment.go | 11 - .../containerapps/helpers/container_apps.go | 97 ++- .../cosmos/cosmosdb_account_resource_test.go | 330 +--------- .../cosmosdb_cassandra_datacenter_resource.go | 20 - ...osdb_cassandra_datacenter_resource_test.go | 82 +-- .../cosmosdb_notebook_workspace_resource.go | 152 ----- ...smosdb_notebook_workspace_resource_test.go | 123 ---- internal/services/cosmos/registration.go | 5 - .../services/databoxedge/customizediff.go | 25 - .../databox_edge_order_resource.go | 587 ------------------ .../databox_edge_order_resource_test.go | 196 ------ internal/services/databoxedge/registration.go | 6 - ...atabricks_customer_managed_key_resource.go | 299 --------- ...icks_customer_managed_key_resource_test.go | 302 --------- .../databricks_workspace_resource.go | 13 - internal/services/databricks/registration.go | 5 - ...tory_integration_runtime_azure_resource.go | 32 +- internal/services/iothub/iothub_resource.go | 57 +- 29 files changed, 107 insertions(+), 2629 deletions(-) delete mode 100644 internal/services/cosmos/cosmosdb_notebook_workspace_resource.go delete mode 100644 internal/services/cosmos/cosmosdb_notebook_workspace_resource_test.go delete mode 100644 internal/services/databoxedge/customizediff.go delete mode 100644 internal/services/databoxedge/databox_edge_order_resource.go delete mode 100644 internal/services/databoxedge/databox_edge_order_resource_test.go delete mode 100644 internal/services/databricks/databricks_customer_managed_key_resource.go delete mode 100644 internal/services/databricks/databricks_customer_managed_key_resource_test.go diff --git a/internal/services/analysisservices/analysis_services_server_resource.go b/internal/services/analysisservices/analysis_services_server_resource.go index 68b328649c1b..c8635d6c605c 100644 --- a/internal/services/analysisservices/analysis_services_server_resource.go +++ b/internal/services/analysisservices/analysis_services_server_resource.go @@ -19,7 +19,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/analysisservices/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -86,13 +85,6 @@ func resourceAnalysisServicesServer() *pluginsdk.Resource { "power_bi_service_enabled": { Type: pluginsdk.TypeBool, Optional: true, - Computed: !features.FourPointOhBeta(), - ConflictsWith: func() []string { - if !features.FourPointOhBeta() { - return []string{"enable_power_bi_service"} - } - return []string{} - }(), }, "ipv4_firewall_rule": { @@ -144,24 +136,7 @@ func resourceAnalysisServicesServer() *pluginsdk.Resource { "tags": commonschema.Tags(), }, } - if !features.FourPointOhBeta() { - resource.Schema["querypool_connection_mode"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringInSlice([]string{ - string(servers.ConnectionModeAll), - string(servers.ConnectionModeReadOnly), - }, false), - } - resource.Schema["enable_power_bi_service"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - Deprecated: "The property `enable_power_bi_service` has been superseded by `power_bi_service_enabled` and will be removed in v4.0 of the AzureRM Provider.", - ConflictsWith: []string{"power_bi_service_enabled"}, - } - } + return resource } @@ -198,14 +173,6 @@ func resourceAnalysisServicesServerCreate(d *pluginsdk.ResourceData, meta interf Tags: tags.Expand(d.Get("tags").(map[string]interface{})), } - if v, ok := d.GetOk("enable_power_bi_service"); ok && !features.FourPointOhBeta() { - if analysisServicesServer.Properties.IPV4FirewallSettings == nil { - analysisServicesServer.Properties.IPV4FirewallSettings = &servers.IPv4FirewallSettings{ - FirewallRules: pointer.To(make([]servers.IPv4FirewallRule, 0)), - } - } - analysisServicesServer.Properties.IPV4FirewallSettings.EnablePowerBIService = pointer.To(v.(bool)) - } if v, ok := d.GetOk("power_bi_service_enabled"); ok { if analysisServicesServer.Properties.IPV4FirewallSettings == nil { analysisServicesServer.Properties.IPV4FirewallSettings = &servers.IPv4FirewallSettings{ @@ -266,9 +233,6 @@ func resourceAnalysisServicesServerRead(d *pluginsdk.ResourceData, meta interfac d.Set("admin_users", adminUsers) enablePowerBi, fwRules := flattenAnalysisServicesServerFirewallSettings(props) - if !features.FourPointOhBeta() { - d.Set("enable_power_bi_service", enablePowerBi) - } d.Set("power_bi_service_enabled", enablePowerBi) if err := d.Set("ipv4_firewall_rule", fwRules); err != nil { return fmt.Errorf("setting `ipv4_firewall_rule`: %s", err) @@ -352,17 +316,6 @@ func resourceAnalysisServicesServerUpdate(d *pluginsdk.ResourceData, meta interf analysisServicesServer.Properties.IPV4FirewallSettings.EnablePowerBIService = pointer.To(d.Get("power_bi_service_enabled").(bool)) } - if !features.FourPointOhBeta() { - if d.HasChange("enable_power_bi_service") { - if analysisServicesServer.Properties.IPV4FirewallSettings == nil { - analysisServicesServer.Properties.IPV4FirewallSettings = &servers.IPv4FirewallSettings{ - FirewallRules: pointer.To(make([]servers.IPv4FirewallRule, 0)), - } - } - analysisServicesServer.Properties.IPV4FirewallSettings.EnablePowerBIService = pointer.To(d.Get("enable_power_bi_service").(bool)) - } - } - if containerUri, ok := d.GetOk("backup_blob_container_uri"); ok { analysisServicesServer.Properties.BackupBlobContainerUri = pointer.To(containerUri.(string)) } diff --git a/internal/services/appservice/validate/app_settings.go b/internal/services/appservice/validate/app_settings.go index 84bc2644c633..5e58ed3780fb 100644 --- a/internal/services/appservice/validate/app_settings.go +++ b/internal/services/appservice/validate/app_settings.go @@ -6,8 +6,6 @@ package validate import ( "fmt" "strings" - - "github.com/hashicorp/terraform-provider-azurerm/internal/features" ) var UnmanagedSettings = []string{ @@ -40,17 +38,9 @@ var UnmanagedSettingsDeprecated = []string{ func AppSettings(input interface{}, key string) (warnings []string, errors []error) { if appSettings, ok := input.(map[string]interface{}); ok { for k := range appSettings { - if !features.FourPointOhBeta() { - for _, f := range UnmanagedSettingsDeprecated { - if strings.EqualFold(k, f) { - errors = append(errors, fmt.Errorf("cannot set a value for %s in %s", k, key)) - } - } - } else { - for _, f := range UnmanagedSettings { - if strings.EqualFold(k, f) { - errors = append(errors, fmt.Errorf("cannot set a value for %s in %s", k, key)) - } + for _, f := range UnmanagedSettings { + if strings.EqualFold(k, f) { + errors = append(errors, fmt.Errorf("cannot set a value for %s in %s", k, key)) } } } diff --git a/internal/services/attestation/attestation_provider_resource.go b/internal/services/attestation/attestation_provider_resource.go index bfcaf8234178..9bbfbbd47d4c 100644 --- a/internal/services/attestation/attestation_provider_resource.go +++ b/internal/services/attestation/attestation_provider_resource.go @@ -22,7 +22,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" @@ -126,27 +125,6 @@ func resourceAttestationProvider() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - s["policy"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - Deprecated: "This field is no longer used and will be removed in v4.0 of the Azure Provider - use `open_enclave_policy_base64`, `sgx_enclave_policy_base64`, `tpm_policy_base64` and `sev_snp_policy_base64` instead.", - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "environment_type": { - Type: pluginsdk.TypeString, - Optional: true, - }, - - "data": { - Type: pluginsdk.TypeString, - Optional: true, - }, - }, - }, - } - } - return s }(), } @@ -315,12 +293,6 @@ func resourceAttestationProviderRead(d *pluginsdk.ResourceData, meta interface{} } d.Set("sev_snp_policy_base64", pointer.From(sevSnpPolicyData)) - if !features.FourPointOhBeta() { - if err := d.Set("policy", []interface{}{}); err != nil { - return fmt.Errorf("setting `policy`: %+v", err) - } - } - return nil } diff --git a/internal/services/automation/automation_certificate_resource.go b/internal/services/automation/automation_certificate_resource.go index 99b13338bb31..6e537d05cc40 100644 --- a/internal/services/automation/automation_certificate_resource.go +++ b/internal/services/automation/automation_certificate_resource.go @@ -13,7 +13,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2023-11-01/certificate" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "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" @@ -81,13 +80,6 @@ func resourceAutomationCertificate() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - resource.Schema["exportable"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Computed: true, - Optional: true, - } - } return resource } diff --git a/internal/services/automation/automation_job_schedule_resource.go b/internal/services/automation/automation_job_schedule_resource.go index b0558c050598..ef7ebcdd10e4 100644 --- a/internal/services/automation/automation_job_schedule_resource.go +++ b/internal/services/automation/automation_job_schedule_resource.go @@ -20,7 +20,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/automation/2023-11-01/schedule" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/migration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -95,7 +94,7 @@ func resourceAutomationJobSchedule() *pluginsdk.Resource { Optional: true, // NOTE: O+C this can remain as this can change if the runbook is updated but cannot be updated by the user Computed: true, - ForceNew: features.FourPointOhBeta(), + ForceNew: true, ValidateFunc: validation.IsUUID, }, diff --git a/internal/services/batch/batch_account_resource.go b/internal/services/batch/batch_account_resource.go index a9815fa71bea..e57117361d38 100644 --- a/internal/services/batch/batch_account_resource.go +++ b/internal/services/batch/batch_account_resource.go @@ -19,7 +19,6 @@ import ( "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/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/batch/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -186,24 +185,6 @@ func resourceBatchAccount() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - resource.Schema["encryption"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - ConfigMode: pluginsdk.SchemaConfigModeAttr, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "key_vault_key_id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: keyVaultValidate.NestedItemIdWithOptionalVersion, - }, - }, - }, - } - } - return resource } diff --git a/internal/services/batch/batch_pool_resource.go b/internal/services/batch/batch_pool_resource.go index fd700398c76e..bfe3bbf4ec24 100644 --- a/internal/services/batch/batch_pool_resource.go +++ b/internal/services/batch/batch_pool_resource.go @@ -22,7 +22,6 @@ import ( "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/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/batch/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/suppress" @@ -829,45 +828,6 @@ func resourceBatchPool() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - resource.Schema["container_configuration"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "type": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.StringIsNotEmpty, - AtLeastOneOf: []string{"container_configuration.0.type", "container_configuration.0.container_image_names", "container_configuration.0.container_registries"}, - }, - "container_image_names": { - Type: pluginsdk.TypeSet, - Optional: true, - ForceNew: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - ValidateFunc: validation.StringIsNotEmpty, - }, - AtLeastOneOf: []string{"container_configuration.0.type", "container_configuration.0.container_image_names", "container_configuration.0.container_registries"}, - }, - "container_registries": { - Type: pluginsdk.TypeList, - Optional: true, - ForceNew: true, - ConfigMode: pluginsdk.SchemaConfigModeAttr, - Elem: &pluginsdk.Resource{ - Schema: containerRegistry(), - }, - AtLeastOneOf: []string{"container_configuration.0.type", "container_configuration.0.container_image_names", "container_configuration.0.container_registries"}, - }, - }, - }, - } - } - return resource } diff --git a/internal/services/cdn/frontdoorruleactions/cdn_frontdoor_rule_actions.go b/internal/services/cdn/frontdoorruleactions/cdn_frontdoor_rule_actions.go index 5dd246592687..77d289b62cc4 100644 --- a/internal/services/cdn/frontdoorruleactions/cdn_frontdoor_rule_actions.go +++ b/internal/services/cdn/frontdoorruleactions/cdn_frontdoor_rule_actions.go @@ -8,7 +8,7 @@ import ( "strings" "github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2021-06-01/cdn" // nolint: staticcheck - "github.com/hashicorp/terraform-provider-azurerm/internal/features" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -231,13 +231,6 @@ func ExpandCdnFrontDoorRouteConfigurationOverrideAction(input []interface{}) (*[ compressionEnabled = cdn.RuleIsCompressionEnabledDisabled } - if !features.FourPointOhBeta() { - // set the default value for forwarding protocol to avoid a breaking change... - if protocol == "" { - protocol = string(cdn.ForwardingProtocolMatchRequest) - } - } - // NOTE: It is valid to not define the originGroupOverride in the Route Configuration Override Action // however, if you do not define the Origin Group ID you also cannot define the Forwarding Protocol either if originGroupIdRaw != "" { @@ -247,7 +240,7 @@ func ExpandCdnFrontDoorRouteConfigurationOverrideAction(input []interface{}) (*[ originGroupOverride = cdn.OriginGroupOverride{ OriginGroup: &cdn.ResourceReference{ - ID: utils.String(originGroupIdRaw), + ID: pointer.To(originGroupIdRaw), }, ForwardingProtocol: cdn.ForwardingProtocol(protocol), } @@ -268,44 +261,21 @@ func ExpandCdnFrontDoorRouteConfigurationOverrideAction(input []interface{}) (*[ return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, if the 'cache_behavior' is set to 'Disabled' you cannot define the 'cache_duration', got %q", cacheDuration) } } else { - if !features.FourPointOhBeta() { - // since 'cache_duration', 'query_string_caching_behavior' and 'cache_behavior' are optional create a default values - // for those values if not set. - if cacheBehavior == "" { - cacheBehavior = string(cdn.RuleCacheBehaviorHonorOrigin) - } - - if queryStringCachingBehavior == "" { - queryStringCachingBehavior = string(cdn.RuleQueryStringCachingBehaviorIgnoreQueryString) - } - - // NOTE: if the cacheBehavior is 'HonorOrigin' the cacheDuration must be null, issue #19311 - if cacheBehavior != string(cdn.RuleCacheBehaviorHonorOrigin) { - if cacheDuration == "" { - cacheDuration = "1.12:00:00" - } - } else if cacheDuration != "" { - return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, if the 'cache_behavior' field is set to 'HonorOrigin' the 'cache_duration' must not be set") - } + if cacheBehavior == "" { + return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_behavior' field must be set") } - if features.FourPointOhBeta() { - if cacheBehavior == "" { - return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_behavior' field must be set") - } - - if queryStringCachingBehavior == "" { - return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'query_string_caching_behavior' field must be set") - } + if queryStringCachingBehavior == "" { + return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'query_string_caching_behavior' field must be set") + } - // NOTE: if the cacheBehavior is 'HonorOrigin' cacheDuration must be null, issue #19311 - if cacheBehavior != string(cdn.RuleCacheBehaviorHonorOrigin) { - if cacheDuration == "" { - return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_duration' field must be set") - } - } else if cacheDuration != "" { - return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_duration' field must not be set if the 'cache_behavior' is 'HonorOrigin'") + // NOTE: if the cacheBehavior is 'HonorOrigin' cacheDuration must be null, issue #19311 + if cacheBehavior != string(cdn.RuleCacheBehaviorHonorOrigin) { + if cacheDuration == "" { + return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_duration' field must be set") } + } else if cacheDuration != "" { + return nil, fmt.Errorf("the 'route_configuration_override_action' block is not valid, the 'cache_duration' field must not be set if the 'cache_behavior' is 'HonorOrigin'") } cacheConfiguration = cdn.CacheConfiguration{ diff --git a/internal/services/connections/api_connection_resource.go b/internal/services/connections/api_connection_resource.go index 9d98ad265738..5e6f1068c89a 100644 --- a/internal/services/connections/api_connection_resource.go +++ b/internal/services/connections/api_connection_resource.go @@ -17,7 +17,6 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "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" @@ -92,15 +91,6 @@ func resourceConnection() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - resource.Schema["display_name"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - } - } - return resource } diff --git a/internal/services/containerapps/container_app_job_resource.go b/internal/services/containerapps/container_app_job_resource.go index 7b4fa4ee12da..6d5b73f24ab3 100644 --- a/internal/services/containerapps/container_app_job_resource.go +++ b/internal/services/containerapps/container_app_job_resource.go @@ -19,7 +19,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2023-05-01/managedenvironmentsstorages" "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2024-02-02-preview/jobs" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/helpers" "github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/validate" @@ -205,22 +204,6 @@ func (r ContainerAppJobResource) Arguments() map[string]*schema.Schema { "tags": commonschema.Tags(), } - if !features.FourPointOhBeta() { - schema["secrets"] = helpers.SecretsSchema() - schema["secrets"].ConflictsWith = []string{"secret"} - schema["secrets"].Computed = true - schema["secrets"].Deprecated = "`secrets` has been renamed to `secret` and will be removed in version 4.0 of the AzureRM Provider." - schema["secret"].ConflictsWith = []string{"secrets"} - schema["secret"].Computed = true - - schema["registries"] = helpers.ContainerAppRegistrySchema() - schema["registries"].ConflictsWith = []string{"registry"} - schema["registries"].Computed = true - schema["registries"].Deprecated = "`registries` has been renamed to `registry` and will be removed in version 4.0 of the AzureRM Provider." - schema["registry"].ConflictsWith = []string{"registries"} - schema["registry"].Computed = true - } - return schema } @@ -271,17 +254,6 @@ func (r ContainerAppJobResource) Create() sdk.ResourceFunc { if err != nil { return fmt.Errorf("expanding registry config for %s: %v", id, err) } - if !features.FourPointOhBeta() && len(model.RegistriesDeprecated) > 0 { - registries, err = helpers.ExpandContainerAppJobRegistries(model.RegistriesDeprecated) - if err != nil { - return fmt.Errorf("expanding registry config for %s: %v", id, err) - } - } - - secrets := helpers.ExpandContainerAppJobSecrets(model.Secrets) - if !features.FourPointOhBeta() && len(model.SecretsDeprecated) > 0 { - secrets = helpers.ExpandContainerAppJobSecrets(model.SecretsDeprecated) - } job := jobs.Job{ Location: location.Normalize(model.Location), @@ -289,7 +261,7 @@ func (r ContainerAppJobResource) Create() sdk.ResourceFunc { Configuration: &jobs.JobConfiguration{ ReplicaRetryLimit: pointer.To(model.ReplicaRetryLimit), ReplicaTimeout: model.ReplicaTimeoutInSeconds, - Secrets: secrets, + Secrets: helpers.ExpandContainerAppJobSecrets(model.Secrets), Registries: registries, }, EnvironmentId: pointer.To(model.ContainerAppEnvironmentId), @@ -380,9 +352,6 @@ func (r ContainerAppJobResource) Read() sdk.ResourceFunc { state.Template = helpers.FlattenContainerAppJobTemplate(props.Template) if config := props.Configuration; config != nil { state.Registries = helpers.FlattenContainerAppJobRegistries(config.Registries) - if !features.FourPointOhBeta() { - state.RegistriesDeprecated = helpers.FlattenContainerAppJobRegistries(config.Registries) - } state.ReplicaTimeoutInSeconds = config.ReplicaTimeout if config.ReplicaRetryLimit != nil { state.ReplicaRetryLimit = pointer.From(config.ReplicaRetryLimit) @@ -406,9 +375,6 @@ func (r ContainerAppJobResource) Read() sdk.ResourceFunc { return fmt.Errorf("listing secrets for %s: %+v", *id, err) } state.Secrets = helpers.FlattenContainerAppJobSecrets(secretResp.Model) - if !features.FourPointOhBeta() { - state.SecretsDeprecated = helpers.FlattenContainerAppJobSecrets(secretResp.Model) - } return metadata.Encode(&state) }, @@ -503,18 +469,6 @@ func (r ContainerAppJobResource) Update() sdk.ResourceFunc { model.Tags = tags.Expand(state.Tags) } - if !features.FourPointOhBeta() { - if d.HasChange("secrets") { - model.Properties.Configuration.Secrets = helpers.ExpandContainerAppJobSecrets(state.SecretsDeprecated) - } - if d.HasChange("registries") { - model.Properties.Configuration.Registries, err = helpers.ExpandContainerAppJobRegistries(state.RegistriesDeprecated) - if err != nil { - return fmt.Errorf("invalid registry config for %s: %v", id, err) - } - } - } - model.Properties.Template = helpers.ExpandContainerAppJobTemplate(state.Template) if err := client.CreateOrUpdateThenPoll(ctx, *id, *model); err != nil { diff --git a/internal/services/containerapps/container_app_job_resource_test.go b/internal/services/containerapps/container_app_job_resource_test.go index f9e3af455a76..f0a224f0c9ac 100644 --- a/internal/services/containerapps/container_app_job_resource_test.go +++ b/internal/services/containerapps/container_app_job_resource_test.go @@ -14,7 +14,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -201,24 +200,6 @@ func TestAccContainerAppJob_complete(t *testing.T) { }) } -func TestAccContainerAppJob_completeDeprecated(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("Skipped as `secrets` and `registries` removed in 4.0") - } - data := acceptance.BuildTestData(t, "azurerm_container_app_job", "test") - r := ContainerAppJobResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.completeDeprecated(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }) -} - func TestAccContainerAppJob_completeUpdate(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_container_app_job", "test") r := ContainerAppJobResource{} @@ -1331,104 +1312,6 @@ resource "azurerm_container_app_job" "test" { `, ContainerAppResource{}.templatePlusExtras(data), data.RandomInteger) } -func (r ContainerAppJobResource) completeDeprecated(data acceptance.TestData) string { - return fmt.Sprintf(` - -%[1]s - -resource "azurerm_container_app_job" "test" { - name = "acctest-cajob%[2]d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - container_app_environment_id = azurerm_container_app_environment.test.id - - identity { - type = "SystemAssigned" - } - - replica_timeout_in_seconds = 10 - replica_retry_limit = 10 - manual_trigger_config { - parallelism = 4 - replica_completion_count = 1 - } - secrets { - name = "registry-password" - value = azurerm_container_registry.test.admin_password - } - registries { - server = azurerm_container_registry.test.login_server - username = azurerm_container_registry.test.admin_username - password_secret_name = "registry-password" - } - - template { - volume { - name = azurerm_container_app_environment_storage.test.name - storage_type = "AzureFile" - storage_name = azurerm_container_app_environment_storage.test.name - } - container { - args = [ - "-c", - "while true; do echo hello; sleep 10;done", - ] - command = [ - "/bin/sh", - ] - image = "jackofallops/azure-containerapps-python-acctest:v0.0.1" - name = "testcontainerappsjob0" - readiness_probe { - transport = "HTTP" - port = 5000 - } - - liveness_probe { - transport = "HTTP" - port = 5000 - path = "/health" - - header { - name = "Cache-Control" - value = "no-cache" - } - - initial_delay = 5 - interval_seconds = 20 - timeout = 2 - failure_count_threshold = 1 - } - startup_probe { - transport = "TCP" - port = 5000 - } - - cpu = 0.5 - memory = "1Gi" - volume_mounts { - path = "/appsettings" - name = azurerm_container_app_environment_storage.test.name - } - } - - init_container { - name = "init-cont-%[2]d" - image = "jackofallops/azure-containerapps-python-acctest:v0.0.1" - cpu = 0.25 - memory = "0.5Gi" - volume_mounts { - name = azurerm_container_app_environment_storage.test.name - path = "/appsettings" - } - } - } - tags = { - ENV = "test" - } -} -`, ContainerAppResource{}.templatePlusExtras(data), data.RandomInteger) -} - func (r ContainerAppJobResource) completeUpdate(data acceptance.TestData) string { return fmt.Sprintf(` diff --git a/internal/services/containerapps/helpers/container_app_environment.go b/internal/services/containerapps/helpers/container_app_environment.go index f54028ad6d23..0cdc0546262d 100644 --- a/internal/services/containerapps/helpers/container_app_environment.go +++ b/internal/services/containerapps/helpers/container_app_environment.go @@ -8,7 +8,6 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2024-03-01/managedenvironments" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" ) @@ -88,8 +87,6 @@ func ExpandWorkloadProfiles(input []WorkloadProfileModel) *[]managedenvironments result := make([]managedenvironments.WorkloadProfile, 0) - consumptionDefined := false - for _, v := range input { r := managedenvironments.WorkloadProfile{ Name: v.Name, @@ -101,19 +98,11 @@ func ExpandWorkloadProfiles(input []WorkloadProfileModel) *[]managedenvironments r.MinimumCount = pointer.To(v.MinimumCount) } else { r.WorkloadProfileType = string(WorkloadProfileSkuConsumption) - consumptionDefined = true } result = append(result, r) } - if !features.FourPointOhBeta() && !consumptionDefined { - result = append(result, managedenvironments.WorkloadProfile{ - Name: string(WorkloadProfileSkuConsumption), - WorkloadProfileType: string(WorkloadProfileSkuConsumption), - }) - } - return &result } diff --git a/internal/services/containerapps/helpers/container_apps.go b/internal/services/containerapps/helpers/container_apps.go index fccd421070eb..10d1e1337a11 100644 --- a/internal/services/containerapps/helpers/container_apps.go +++ b/internal/services/containerapps/helpers/container_apps.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2023-05-01/containerapps" "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2023-05-01/daprcomponents" "github.com/hashicorp/go-azure-sdk/resource-manager/containerapps/2024-03-01/managedenvironments" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/services/containerapps/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" @@ -162,68 +161,62 @@ type Ingress struct { } func ContainerAppIngressSchema() *pluginsdk.Schema { - r := &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "allow_insecure_connections": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - Description: "Should this ingress allow insecure connections?", - }, + return &pluginsdk.Schema{ + Type: pluginsdk.TypeList, + Optional: true, + MaxItems: 1, + Elem: &pluginsdk.Resource{ + Schema: map[string]*pluginsdk.Schema{ + "allow_insecure_connections": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + Description: "Should this ingress allow insecure connections?", + }, - "external_enabled": { - Type: pluginsdk.TypeBool, - Optional: true, - Default: false, - Description: "Is this an external Ingress.", - }, + "external_enabled": { + Type: pluginsdk.TypeBool, + Optional: true, + Default: false, + Description: "Is this an external Ingress.", + }, - "custom_domain": ContainerAppIngressCustomDomainSchemaComputed(), + "custom_domain": ContainerAppIngressCustomDomainSchemaComputed(), - "fqdn": { - Type: pluginsdk.TypeString, - Computed: true, - Description: "The FQDN of the ingress.", - }, + "fqdn": { + Type: pluginsdk.TypeString, + Computed: true, + Description: "The FQDN of the ingress.", + }, - "ip_security_restriction": ContainerAppIngressIpSecurityRestriction(), + "ip_security_restriction": ContainerAppIngressIpSecurityRestriction(), - "target_port": { - Type: pluginsdk.TypeInt, - Required: true, - ValidateFunc: validation.IntBetween(1, 65535), - Description: "The target port on the container for the Ingress traffic.", - }, + "target_port": { + Type: pluginsdk.TypeInt, + Required: true, + ValidateFunc: validation.IntBetween(1, 65535), + Description: "The target port on the container for the Ingress traffic.", + }, - "exposed_port": { - Type: pluginsdk.TypeInt, - Optional: true, - ValidateFunc: validation.IntBetween(1, 65535), - Description: "The exposed port on the container for the Ingress traffic.", - }, + "exposed_port": { + Type: pluginsdk.TypeInt, + Optional: true, + ValidateFunc: validation.IntBetween(1, 65535), + Description: "The exposed port on the container for the Ingress traffic.", + }, - "traffic_weight": ContainerAppIngressTrafficWeight(), + "traffic_weight": ContainerAppIngressTrafficWeight(), - "transport": { - Type: pluginsdk.TypeString, - Optional: true, - Default: string(containerapps.IngressTransportMethodAuto), - ValidateFunc: validation.StringInSlice(containerapps.PossibleValuesForIngressTransportMethod(), false), - Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`, `tcp`. Defaults to `auto`", + "transport": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(containerapps.IngressTransportMethodAuto), + ValidateFunc: validation.StringInSlice(containerapps.PossibleValuesForIngressTransportMethod(), false), + Description: "The transport method for the Ingress. Possible values include `auto`, `http`, and `http2`, `tcp`. Defaults to `auto`", + }, }, }, } - - if !features.FourPointOhBeta() { - r.Schema["custom_domain"] = ContainerAppIngressCustomDomainSchema() - } - - return &pluginsdk.Schema{ - Type: pluginsdk.TypeList, - Optional: true, - MaxItems: 1, - Elem: r, - } } func ContainerAppIngressSchemaComputed() *pluginsdk.Schema { diff --git a/internal/services/cosmos/cosmosdb_account_resource_test.go b/internal/services/cosmos/cosmosdb_account_resource_test.go index 3f26cd7d2126..f47f04c1e858 100644 --- a/internal/services/cosmos/cosmosdb_account_resource_test.go +++ b/internal/services/cosmos/cosmosdb_account_resource_test.go @@ -11,16 +11,15 @@ import ( "strconv" "testing" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-sdk/resource-manager/cosmosdb/2024-08-15/cosmosdb" "github.com/hashicorp/go-uuid" "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) type CosmosDBAccountResource struct{} @@ -967,9 +966,6 @@ func TestAccCosmosDBAccount_updateCapacity(t *testing.T) { } func TestAccCosmosDBAccount_vNetFilters(t *testing.T) { - if !features.FourPointOhBeta() { - t.Skip("this test requires 4.0 mode") - } data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -986,27 +982,6 @@ func TestAccCosmosDBAccount_vNetFilters(t *testing.T) { }) } -// TODO 4.0 remove post 4.0 -func TestAccCosmosDBAccount_vNetFiltersThreePointOh(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("this test requires 3.0 mode") - } - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") - r := CosmosDBAccountResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.vNetFiltersThreePointOh(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("is_virtual_network_filter_enabled").HasValue("true"), - check.That(data.ResourceName).Key("virtual_network_rule.#").HasValue("2"), - ), - }, - data.ImportStep(), - }) -} - func TestAccCosmosDBAccount_identity(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -1449,92 +1424,7 @@ func TestAccCosmosDBAccount_gremlinDatabasesToRestore(t *testing.T) { }) } -// TODO 4.0 remove post 4.0 -func TestAccCosmosDBAccount_ipRangeFiltersThreePointOh(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("this test requires 3.0 mode") - } - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") - r := CosmosDBAccountResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.ipRangeFiltersThreePointOh(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.ipRangeFiltersUpdatedThreePointOh(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - { - Config: r.vNetFiltersThreePointOh(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }) -} - -func TestAccCosmosDBAccount_supersededProperties(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("this test contains deprecated properties and can be removed post 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") - // Limited regional availability - data.Locations.Primary = "westeurope" - data.Locations.Secondary = "northeurope" - r := CosmosDBAccountResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basicMongoDB(data, cosmosdb.DefaultConsistencyLevelEventual), - Check: acceptance.ComposeAggregateTestCheckFunc( - checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 1), - ), - }, - data.ImportStep(), - { - Config: r.supersededProperties(data, cosmosdb.DefaultConsistencyLevelEventual), - Check: acceptance.ComposeAggregateTestCheckFunc( - checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 2), - ), - }, - data.ImportStep(), - }) -} - -func TestAccCosmosDBAccount_supersededFreeTier(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("this test contains deprecated properties and can be removed post 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") - r := CosmosDBAccountResource{} - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.supersededFreeTier(data, "GlobalDocumentDB", cosmosdb.DefaultConsistencyLevelEventual), - Check: acceptance.ComposeAggregateTestCheckFunc( - checkAccCosmosDBAccount_basic(data, cosmosdb.DefaultConsistencyLevelEventual, 1), - check.That(data.ResourceName).Key("enable_free_tier").HasValue("true"), - ), - }, - data.ImportStep(), - }) -} - func TestAccCosmosDBAccount_ipRangeFilters(t *testing.T) { - if !features.FourPointOhBeta() { - t.Skip("this test requires 4.0 mode") - } data := acceptance.BuildTestData(t, "azurerm_cosmosdb_account", "test") r := CosmosDBAccountResource{} @@ -1586,7 +1476,7 @@ func (t CosmosDBAccountResource) Exists(ctx context.Context, clients *clients.Cl return nil, fmt.Errorf("reading Cosmos Database (%s): %+v", id.String(), err) } - return utils.Bool(resp.ID != nil), nil + return pointer.To(resp.ID != nil), nil } func (CosmosDBAccountResource) basic(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel) string { @@ -2651,47 +2541,6 @@ resource "azurerm_cosmosdb_account" "test" { `, r.vNetFiltersPreReqs(data), data.RandomInteger) } -func (r CosmosDBAccountResource) vNetFiltersThreePointOh(data acceptance.TestData) string { - return fmt.Sprintf(` -%[1]s - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%[2]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "GlobalDocumentDB" - - multiple_write_locations_enabled = false - automatic_failover_enabled = false - - consistency_policy { - consistency_level = "Eventual" - max_interval_in_seconds = 5 - max_staleness_prefix = 100 - } - - is_virtual_network_filter_enabled = true - ip_range_filter = "" - - virtual_network_rule { - id = azurerm_subnet.subnet1.id - ignore_missing_vnet_service_endpoint = true - } - - virtual_network_rule { - id = azurerm_subnet.subnet2.id - ignore_missing_vnet_service_endpoint = false - } - - geo_location { - location = azurerm_resource_group.test.location - failover_priority = 0 - } -} -`, r.vNetFiltersPreReqs(data), data.RandomInteger) -} - func (CosmosDBAccountResource) freeTier(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel) string { return fmt.Sprintf(` provider "azurerm" { @@ -4927,88 +4776,6 @@ resource "azurerm_cosmosdb_account" "test" { `, r.vNetFiltersPreReqs(data), data.RandomInteger) } -func (r CosmosDBAccountResource) ipRangeFiltersThreePointOh(data acceptance.TestData) string { - return fmt.Sprintf(` -%[1]s - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%[2]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "GlobalDocumentDB" - - multiple_write_locations_enabled = false - automatic_failover_enabled = false - - consistency_policy { - consistency_level = "Eventual" - max_interval_in_seconds = 5 - max_staleness_prefix = 100 - } - - is_virtual_network_filter_enabled = true - ip_range_filter = "55.0.1.0/24" - - virtual_network_rule { - id = azurerm_subnet.subnet1.id - ignore_missing_vnet_service_endpoint = true - } - - virtual_network_rule { - id = azurerm_subnet.subnet2.id - ignore_missing_vnet_service_endpoint = false - } - - geo_location { - location = azurerm_resource_group.test.location - failover_priority = 0 - } -} -`, r.vNetFiltersPreReqs(data), data.RandomInteger) -} - -func (r CosmosDBAccountResource) ipRangeFiltersUpdatedThreePointOh(data acceptance.TestData) string { - return fmt.Sprintf(` -%[1]s - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%[2]d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "GlobalDocumentDB" - - multiple_write_locations_enabled = false - automatic_failover_enabled = false - - consistency_policy { - consistency_level = "Eventual" - max_interval_in_seconds = 5 - max_staleness_prefix = 100 - } - - is_virtual_network_filter_enabled = true - ip_range_filter = "55.0.1.0/24,55.0.2.0/24" - - virtual_network_rule { - id = azurerm_subnet.subnet1.id - ignore_missing_vnet_service_endpoint = true - } - - virtual_network_rule { - id = azurerm_subnet.subnet2.id - ignore_missing_vnet_service_endpoint = false - } - - geo_location { - location = azurerm_resource_group.test.location - failover_priority = 0 - } -} -`, r.vNetFiltersPreReqs(data), data.RandomInteger) -} - func (CosmosDBAccountResource) updateTagWithUserAssignedDefaultIdentity(data acceptance.TestData, tag string) string { return fmt.Sprintf(` provider "azurerm" { @@ -5104,96 +4871,3 @@ resource "azurerm_cosmosdb_account" "test" { } `, r.completePreReqs(data), data.RandomInteger, string(kind), string(consistency), data.Locations.Secondary, data.Locations.Ternary) } - -func (CosmosDBAccountResource) supersededProperties(data acceptance.TestData, consistency cosmosdb.DefaultConsistencyLevel) string { - return fmt.Sprintf(` -variable "geo_location" { - type = list(object({ - location = string - failover_priority = string - zone_redundant = bool - })) - default = [ - { - location = "%s" - failover_priority = 0 - zone_redundant = false - }, - { - location = "%s" - failover_priority = 1 - zone_redundant = true - } - ] -} - -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-cosmos-%d" - location = "%s" -} - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "MongoDB" - - capabilities { - name = "EnableMongo" - } - - enable_multiple_write_locations = true - enable_automatic_failover = true - - consistency_policy { - consistency_level = "%s" - } - - dynamic "geo_location" { - for_each = var.geo_location - content { - location = geo_location.value.location - failover_priority = geo_location.value.failover_priority - zone_redundant = geo_location.value.zone_redundant - } - } -} -`, data.Locations.Primary, data.Locations.Secondary, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(consistency)) -} - -func (CosmosDBAccountResource) supersededFreeTier(data acceptance.TestData, kind cosmosdb.DatabaseAccountKind, consistency cosmosdb.DefaultConsistencyLevel) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-cosmos-%d" - location = "%s" -} - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "%s" - - enable_free_tier = true - - consistency_policy { - consistency_level = "%s" - } - - geo_location { - location = azurerm_resource_group.test.location - failover_priority = 0 - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, string(kind), string(consistency)) -} diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index 829a90858194..0f0b796a3190 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -17,7 +17,6 @@ import ( "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/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/validate" keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -120,25 +119,6 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - // NOTE: The API does not expose a constant for the Sku so I had to hardcode it here... - // Per the service team, the current default Sku is 'Standard_DS14_v2' but moving forward - // the new default value should be 'Standard_E16s_v5'. - resource.Schema["sku_name"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ValidateFunc: validation.StringIsNotEmpty, - } - } else { - resource.Schema["sku_name"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - Optional: true, - Default: "Standard_E16s_v5", - ValidateFunc: validation.StringIsNotEmpty, - } - } - return resource } diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go index 606321ee719d..c7cae4ab7616 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource_test.go @@ -12,7 +12,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) @@ -63,61 +62,32 @@ func testAccCassandraDatacenter_updateSku(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_cosmosdb_cassandra_datacenter", "test") r := CassandraDatacenterResource{} - if !features.FourPointOhBeta() { - data.ResourceSequentialTest(t, r, []acceptance.TestStep{ - { - Config: r.basicSku(data, "Standard_DS14_v2"), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), - ), - }, - data.ImportStep(), - { - Config: r.basicSku(data, "Standard_DS13_v2"), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS13_v2"), - ), - }, - data.ImportStep(), - { - Config: r.basicSku(data, "Standard_DS14_v2"), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_DS14_v2"), - ), - }, - data.ImportStep(), - }) - } else { - data.ResourceSequentialTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), - ), - }, - data.ImportStep(), - { - Config: r.basicSku(data, "Standard_E8s_v5"), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E8s_v5"), - ), - }, - data.ImportStep(), - { - Config: r.basic(data), - Check: acceptance.ComposeAggregateTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), - ), - }, - data.ImportStep(), - }) - } + data.ResourceSequentialTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), + ), + }, + data.ImportStep(), + { + Config: r.basicSku(data, "Standard_E8s_v5"), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E8s_v5"), + ), + }, + data.ImportStep(), + { + Config: r.basic(data), + Check: acceptance.ComposeAggregateTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("sku_name").HasValue("Standard_E16s_v5"), + ), + }, + data.ImportStep(), + }) } func (t CassandraDatacenterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { diff --git a/internal/services/cosmos/cosmosdb_notebook_workspace_resource.go b/internal/services/cosmos/cosmosdb_notebook_workspace_resource.go deleted file mode 100644 index 4857b29cdb8a..000000000000 --- a/internal/services/cosmos/cosmosdb_notebook_workspace_resource.go +++ /dev/null @@ -1,152 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package cosmos - -import ( - "fmt" - "log" - "time" - - "github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2021-10-15/documentdb" // nolint: staticcheck - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/validate" - "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" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -func resourceCosmosDbNotebookWorkspace() *pluginsdk.Resource { - return &pluginsdk.Resource{ - Create: resourceCosmosDbNotebookWorkspaceCreate, - Read: resourceCosmosDbNotebookWorkspaceRead, - Delete: resourceCosmosDbNotebookWorkspaceDelete, - - Timeouts: &pluginsdk.ResourceTimeout{ - Create: pluginsdk.DefaultTimeout(30 * time.Minute), - Read: pluginsdk.DefaultTimeout(5 * time.Minute), - Delete: pluginsdk.DefaultTimeout(30 * time.Minute), - }, - - Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := parse.NotebookWorkspaceID(id) - return err - }), - - DeprecationMessage: `CosmosDb Notebook Workspace is now Deprecated - as such the 'azurerm_cosmosdb_notebook_workspace' resource is deprecated and will be removed in v4.0 of the AzureRM Provider`, - - Schema: map[string]*pluginsdk.Schema{ - "name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validation.StringInSlice([]string{ - "default", - }, false), - }, - - "resource_group_name": commonschema.ResourceGroupName(), - - "account_name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.CosmosAccountName, - }, - - "server_endpoint": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - } -} - -func resourceCosmosDbNotebookWorkspaceCreate(d *pluginsdk.ResourceData, meta interface{}) error { - subscriptionId := meta.(*clients.Client).Account.SubscriptionId - client := meta.(*clients.Client).Cosmos.NotebookWorkspaceClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - name := d.Get("name").(string) - resourceGroup := d.Get("resource_group_name").(string) - accountName := d.Get("account_name").(string) - - id := parse.NewNotebookWorkspaceID(subscriptionId, resourceGroup, accountName, name) - - existing, err := client.Get(ctx, id.ResourceGroup, id.DatabaseAccountName) - if err != nil { - if !utils.ResponseWasNotFound(existing.Response) { - return fmt.Errorf("checking for existing CosmosDb NotebookWorkspace %q: %+v", id, err) - } - } - if !utils.ResponseWasNotFound(existing.Response) { - return tf.ImportAsExistsError("azurerm_cosmosdb_notebook_workspace", id.ID()) - } - - notebookCreateUpdateParameters := documentdb.NotebookWorkspaceCreateUpdateParameters{} - future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.DatabaseAccountName, notebookCreateUpdateParameters) - if err != nil { - return fmt.Errorf("creating CosmosDb NotebookWorkspace %q: %+v", id, err) - } - - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for creation of the CosmosDb NotebookWorkspace %q: %+v", id, err) - } - - d.SetId(id.ID()) - return resourceCosmosDbNotebookWorkspaceRead(d, meta) -} - -func resourceCosmosDbNotebookWorkspaceRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cosmos.NotebookWorkspaceClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := parse.NotebookWorkspaceID(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, id.ResourceGroup, id.DatabaseAccountName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] CosmosDb NotebookWorkspace %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil - } - return fmt.Errorf("retrieving CosmosDb NotebookWorkspace %q: %+v", id, err) - } - d.Set("name", id.Name) - d.Set("resource_group_name", id.ResourceGroup) - d.Set("account_name", id.DatabaseAccountName) - if props := resp.NotebookWorkspaceProperties; props != nil { - d.Set("server_endpoint", props.NotebookServerEndpoint) - } - return nil -} - -func resourceCosmosDbNotebookWorkspaceDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Cosmos.NotebookWorkspaceClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := parse.NotebookWorkspaceID(d.Id()) - if err != nil { - return err - } - - future, err := client.Delete(ctx, id.ResourceGroup, id.DatabaseAccountName) - if err != nil { - return fmt.Errorf("deleting CosmosDb NotebookWorkspace %q: %+v", id, err) - } - - if err := future.WaitForCompletionRef(ctx, client.Client); err != nil { - return fmt.Errorf("waiting for deletion of the CosmosDb NotebookWorkspace %q: %+v", id, err) - } - return nil -} diff --git a/internal/services/cosmos/cosmosdb_notebook_workspace_resource_test.go b/internal/services/cosmos/cosmosdb_notebook_workspace_resource_test.go deleted file mode 100644 index d8cbd053ab20..000000000000 --- a/internal/services/cosmos/cosmosdb_notebook_workspace_resource_test.go +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package cosmos_test - -import ( - "context" - "fmt" - "testing" - - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/cosmos/parse" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -type CosmosDbNotebookWorkspaceResource struct{} - -func TestAccCosmosDbNotebookWorkspace_basic(t *testing.T) { - t.Skip("Skipping as CosmosDb Notebook Workspace is deprecated") - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_notebook_workspace", "test") - r := CosmosDbNotebookWorkspaceResource{} - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }) -} - -func TestAccCosmosDbNotebookWorkspace_requiresImport(t *testing.T) { - t.Skip("Skipping as CosmosDb Notebook Workspace is deprecated") - data := acceptance.BuildTestData(t, "azurerm_cosmosdb_notebook_workspace", "test") - r := CosmosDbNotebookWorkspaceResource{} - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.RequiresImportErrorStep(r.requiresImport), - }) -} - -func (r CosmosDbNotebookWorkspaceResource) Exists(ctx context.Context, client *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := parse.NotebookWorkspaceID(state.ID) - if err != nil { - return nil, err - } - resp, err := client.Cosmos.NotebookWorkspaceClient.Get(ctx, id.ResourceGroup, id.DatabaseAccountName) - if err != nil { - if utils.ResponseWasNotFound(resp.Response) { - return utils.Bool(false), nil - } - return nil, fmt.Errorf("retrieving Cosmos NotebookWorkspace %q: %+v", id, err) - } - return utils.Bool(true), nil -} - -//nolint:unused -func (r CosmosDbNotebookWorkspaceResource) template(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctest-cosmosdb-%d" - location = "%s" -} - -resource "azurerm_cosmosdb_account" "test" { - name = "acctest-ca-%d" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - offer_type = "Standard" - kind = "GlobalDocumentDB" - - consistency_policy { - consistency_level = "BoundedStaleness" - } - - geo_location { - location = azurerm_resource_group.test.location - failover_priority = 0 - } -} -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) -} - -//nolint:unused -func (r CosmosDbNotebookWorkspaceResource) basic(data acceptance.TestData) string { - template := r.template(data) - return fmt.Sprintf(` -%s - -resource "azurerm_cosmosdb_notebook_workspace" "test" { - name = "default" - resource_group_name = azurerm_resource_group.test.name - account_name = azurerm_cosmosdb_account.test.name -} -`, template) -} - -//nolint:unused -func (r CosmosDbNotebookWorkspaceResource) requiresImport(data acceptance.TestData) string { - config := r.basic(data) - return fmt.Sprintf(` -%s - -resource "azurerm_cosmosdb_notebook_workspace" "import" { - name = "default" - resource_group_name = azurerm_resource_group.test.name - account_name = azurerm_cosmosdb_account.test.name -} -`, config) -} diff --git a/internal/services/cosmos/registration.go b/internal/services/cosmos/registration.go index ee457112d39e..1d8cd949c5c2 100644 --- a/internal/services/cosmos/registration.go +++ b/internal/services/cosmos/registration.go @@ -4,7 +4,6 @@ package cosmos import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -82,9 +81,5 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_cosmosdb_table": resourceCosmosDbTable(), } - if !features.FourPointOhBeta() { - resources["azurerm_cosmosdb_notebook_workspace"] = resourceCosmosDbNotebookWorkspace() - } - return resources } diff --git a/internal/services/databoxedge/customizediff.go b/internal/services/databoxedge/customizediff.go deleted file mode 100644 index 77ba77108258..000000000000 --- a/internal/services/databoxedge/customizediff.go +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package databoxedge - -import ( - "context" - "fmt" - - "github.com/hashicorp/terraform-provider-azurerm/internal/services/databoxedge/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" -) - -func databoxEdgeCustomizeDiff(ctx context.Context, d *pluginsdk.ResourceDiff, v interface{}) error { - if value, ok := d.GetOk("shipment_address"); ok { - shippingInfo := (value.([]interface{}))[0].(map[string]interface{}) - - _, err := validate.DataboxEdgeStreetAddress(shippingInfo["address"].([]interface{}), "address") - if err != nil { - return fmt.Errorf("%s", err) - } - } - - return nil -} diff --git a/internal/services/databoxedge/databox_edge_order_resource.go b/internal/services/databoxedge/databox_edge_order_resource.go deleted file mode 100644 index 8df0918f9806..000000000000 --- a/internal/services/databoxedge/databox_edge_order_resource.go +++ /dev/null @@ -1,587 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package databoxedge - -import ( - "fmt" - "log" - "time" - - "github.com/hashicorp/go-azure-helpers/lang/response" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" - "github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2022-03-01/orders" - "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/databoxedge/migration" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/databoxedge/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -func resourceOrder() *pluginsdk.Resource { - return &pluginsdk.Resource{ - Create: resourceOrderCreateUpdate, - Read: resourceOrderRead, - Update: resourceOrderCreateUpdate, - Delete: resourceOrderDelete, - - DeprecationMessage: `Creating DataBox Edge Orders are not supported via the Azure API - as such the 'azurerm_databox_edge_order' resource is deprecated and will be removed in v4.0 of the AzureRM Provider`, - - Timeouts: &pluginsdk.ResourceTimeout{ - Create: pluginsdk.DefaultTimeout(30 * time.Minute), - Read: pluginsdk.DefaultTimeout(5 * time.Minute), - Update: pluginsdk.DefaultTimeout(30 * time.Minute), - Delete: pluginsdk.DefaultTimeout(30 * time.Minute), - }, - - Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := orders.ParseDataBoxEdgeDeviceID(id) - return err - }), - - SchemaVersion: 1, - StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ - 0: migration.DataBoxEdgeOrderV0ToV1{}, - }), - - Schema: map[string]*pluginsdk.Schema{ - "device_name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeName, - }, - - "resource_group_name": commonschema.ResourceGroupName(), - - "contact": { - Type: pluginsdk.TypeList, - Required: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "company_name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeCompanyName, - }, - - "name": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeContactName, - }, - - "emails": { - Type: pluginsdk.TypeSet, - Required: true, - ForceNew: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - }, - }, - - "phone_number": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgePhoneNumber, - }, - }, - }, - }, - - "status": { - Type: pluginsdk.TypeList, - Computed: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "info": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "comments": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "additional_details": { - Type: pluginsdk.TypeMap, - Computed: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - }, - }, - - "last_update": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - }, - }, - - "shipment_address": { - Type: pluginsdk.TypeList, - Required: true, - MaxItems: 1, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "address": { - Type: pluginsdk.TypeList, - Required: true, - MaxItems: 3, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - }, - }, - - "city": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeCity, - }, - - "country": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeCountry, - }, - - "state": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgeState, - }, - - "postal_code": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, - ValidateFunc: validate.DataboxEdgePostalCode, - }, - }, - }, - }, - - "shipment_tracking": { - Type: pluginsdk.TypeSet, - Computed: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "carrier_name": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "serial_number": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "tracking_id": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "tracking_url": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - }, - }, - - "shipment_history": { - Type: pluginsdk.TypeSet, - Computed: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "additional_details": { - Type: pluginsdk.TypeMap, - Computed: true, - Elem: &pluginsdk.Schema{ - Type: pluginsdk.TypeString, - }, - }, - - "comments": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "last_update": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - }, - }, - - "return_tracking": { - Type: pluginsdk.TypeSet, - Computed: true, - Elem: &pluginsdk.Resource{ - Schema: map[string]*pluginsdk.Schema{ - "carrier_name": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "serial_number": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "tracking_id": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "tracking_url": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - }, - }, - - "name": { - Type: pluginsdk.TypeString, - Computed: true, - }, - - "serial_number": { - Type: pluginsdk.TypeString, - Computed: true, - }, - }, - - CustomizeDiff: pluginsdk.CustomizeDiffShim(databoxEdgeCustomizeDiff), - } -} - -func resourceOrderCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - subscriptionId := meta.(*clients.Client).Account.SubscriptionId - client := meta.(*clients.Client).DataboxEdge.OrdersClient - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - id := orders.NewDataBoxEdgeDeviceID(subscriptionId, d.Get("resource_group_name").(string), d.Get("device_name").(string)) // TODO: state migration - if d.IsNewResource() { - existing, err := client.Get(ctx, id) - if err != nil { - if !response.WasNotFound(existing.HttpResponse) { - return fmt.Errorf("checking for presence of existing %s: %+v", id, err) - } - } - if !response.WasNotFound(existing.HttpResponse) { - return tf.ImportAsExistsError("azurerm_databox_edge_order", id.ID()) - } - } - - order := orders.Order{ - Properties: &orders.OrderProperties{ - ContactInformation: expandOrderContactDetails(d.Get("contact").([]interface{})), - ShippingAddress: expandOrderAddress(d.Get("shipment_address").([]interface{})), - }, - } - - if err := client.CreateOrUpdateThenPoll(ctx, id, order); err != nil { - return fmt.Errorf("creating/updating %s: %+v", id, err) - } - - d.SetId(id.ID()) - return resourceOrderRead(d, meta) -} - -func resourceOrderRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataboxEdge.OrdersClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := orders.ParseDataBoxEdgeDeviceID(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, *id) - if err != nil { - if response.WasNotFound(resp.HttpResponse) { - log.Printf("[INFO] %s does not exist - removing from state", *id) - d.SetId("") - return nil - } - - return fmt.Errorf("retrieving %s: %+v", *id, err) - } - - d.Set("name", "default") // only one possible value - d.Set("resource_group_name", id.ResourceGroupName) - d.Set("device_name", id.DataBoxEdgeDeviceName) - - if model := resp.Model; model != nil { - if props := model.Properties; props != nil { - if err := d.Set("contact", flattenOrderContactDetails(props.ContactInformation)); err != nil { - return fmt.Errorf("setting `contact`: %+v", err) - } - currentStatus, err := flattenOrderStatus(props.CurrentStatus) - if err != nil { - return fmt.Errorf("flattening `status`: %+v", err) - } - if err := d.Set("status", currentStatus); err != nil { - return fmt.Errorf("setting `status`: %+v", err) - } - if err := d.Set("shipment_address", flattenOrderAddress(props.ShippingAddress)); err != nil { - return fmt.Errorf("setting `shipment_address`: %+v", err) - } - if err := d.Set("shipment_tracking", flattenOrderTrackingInfo(props.DeliveryTrackingInfo)); err != nil { - return fmt.Errorf("setting `shipment_tracking`: %+v", err) - } - shipmentHistory, err := flattenOrderHistory(props.OrderHistory) - if err != nil { - return fmt.Errorf("flattening `shipment_history`: %+v", err) - } - if err := d.Set("shipment_history", shipmentHistory); err != nil { - return fmt.Errorf("setting `shipment_history`: %+v", err) - } - if err := d.Set("return_tracking", flattenOrderTrackingInfo(props.ReturnTrackingInfo)); err != nil { - return fmt.Errorf("setting `return_tracking`: %+v", err) - } - d.Set("serial_number", props.SerialNumber) - } - } - - return nil -} - -func resourceOrderDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataboxEdge.OrdersClient - ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := orders.ParseDataBoxEdgeDeviceID(d.Id()) - if err != nil { - return err - } - - if err := client.DeleteThenPoll(ctx, *id); err != nil { - return fmt.Errorf("deleting %s: %v", *id, err) - } - - return nil -} - -func expandOrderContactDetails(input []interface{}) orders.ContactDetails { - v := input[0].(map[string]interface{}) - emailList := make([]string, 0) - - for _, val := range v["emails"].(*pluginsdk.Set).List() { - emailList = append(emailList, val.(string)) - } - - return orders.ContactDetails{ - ContactPerson: v["name"].(string), - CompanyName: v["company_name"].(string), - Phone: v["phone_number"].(string), - EmailList: emailList, - } -} - -func expandOrderAddress(input []interface{}) *orders.Address { - if len(input) == 0 { - return nil - } - v := input[0].(map[string]interface{}) - - var address1 string - var address2 string - var address3 string - - addressLines := v["address"].([]interface{}) - - for i, addressLine := range addressLines { - if addressLine != "" { - switch i { - case 0: - address1 = addressLine.(string) - case 1: - address2 = addressLine.(string) - case 3: - address3 = addressLine.(string) - } - } - } - - return &orders.Address{ - AddressLine1: utils.String(address1), - AddressLine2: utils.String(address2), - AddressLine3: utils.String(address3), - PostalCode: utils.String(v["postal_code"].(string)), - City: utils.String(v["city"].(string)), - State: utils.String(v["state"].(string)), - Country: v["country"].(string), - } -} - -func flattenOrderContactDetails(input orders.ContactDetails) []interface{} { - return []interface{}{ - map[string]interface{}{ - "company_name": input.CompanyName, - "name": input.ContactPerson, - "emails": input.EmailList, - "phone_number": input.Phone, - }, - } -} - -func flattenOrderStatus(input *orders.OrderStatus) (*[]interface{}, error) { - if input == nil { - return &[]interface{}{}, nil - } - - var status string - if input.Status != "" { - status = string(input.Status) - } - - var comments string - if input.Comments != nil { - comments = *input.Comments - } - additionalOrderDetails := make(map[string]interface{}) - if input.AdditionalOrderDetails != nil { - for k, v := range *input.AdditionalOrderDetails { - additionalOrderDetails[k] = v - } - } - var updateDateTime string - d, err := input.GetUpdateDateTimeAsTime() - if err != nil { - return nil, fmt.Errorf("parsing UpdateDateTime: %+v", err) - } - if d != nil { - updateDateTime = d.Format(time.RFC3339) - } - return &[]interface{}{ - map[string]interface{}{ - "info": status, - "comments": comments, - "additional_details": additionalOrderDetails, - "last_update": updateDateTime, - }, - }, nil -} - -func flattenOrderAddress(input *orders.Address) []interface{} { - if input == nil { - return make([]interface{}, 0) - } - - var postalCode string - if input.PostalCode != nil { - postalCode = *input.PostalCode - } - - var state string - if input.State != nil { - state = *input.State - } - - address := make([]interface{}, 0) - if input.AddressLine1 != nil { - address = append(address, *input.AddressLine1) - } - - if input.AddressLine2 != nil && *input.AddressLine2 != "" { - address = append(address, *input.AddressLine2) - } - - if input.AddressLine3 != nil && *input.AddressLine3 != "" { - address = append(address, *input.AddressLine3) - } - - return []interface{}{ - map[string]interface{}{ - "address": address, - "city": input.City, - "country": input.Country, - "postal_code": postalCode, - "state": state, - }, - } -} - -func flattenOrderTrackingInfo(input *[]orders.TrackingInfo) []interface{} { - results := make([]interface{}, 0) - if input == nil { - return results - } - - for _, item := range *input { - var carrierName string - if item.CarrierName != nil { - carrierName = *item.CarrierName - } - var serialNumber string - if item.SerialNumber != nil { - serialNumber = *item.SerialNumber - } - var trackingId string - if item.TrackingId != nil { - trackingId = *item.TrackingId - } - var trackingUrl string - if item.TrackingURL != nil { - trackingUrl = *item.TrackingURL - } - results = append(results, map[string]interface{}{ - "carrier_name": carrierName, - "serial_number": serialNumber, - "tracking_id": trackingId, - "tracking_url": trackingUrl, - }) - } - return results -} - -func flattenOrderHistory(input *[]orders.OrderStatus) (*[]interface{}, error) { - results := make([]interface{}, 0) - if input != nil { - for _, item := range *input { - additionalOrderDetails := make(map[string]interface{}) - if item.AdditionalOrderDetails != nil { - for k, v := range *item.AdditionalOrderDetails { - additionalOrderDetails[k] = v - } - } - var comments string - if item.Comments != nil { - comments = *item.Comments - } - var updateDateTime string - d, err := item.GetUpdateDateTimeAsTime() - if err != nil { - return nil, fmt.Errorf("parsing UpdateDateTime: %+v", err) - } - if d != nil { - updateDateTime = d.Format(time.RFC3339) - } - results = append(results, map[string]interface{}{ - "additional_details": additionalOrderDetails, - "comments": comments, - "last_update": updateDateTime, - }) - } - } - - return &results, nil -} diff --git a/internal/services/databoxedge/databox_edge_order_resource_test.go b/internal/services/databoxedge/databox_edge_order_resource_test.go deleted file mode 100644 index 336adafbeade..000000000000 --- a/internal/services/databoxedge/databox_edge_order_resource_test.go +++ /dev/null @@ -1,196 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package databoxedge_test - -import ( - "context" - "fmt" - "testing" - - "github.com/hashicorp/go-azure-sdk/resource-manager/databoxedge/2022-03-01/orders" - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -type DataboxEdgeOrderResource struct{} - -func TestAccDataboxEdgeOrder_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_databox_edge_order", "test") - r := DataboxEdgeOrderResource{} - - if features.FourPointOhBeta() { - t.Skipf("Skipping since `azurerm_databox_edge_order` is deprecated and will be removed in 4.0") - } - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }, - ) -} - -func TestAccDataboxEdgeOrder_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_databox_edge_order", "test") - r := DataboxEdgeOrderResource{} - - if features.FourPointOhBeta() { - t.Skipf("Skipping since `azurerm_databox_edge_order` is deprecated and will be removed in 4.0") - } - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - { - Config: r.requiresImport(data), - ExpectError: acceptance.RequiresImportError("azurerm_databox_edge_order"), - }, - }) -} - -func TestAccDataboxEdgeOrder_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_databox_edge_order", "test") - r := DataboxEdgeOrderResource{} - - if features.FourPointOhBeta() { - t.Skipf("Skipping since `azurerm_databox_edge_order` is deprecated and will be removed in 4.0") - } - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.complete(data), - Check: acceptance.ComposeTestCheckFunc( - check.That(data.ResourceName).ExistsInAzure(r), - ), - }, - data.ImportStep(), - }, - ) -} - -func (DataboxEdgeOrderResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := orders.ParseDataBoxEdgeDeviceID(state.ID) - if err != nil { - return nil, err - } - - resp, err := clients.DataboxEdge.OrdersClient.Get(ctx, *id) - if err != nil { - return nil, fmt.Errorf("retrieving %s: %+v", *id, err) - } - - return utils.Bool(resp.Model != nil), nil -} - -// Location has to be hard coded due to limited support of locations for this resource -func (DataboxEdgeOrderResource) template(data acceptance.TestData) string { - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-databoxedge-%d" - location = "%s" -} - -resource "azurerm_databox_edge_device" "test" { - name = "acctest-dd-%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - - sku_name = "EdgeP_Base-Standard" -} -`, data.RandomInteger, "eastus", data.RandomString) -} - -func (r DataboxEdgeOrderResource) basic(data acceptance.TestData) string { - return fmt.Sprintf(` -%s - -resource "azurerm_databox_edge_order" "test" { - resource_group_name = azurerm_resource_group.test.name - device_name = azurerm_databox_edge_device.test.name - - contact { - name = "TerraForm Test" - emails = ["creator4983@FlynnsArcade.com"] - company_name = "Microsoft" - phone_number = "425-882-8080" - } - - shipment_address { - address = ["One Microsoft Way"] - city = "Redmond" - postal_code = "98052" - state = "WA" - country = "United States" - } -} -`, r.template(data)) -} - -func (r DataboxEdgeOrderResource) requiresImport(data acceptance.TestData) string { - return fmt.Sprintf(` -%s - -resource "azurerm_databox_edge_order" "import" { - resource_group_name = azurerm_databox_edge_order.test.resource_group_name - device_name = azurerm_databox_edge_device.test.name - - contact { - name = "TerraForm Test" - emails = ["creator4983@FlynnsArcade.com"] - company_name = "Microsoft" - phone_number = "425-882-8080" - } - - shipment_address { - address = ["One Microsoft Way"] - city = "Redmond" - postal_code = "98052" - state = "WA" - country = "United States" - } -} -`, r.basic(data)) -} - -func (r DataboxEdgeOrderResource) complete(data acceptance.TestData) string { - return fmt.Sprintf(` -%s - -resource "azurerm_databox_edge_order" "test" { - resource_group_name = azurerm_resource_group.test.name - device_name = azurerm_databox_edge_device.test.name - - contact { - name = "TerraForm Test" - emails = ["creator4983@FlynnsArcade.com"] - company_name = "Flynn's Arcade" - phone_number = "(800) 555-1234" - } - - shipment_address { - address = ["One Microsoft Way"] - city = "Redmond" - postal_code = "98052" - state = "WA" - country = "United States" - } -} -`, r.template(data)) -} diff --git a/internal/services/databoxedge/registration.go b/internal/services/databoxedge/registration.go index d5081b828039..e566be49fc95 100644 --- a/internal/services/databoxedge/registration.go +++ b/internal/services/databoxedge/registration.go @@ -4,7 +4,6 @@ package databoxedge import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -51,10 +50,5 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { - if !features.FourPointOhBeta() { - return map[string]*pluginsdk.Resource{ - "azurerm_databox_edge_order": resourceOrder(), - } - } return map[string]*pluginsdk.Resource{} } diff --git a/internal/services/databricks/databricks_customer_managed_key_resource.go b/internal/services/databricks/databricks_customer_managed_key_resource.go deleted file mode 100644 index 51320bfcf2e5..000000000000 --- a/internal/services/databricks/databricks_customer_managed_key_resource.go +++ /dev/null @@ -1,299 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package databricks - -import ( - "context" - "fmt" - "log" - "strings" - "time" - - "github.com/hashicorp/go-azure-helpers/lang/pointer" - "github.com/hashicorp/go-azure-helpers/lang/response" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" - "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2024-05-01/workspaces" - "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/locks" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/databricks/migration" - keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" - keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" -) - -func resourceDatabricksWorkspaceCustomerManagedKey() *pluginsdk.Resource { - return &pluginsdk.Resource{ - Create: databricksWorkspaceCustomerManagedKeyCreateUpdate, - Read: databricksWorkspaceCustomerManagedKeyRead, - Update: databricksWorkspaceCustomerManagedKeyCreateUpdate, - Delete: databricksWorkspaceCustomerManagedKeyDelete, - - Timeouts: &pluginsdk.ResourceTimeout{ - Create: pluginsdk.DefaultTimeout(30 * time.Minute), - Read: pluginsdk.DefaultTimeout(5 * time.Minute), - Update: pluginsdk.DefaultTimeout(30 * time.Minute), - Delete: pluginsdk.DefaultTimeout(30 * time.Minute), - }, - - DeprecationMessage: "The resource `azurerm_databricks_workspace_customer_managed_key` will be removed in v4.0 of the AzureRM Provider in favour of the `azurerm_databricks_workspace_root_dbfs_customer_managed_key` resource.", - - Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { - _, err := workspaces.ParseWorkspaceID(id) - return err - }, func(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) ([]*pluginsdk.ResourceData, error) { - // validate that the passed ID is a valid CMK configuration ID - id, err := workspaces.ParseWorkspaceID(d.Id()) - if err != nil { - return []*pluginsdk.ResourceData{d}, err - } - - // set the new values for the CMK resource - d.SetId(id.ID()) - d.Set("workspace_id", id.ID()) - - return []*pluginsdk.ResourceData{d}, nil - }), - - SchemaVersion: 1, - StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ - 0: migration.CustomerManagedKeyV0ToV1{}, - }), - - Schema: map[string]*pluginsdk.Schema{ - "workspace_id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: workspaces.ValidateWorkspaceID, - }, - - // Make this key vault key id and abstract everything from the string... - "key_vault_key_id": { - Type: pluginsdk.TypeString, - Required: true, - ValidateFunc: keyVaultValidate.KeyVaultChildID, - }, - }, - } -} - -func databricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - workspaceClient := meta.(*clients.Client).DataBricks.WorkspacesClient - keyVaultsClient := meta.(*clients.Client).KeyVault - ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := workspaces.ParseWorkspaceID(d.Get("workspace_id").(string)) - if err != nil { - return err - } - - keyIdRaw := d.Get("key_vault_key_id").(string) - key, err := keyVaultParse.ParseNestedItemID(keyIdRaw) - if err != nil { - return err - } - - // Not sure if I should also lock the key vault here too - // or at the very least the key? - locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace") - defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace") - var encryptionEnabled bool - - workspace, err := workspaceClient.Get(ctx, *id) - if err != nil { - return fmt.Errorf("retrieving %s: %+v", *id, err) - } - - keySource := workspaces.KeySourceDefault - var params *workspaces.WorkspaceCustomParameters - - if model := workspace.Model; model != nil { - if params = model.Properties.Parameters; params != nil { - if params.PrepareEncryption != nil { - encryptionEnabled = model.Properties.Parameters.PrepareEncryption.Value - } - - if params.Encryption != nil && params.Encryption.Value != nil && params.Encryption.Value.KeySource != nil { - keySource = pointer.From(params.Encryption.Value.KeySource) - } - } else { - return fmt.Errorf("`WorkspaceCustomParameters` were nil") - } - } else { - return fmt.Errorf("`Workspace` was nil") - } - - if !encryptionEnabled { - return fmt.Errorf("%s: `customer_managed_key_enabled` must be set to `true`", *id) - } - - // make sure the key vault exists - subscriptionId := commonids.NewSubscriptionID(id.SubscriptionId) - keyVaultIdRaw, err := keyVaultsClient.KeyVaultIDFromBaseUrl(ctx, subscriptionId, key.KeyVaultBaseUrl) - if err != nil || keyVaultIdRaw == nil { - return fmt.Errorf("retrieving the Resource ID for the Key Vault at URL %q: %+v", key.KeyVaultBaseUrl, err) - } - - // Only throw the import error if the keysource value has been set to something other than default... - if params.Encryption != nil && params.Encryption.Value != nil && keySource != workspaces.KeySourceDefault { - return tf.ImportAsExistsError("azurerm_databricks_workspace_customer_managed_key", id.ID()) - } - - // We need to pull all of the custom params from the parent - // workspace resource and then add our new encryption values into the - // structure, else the other values set in the parent workspace - // resource will be lost and overwritten as nil. ¯\_(ツ)_/¯ - // NOTE: 'workspace.Parameters' will never be nil as 'customer_managed_key_enabled' and 'infrastructure_encryption_enabled' - // fields have a default value in the parent workspace resource. - params.Encryption = &workspaces.WorkspaceEncryptionParameter{ - Value: &workspaces.Encryption{ - KeySource: pointer.To(workspaces.KeySourceMicrosoftPointKeyvault), - KeyName: pointer.To(key.Name), - Keyversion: pointer.To(key.Version), - Keyvaulturi: pointer.To(key.KeyVaultBaseUrl), - }, - } - - props := getProps(*workspace.Model, params) - - if err = workspaceClient.CreateOrUpdateThenPoll(ctx, *id, props); err != nil { - return fmt.Errorf("creating/updating Customer Managed Key for %s: %+v", *id, err) - } - - d.SetId(id.ID()) - return databricksWorkspaceCustomerManagedKeyRead(d, meta) -} - -func databricksWorkspaceCustomerManagedKeyRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataBricks.WorkspacesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := workspaces.ParseWorkspaceID(d.Id()) - if err != nil { - return err - } - - resp, err := client.Get(ctx, *id) - if err != nil { - if response.WasNotFound(resp.HttpResponse) { - log.Printf("[DEBUG] %s was not found - removing from state", *id) - d.SetId("") - return nil - } - - return fmt.Errorf("retrieving %s: %+v", *id, err) - } - - keySource := "" - keyName := "" - keyVersion := "" - keyVaultURI := "" - - if model := resp.Model; model != nil { - if model.Properties.Parameters != nil { - if props := model.Properties.Parameters.Encryption; props != nil { - if props.Value.KeySource != nil { - keySource = string(*props.Value.KeySource) - } - if props.Value.KeyName != nil { - keyName = *props.Value.KeyName - } - if props.Value.Keyversion != nil { - keyVersion = *props.Value.Keyversion - } - if props.Value.Keyvaulturi != nil { - keyVaultURI = *props.Value.Keyvaulturi - } - } - } - } - - if strings.EqualFold(keySource, string(workspaces.KeySourceMicrosoftPointKeyvault)) && (keyName == "" || keyVersion == "" || keyVaultURI == "") { - d.SetId("") - return nil - } - - d.SetId(id.ID()) - d.Set("workspace_id", id.ID()) - - if keyVaultURI != "" { - key, err := keyVaultParse.NewNestedItemID(keyVaultURI, keyVaultParse.NestedItemTypeKey, keyName, keyVersion) - if err == nil { - d.Set("key_vault_key_id", key.ID()) - } - } - - return nil -} - -func databricksWorkspaceCustomerManagedKeyDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).DataBricks.WorkspacesClient - ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) - defer cancel() - - id, err := workspaces.ParseWorkspaceID(d.Id()) - if err != nil { - return err - } - - // Not sure if I should also lock the key vault here too - locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace") - defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace") - - workspace, err := client.Get(ctx, *id) - if err != nil { - return fmt.Errorf("retrieving %s: %+v", *id, err) - } - - // Since this isn't real and you cannot turn off CMK without destroying the - // workspace and recreating it the best I can do is to set the workspace - // back to using Microsoft managed keys and removing the CMK fields - // also need to pull all of the custom params from the parent - // workspace resource and then add our new encryption values into the - // structure, else the other values set in the parent workspace - // resource will be lost and overwritten as nil. ¯\_(ツ)_/¯ - keySource := workspaces.KeySourceDefault - params := workspace.Model.Properties.Parameters - params.Encryption = &workspaces.WorkspaceEncryptionParameter{ - Value: &workspaces.Encryption{ - KeySource: &keySource, - }, - } - - props := getProps(*workspace.Model, params) - - if err = client.CreateOrUpdateThenPoll(ctx, *id, props); err != nil { - return fmt.Errorf("removing Customer Managed Key from %s: %+v", *id, err) - } - - return nil -} - -func getProps(workspace workspaces.Workspace, params *workspaces.WorkspaceCustomParameters) workspaces.Workspace { - props := workspaces.Workspace{ - Location: workspace.Location, - Sku: workspace.Sku, - Properties: workspaces.WorkspaceProperties{ - PublicNetworkAccess: workspace.Properties.PublicNetworkAccess, - ManagedResourceGroupId: workspace.Properties.ManagedResourceGroupId, - Parameters: params, - }, - Tags: workspace.Tags, - } - - // If notebook encryption exists add it to the properties - if workspace.Properties.Encryption != nil { - props.Properties.Encryption = workspace.Properties.Encryption - } - - // This is only valid if Private Link only is set - if workspace.Properties.PublicNetworkAccess != nil && *workspace.Properties.PublicNetworkAccess == workspaces.PublicNetworkAccessDisabled { - props.Properties.RequiredNsgRules = workspace.Properties.RequiredNsgRules - } - - return props -} diff --git a/internal/services/databricks/databricks_customer_managed_key_resource_test.go b/internal/services/databricks/databricks_customer_managed_key_resource_test.go deleted file mode 100644 index b8824c54fec9..000000000000 --- a/internal/services/databricks/databricks_customer_managed_key_resource_test.go +++ /dev/null @@ -1,302 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package databricks_test - -import ( - "context" - "fmt" - "testing" - - "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2024-05-01/workspaces" - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" - "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" - "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" - "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" - "github.com/hashicorp/terraform-provider-azurerm/utils" -) - -type DatabricksWorkspaceCustomerManagedKeyResource struct{} - -func TestAccDatabricksWorkspaceCustomerManagedKey_basic(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("Resource no longer exists in 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") - parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") - r := DatabricksWorkspaceCustomerManagedKeyResource{} - cmkTemplate := r.cmkTemplate() - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data, cmkTemplate), - Check: acceptance.ComposeTestCheckFunc( - // You must look for the parent resource (e.g. Databricks Workspace) - // and then derive if the CMK object has been set or not... - check.That(parent.ResourceName).ExistsInAzure(r), - ), - }, - parent.ImportStep(), - }) -} - -func TestAccDatabricksWorkspaceCustomerManagedKey_remove(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("Resource no longer exists in 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") - parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") - r := DatabricksWorkspaceCustomerManagedKeyResource{} - cmkTemplate := r.cmkTemplate() - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data, cmkTemplate), - Check: acceptance.ComposeTestCheckFunc( - check.That(parent.ResourceName).ExistsInAzure(r), - ), - }, - parent.ImportStep(), - { - Config: r.basic(data, ""), - Check: acceptance.ComposeTestCheckFunc( - // Then ensure the encryption settings on the Databricks Workspace - // have been reverted to their default state - check.That(parent.ResourceName).DoesNotExistInAzure(r), - ), - }, - parent.ImportStep(), - }) -} - -func TestAccDatabricksWorkspaceCustomerManagedKey_requiresImport(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("Resource no longer exists in 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") - parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") - r := DatabricksWorkspaceCustomerManagedKeyResource{} - cmkTemplate := r.cmkTemplate() - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.basic(data, cmkTemplate), - Check: acceptance.ComposeTestCheckFunc( - check.That(parent.ResourceName).ExistsInAzure(r), - ), - }, - data.RequiresImportErrorStep(r.requiresImport), - }) -} - -func TestAccDatabricksWorkspaceCustomerManagedKey_noIp(t *testing.T) { - if features.FourPointOhBeta() { - t.Skip("Resource no longer exists in 4.0") - } - - data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") - parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") - r := DatabricksWorkspaceCustomerManagedKeyResource{} - cmkTemplate := r.cmkTemplate() - - data.ResourceTest(t, r, []acceptance.TestStep{ - { - Config: r.noip(data, cmkTemplate), - Check: acceptance.ComposeTestCheckFunc( - check.That(parent.ResourceName).ExistsInAzure(r), - ), - }, - parent.ImportStep(), - { - Config: r.noip(data, ""), - Check: acceptance.ComposeTestCheckFunc( - check.That(parent.ResourceName).DoesNotExistInAzure(r), - check.That(parent.ResourceName).Key("custom_parameters.0.no_public_ip").IsSet(), - ), - }, - parent.ImportStep(), - }) -} - -func (DatabricksWorkspaceCustomerManagedKeyResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := workspaces.ParseWorkspaceID(state.ID) - if err != nil { - return nil, err - } - - resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id) - if err != nil { - return nil, fmt.Errorf("retrieving %s: %+v", id, err) - } - - // This is the only way we can tell if the CMK has actually been provisioned or not... - if resp.Model != nil && resp.Model.Properties.Parameters != nil && resp.Model.Properties.Parameters.Encryption != nil && resp.Model.Properties.Parameters.Encryption.Value != nil && resp.Model.Properties.Parameters.Encryption.Value.KeySource != nil { - if *resp.Model.Properties.Parameters.Encryption.Value.KeySource == workspaces.KeySourceMicrosoftPointKeyvault { - return utils.Bool(true), nil - } - } - - return utils.Bool(false), nil -} - -func (r DatabricksWorkspaceCustomerManagedKeyResource) requiresImport(data acceptance.TestData) string { - cmkTemplate := r.cmkTemplate() - template := r.basic(data, cmkTemplate) - return fmt.Sprintf(` -%s -resource "azurerm_databricks_workspace_customer_managed_key" "import" { - workspace_id = azurerm_databricks_workspace.test.id - key_vault_key_id = azurerm_key_vault_key.test.id -} -`, template) -} - -func (r DatabricksWorkspaceCustomerManagedKeyResource) basic(data acceptance.TestData, cmk string) string { - keyVault := r.keyVaultTemplate(data) - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-db-%[1]d" - location = "%[2]s" -} - -%[3]s - -resource "azurerm_databricks_workspace" "test" { - name = "acctestDBW-%[1]d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - sku = "premium" - - customer_managed_key_enabled = true - infrastructure_encryption_enabled = true -} - -%[4]s -`, data.RandomInteger, "eastus2", keyVault, cmk) -} - -func (r DatabricksWorkspaceCustomerManagedKeyResource) noip(data acceptance.TestData, cmk string) string { - keyVault := r.keyVaultTemplate(data) - return fmt.Sprintf(` -provider "azurerm" { - features {} -} - -data "azurerm_client_config" "current" {} - -resource "azurerm_resource_group" "test" { - name = "acctestRG-db-%[1]d" - location = "%[2]s" -} - -%[3]s - -resource "azurerm_databricks_workspace" "test" { - name = "acctestDBW-%[1]d" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - sku = "premium" - - customer_managed_key_enabled = true - - custom_parameters { - no_public_ip = true - } -} - -%[5]s -`, data.RandomInteger, "eastus2", keyVault, data.RandomString, cmk) -} - -func (DatabricksWorkspaceCustomerManagedKeyResource) cmkTemplate() string { - return ` -resource "azurerm_databricks_workspace_customer_managed_key" "test" { - depends_on = [azurerm_key_vault_access_policy.databricks] - - workspace_id = azurerm_databricks_workspace.test.id - key_vault_key_id = azurerm_key_vault_key.test.id -} -` -} - -func (DatabricksWorkspaceCustomerManagedKeyResource) keyVaultTemplate(data acceptance.TestData) string { - return fmt.Sprintf(` -resource "azurerm_key_vault" "test" { - name = "acctest-kv-%[3]s" - location = azurerm_resource_group.test.location - resource_group_name = azurerm_resource_group.test.name - tenant_id = data.azurerm_client_config.current.tenant_id - sku_name = "premium" - - soft_delete_retention_days = 7 -} - -resource "azurerm_key_vault_key" "test" { - depends_on = [azurerm_key_vault_access_policy.terraform] - - name = "acctest-key-%[1]d" - key_vault_id = azurerm_key_vault.test.id - key_type = "RSA" - key_size = 2048 - - key_opts = [ - "decrypt", - "encrypt", - "sign", - "unwrapKey", - "verify", - "wrapKey", - ] -} - -resource "azurerm_key_vault_access_policy" "terraform" { - key_vault_id = azurerm_key_vault.test.id - tenant_id = azurerm_key_vault.test.tenant_id - object_id = data.azurerm_client_config.current.object_id - - key_permissions = [ - "Get", - "List", - "Create", - "Decrypt", - "Encrypt", - "GetRotationPolicy", - "Sign", - "UnwrapKey", - "Verify", - "WrapKey", - "Delete", - "Restore", - "Recover", - "Update", - "Purge", - ] -} - -resource "azurerm_key_vault_access_policy" "databricks" { - depends_on = [azurerm_databricks_workspace.test] - - key_vault_id = azurerm_key_vault.test.id - tenant_id = azurerm_databricks_workspace.test.storage_account_identity.0.tenant_id - object_id = azurerm_databricks_workspace.test.storage_account_identity.0.principal_id - - key_permissions = [ - "Get", - "GetRotationPolicy", - "UnwrapKey", - "WrapKey", - "Delete", - ] -} -`, data.RandomInteger, data.Locations.Primary, data.RandomString) -} diff --git a/internal/services/databricks/databricks_workspace_resource.go b/internal/services/databricks/databricks_workspace_resource.go index 38f329f6cb51..8754002b4686 100644 --- a/internal/services/databricks/databricks_workspace_resource.go +++ b/internal/services/databricks/databricks_workspace_resource.go @@ -22,7 +22,6 @@ import ( "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/features" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" "github.com/hashicorp/terraform-provider-azurerm/internal/services/databricks/validate" keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" @@ -144,7 +143,6 @@ func resourceDatabricksWorkspace() *pluginsdk.Resource { "network_security_group_rules_required": { Type: pluginsdk.TypeString, Optional: true, - Computed: !features.FourPointOhBeta(), ValidateFunc: validation.StringInSlice([]string{ string(workspaces.RequiredNsgRulesAllRules), string(workspaces.RequiredNsgRulesNoAzureDatabricksRules), @@ -380,17 +378,6 @@ func resourceDatabricksWorkspace() *pluginsdk.Resource { }), } - if !features.FourPointOhBeta() { - // NOTE: Leaving this as O+C as the 2024-05-01 API breaking change was accidentally introduced in PR #25919 - // and released in v3.104.0 of the provider... - resource.Schema["custom_parameters"].Elem.(*pluginsdk.Resource).Schema["no_public_ip"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - AtLeastOneOf: workspaceCustomParametersString(), - } - } - return resource } diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index c1bf344a2b6d..2b7317a3b718 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -4,7 +4,6 @@ package databricks import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -44,14 +43,10 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { resources := map[string]*pluginsdk.Resource{ "azurerm_databricks_workspace": resourceDatabricksWorkspace(), - "azurerm_databricks_workspace_customer_managed_key": resourceDatabricksWorkspaceCustomerManagedKey(), // TODO: Remove in 4.0 "azurerm_databricks_workspace_root_dbfs_customer_managed_key": resourceDatabricksWorkspaceRootDbfsCustomerManagedKey(), "azurerm_databricks_virtual_network_peering": resourceDatabricksVirtualNetworkPeering(), } - if !features.FourPointOhBeta() { - resources["azurerm_databricks_workspace_customer_managed_key"] = resourceDatabricksWorkspaceCustomerManagedKey() - } return resources } diff --git a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go index a2bbab923f47..b4ac3d9c661f 100644 --- a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go +++ b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go @@ -8,12 +8,12 @@ import ( "regexp" "time" + "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" "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/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/datafactory/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" @@ -116,14 +116,6 @@ func resourceDataFactoryIntegrationRuntimeAzure() *pluginsdk.Resource { }, } - if !features.FourPointOhBeta() { - resource.Schema["cleanup_enabled"] = &pluginsdk.Schema{ - Type: pluginsdk.TypeBool, - Optional: true, - Computed: true, - } - } - return resource } @@ -280,27 +272,13 @@ func resourceDataFactoryIntegrationRuntimeAzureDelete(d *pluginsdk.ResourceData, } func expandDataFactoryIntegrationRuntimeAzureComputeProperties(d *pluginsdk.ResourceData) *datafactory.IntegrationRuntimeComputeProperties { - location := azure.NormalizeLocation(d.Get("location").(string)) - coreCount := int32(d.Get("core_count").(int)) - timeToLiveMin := int32(d.Get("time_to_live_min").(int)) - - cleanup := true - if features.FourPointOhBeta() { - cleanup = d.Get("cleanup_enabled").(bool) - } else { - // nolint staticcheck - if v, ok := d.GetOkExists("cleanup_enabled"); ok { - cleanup = v.(bool) - } - } - return &datafactory.IntegrationRuntimeComputeProperties{ - Location: &location, + Location: pointer.To(azure.NormalizeLocation(d.Get("location").(string))), DataFlowProperties: &datafactory.IntegrationRuntimeDataFlowProperties{ ComputeType: datafactory.DataFlowComputeType(d.Get("compute_type").(string)), - CoreCount: &coreCount, - TimeToLive: &timeToLiveMin, - Cleanup: utils.Bool(cleanup), + CoreCount: pointer.To(int32(d.Get("core_count").(int))), + TimeToLive: pointer.To(int32(d.Get("time_to_live_min").(int))), + Cleanup: pointer.To(d.Get("cleanup_enabled").(bool)), }, } } diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index eb490bde7947..7517c619acde 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -21,7 +21,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/locks" eventhubValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/eventhub/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/migration" @@ -163,27 +162,15 @@ func resourceIotHub() *pluginsdk.Resource { }, "event_hub_partition_count": { - Type: pluginsdk.TypeInt, - Optional: true, - Computed: !features.FourPointOhBeta(), - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return 4 - }(), + Type: pluginsdk.TypeInt, + Optional: true, + Default: 4, ValidateFunc: validation.IntBetween(2, 128), }, "event_hub_retention_in_days": { - Type: pluginsdk.TypeInt, - Optional: true, - Computed: !features.FourPointOhBeta(), - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return 1 - }(), + Type: pluginsdk.TypeInt, + Optional: true, + Default: 1, ValidateFunc: validation.IntBetween(1, 7), }, @@ -231,38 +218,20 @@ func resourceIotHub() *pluginsdk.Resource { "sas_ttl": { Type: pluginsdk.TypeString, Optional: true, - Computed: !features.FourPointOhBeta(), ValidateFunc: validate.ISO8601Duration, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return "PT1H" - }(), + Default: "PT1H", }, "default_ttl": { Type: pluginsdk.TypeString, Optional: true, - Computed: !features.FourPointOhBeta(), ValidateFunc: validate.ISO8601Duration, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return "PT1H" - }(), + Default: "PT1H", }, "lock_duration": { Type: pluginsdk.TypeString, Optional: true, - Computed: !features.FourPointOhBeta(), ValidateFunc: validate.ISO8601Duration, - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return "PT1M" - }(), + Default: "PT1M", }, }, }, @@ -503,13 +472,7 @@ func resourceIotHub() *pluginsdk.Resource { "enabled": { Type: pluginsdk.TypeBool, Optional: true, - Computed: !features.FourPointOhBeta(), - Default: func() interface{} { - if !features.FourPointOhBeta() { - return nil - } - return true - }(), + Default: true, }, }, }, From 056563c08cdd14c53b3b21a8c79377dedeb32ee2 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 12:04:00 -0800 Subject: [PATCH 2/7] address review comments --- .../cosmosdb_cassandra_datacenter_resource.go | 10 + ...atabricks_customer_managed_key_resource.go | 299 +++++++++++++++++ ...icks_customer_managed_key_resource_test.go | 302 ++++++++++++++++++ internal/services/databricks/registration.go | 5 +- 4 files changed, 613 insertions(+), 3 deletions(-) create mode 100644 internal/services/databricks/databricks_customer_managed_key_resource.go create mode 100644 internal/services/databricks/databricks_customer_managed_key_resource_test.go diff --git a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go index 0f0b796a3190..6333e2bb4dd0 100644 --- a/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go +++ b/internal/services/cosmos/cosmosdb_cassandra_datacenter_resource.go @@ -92,23 +92,33 @@ func resourceCassandraDatacenter() *pluginsdk.Resource { Optional: true, ValidateFunc: keyVaultValidate.NestedItemId, }, + "node_count": { Type: pluginsdk.TypeInt, Optional: true, ValidateFunc: validation.IntAtLeast(3), Default: 3, }, + "disk_count": { Type: pluginsdk.TypeInt, Optional: true, ValidateFunc: validation.IntBetween(1, 10), }, + "availability_zones_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: true, }, + "sku_name": { + Type: pluginsdk.TypeString, + Optional: true, + Default: "Standard_E16s_v5", + ValidateFunc: validation.StringIsNotEmpty, + }, + "seed_node_ip_addresses": { Type: pluginsdk.TypeList, Computed: true, diff --git a/internal/services/databricks/databricks_customer_managed_key_resource.go b/internal/services/databricks/databricks_customer_managed_key_resource.go new file mode 100644 index 000000000000..bc28d733c10e --- /dev/null +++ b/internal/services/databricks/databricks_customer_managed_key_resource.go @@ -0,0 +1,299 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package databricks + +import ( + "context" + "fmt" + "log" + "strings" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" + "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2024-05-01/workspaces" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/locks" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/databricks/migration" + keyVaultParse "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/parse" + keyVaultValidate "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/validate" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" +) + +func resourceDatabricksWorkspaceCustomerManagedKey() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: databricksWorkspaceCustomerManagedKeyCreateUpdate, + Read: databricksWorkspaceCustomerManagedKeyRead, + Update: databricksWorkspaceCustomerManagedKeyCreateUpdate, + Delete: databricksWorkspaceCustomerManagedKeyDelete, + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + DeprecationMessage: "The resource `azurerm_databricks_workspace_customer_managed_key` will be removed in v5.0 of the AzureRM Provider in favour of the `azurerm_databricks_workspace_root_dbfs_customer_managed_key` resource.", + + Importer: pluginsdk.ImporterValidatingResourceIdThen(func(id string) error { + _, err := workspaces.ParseWorkspaceID(id) + return err + }, func(ctx context.Context, d *pluginsdk.ResourceData, meta interface{}) ([]*pluginsdk.ResourceData, error) { + // validate that the passed ID is a valid CMK configuration ID + id, err := workspaces.ParseWorkspaceID(d.Id()) + if err != nil { + return []*pluginsdk.ResourceData{d}, err + } + + // set the new values for the CMK resource + d.SetId(id.ID()) + d.Set("workspace_id", id.ID()) + + return []*pluginsdk.ResourceData{d}, nil + }), + + SchemaVersion: 1, + StateUpgraders: pluginsdk.StateUpgrades(map[int]pluginsdk.StateUpgrade{ + 0: migration.CustomerManagedKeyV0ToV1{}, + }), + + Schema: map[string]*pluginsdk.Schema{ + "workspace_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: workspaces.ValidateWorkspaceID, + }, + + // Make this key vault key id and abstract everything from the string... + "key_vault_key_id": { + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: keyVaultValidate.KeyVaultChildID, + }, + }, + } +} + +func databricksWorkspaceCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + workspaceClient := meta.(*clients.Client).DataBricks.WorkspacesClient + keyVaultsClient := meta.(*clients.Client).KeyVault + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := workspaces.ParseWorkspaceID(d.Get("workspace_id").(string)) + if err != nil { + return err + } + + keyIdRaw := d.Get("key_vault_key_id").(string) + key, err := keyVaultParse.ParseNestedItemID(keyIdRaw) + if err != nil { + return err + } + + // Not sure if I should also lock the key vault here too + // or at the very least the key? + locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace") + defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace") + var encryptionEnabled bool + + workspace, err := workspaceClient.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + keySource := workspaces.KeySourceDefault + var params *workspaces.WorkspaceCustomParameters + + if model := workspace.Model; model != nil { + if params = model.Properties.Parameters; params != nil { + if params.PrepareEncryption != nil { + encryptionEnabled = model.Properties.Parameters.PrepareEncryption.Value + } + + if params.Encryption != nil && params.Encryption.Value != nil && params.Encryption.Value.KeySource != nil { + keySource = pointer.From(params.Encryption.Value.KeySource) + } + } else { + return fmt.Errorf("`WorkspaceCustomParameters` were nil") + } + } else { + return fmt.Errorf("`Workspace` was nil") + } + + if !encryptionEnabled { + return fmt.Errorf("%s: `customer_managed_key_enabled` must be set to `true`", *id) + } + + // make sure the key vault exists + subscriptionId := commonids.NewSubscriptionID(id.SubscriptionId) + keyVaultIdRaw, err := keyVaultsClient.KeyVaultIDFromBaseUrl(ctx, subscriptionId, key.KeyVaultBaseUrl) + if err != nil || keyVaultIdRaw == nil { + return fmt.Errorf("retrieving the Resource ID for the Key Vault at URL %q: %+v", key.KeyVaultBaseUrl, err) + } + + // Only throw the import error if the keysource value has been set to something other than default... + if params.Encryption != nil && params.Encryption.Value != nil && keySource != workspaces.KeySourceDefault { + return tf.ImportAsExistsError("azurerm_databricks_workspace_customer_managed_key", id.ID()) + } + + // We need to pull all of the custom params from the parent + // workspace resource and then add our new encryption values into the + // structure, else the other values set in the parent workspace + // resource will be lost and overwritten as nil. ¯\_(ツ)_/¯ + // NOTE: 'workspace.Parameters' will never be nil as 'customer_managed_key_enabled' and 'infrastructure_encryption_enabled' + // fields have a default value in the parent workspace resource. + params.Encryption = &workspaces.WorkspaceEncryptionParameter{ + Value: &workspaces.Encryption{ + KeySource: pointer.To(workspaces.KeySourceMicrosoftPointKeyvault), + KeyName: pointer.To(key.Name), + Keyversion: pointer.To(key.Version), + Keyvaulturi: pointer.To(key.KeyVaultBaseUrl), + }, + } + + props := getProps(*workspace.Model, params) + + if err = workspaceClient.CreateOrUpdateThenPoll(ctx, *id, props); err != nil { + return fmt.Errorf("creating/updating Customer Managed Key for %s: %+v", *id, err) + } + + d.SetId(id.ID()) + return databricksWorkspaceCustomerManagedKeyRead(d, meta) +} + +func databricksWorkspaceCustomerManagedKeyRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataBricks.WorkspacesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := workspaces.ParseWorkspaceID(d.Id()) + if err != nil { + return err + } + + resp, err := client.Get(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + log.Printf("[DEBUG] %s was not found - removing from state", *id) + d.SetId("") + return nil + } + + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + keySource := "" + keyName := "" + keyVersion := "" + keyVaultURI := "" + + if model := resp.Model; model != nil { + if model.Properties.Parameters != nil { + if props := model.Properties.Parameters.Encryption; props != nil { + if props.Value.KeySource != nil { + keySource = string(*props.Value.KeySource) + } + if props.Value.KeyName != nil { + keyName = *props.Value.KeyName + } + if props.Value.Keyversion != nil { + keyVersion = *props.Value.Keyversion + } + if props.Value.Keyvaulturi != nil { + keyVaultURI = *props.Value.Keyvaulturi + } + } + } + } + + if strings.EqualFold(keySource, string(workspaces.KeySourceMicrosoftPointKeyvault)) && (keyName == "" || keyVersion == "" || keyVaultURI == "") { + d.SetId("") + return nil + } + + d.SetId(id.ID()) + d.Set("workspace_id", id.ID()) + + if keyVaultURI != "" { + key, err := keyVaultParse.NewNestedItemID(keyVaultURI, keyVaultParse.NestedItemTypeKey, keyName, keyVersion) + if err == nil { + d.Set("key_vault_key_id", key.ID()) + } + } + + return nil +} + +func databricksWorkspaceCustomerManagedKeyDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataBricks.WorkspacesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := workspaces.ParseWorkspaceID(d.Id()) + if err != nil { + return err + } + + // Not sure if I should also lock the key vault here too + locks.ByName(id.WorkspaceName, "azurerm_databricks_workspace") + defer locks.UnlockByName(id.WorkspaceName, "azurerm_databricks_workspace") + + workspace, err := client.Get(ctx, *id) + if err != nil { + return fmt.Errorf("retrieving %s: %+v", *id, err) + } + + // Since this isn't real and you cannot turn off CMK without destroying the + // workspace and recreating it the best I can do is to set the workspace + // back to using Microsoft managed keys and removing the CMK fields + // also need to pull all of the custom params from the parent + // workspace resource and then add our new encryption values into the + // structure, else the other values set in the parent workspace + // resource will be lost and overwritten as nil. ¯\_(ツ)_/¯ + keySource := workspaces.KeySourceDefault + params := workspace.Model.Properties.Parameters + params.Encryption = &workspaces.WorkspaceEncryptionParameter{ + Value: &workspaces.Encryption{ + KeySource: &keySource, + }, + } + + props := getProps(*workspace.Model, params) + + if err = client.CreateOrUpdateThenPoll(ctx, *id, props); err != nil { + return fmt.Errorf("removing Customer Managed Key from %s: %+v", *id, err) + } + + return nil +} + +func getProps(workspace workspaces.Workspace, params *workspaces.WorkspaceCustomParameters) workspaces.Workspace { + props := workspaces.Workspace{ + Location: workspace.Location, + Sku: workspace.Sku, + Properties: workspaces.WorkspaceProperties{ + PublicNetworkAccess: workspace.Properties.PublicNetworkAccess, + ManagedResourceGroupId: workspace.Properties.ManagedResourceGroupId, + Parameters: params, + }, + Tags: workspace.Tags, + } + + // If notebook encryption exists add it to the properties + if workspace.Properties.Encryption != nil { + props.Properties.Encryption = workspace.Properties.Encryption + } + + // This is only valid if Private Link only is set + if workspace.Properties.PublicNetworkAccess != nil && *workspace.Properties.PublicNetworkAccess == workspaces.PublicNetworkAccessDisabled { + props.Properties.RequiredNsgRules = workspace.Properties.RequiredNsgRules + } + + return props +} diff --git a/internal/services/databricks/databricks_customer_managed_key_resource_test.go b/internal/services/databricks/databricks_customer_managed_key_resource_test.go new file mode 100644 index 000000000000..4ecf94ea2dbf --- /dev/null +++ b/internal/services/databricks/databricks_customer_managed_key_resource_test.go @@ -0,0 +1,302 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package databricks_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-sdk/resource-manager/databricks/2024-05-01/workspaces" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type DatabricksWorkspaceCustomerManagedKeyResource struct{} + +func TestAccDatabricksWorkspaceCustomerManagedKey_basic(t *testing.T) { + if features.FivePointOhBeta() { + t.Skip("Resource no longer exists in 5.0") + } + + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") + parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") + r := DatabricksWorkspaceCustomerManagedKeyResource{} + cmkTemplate := r.cmkTemplate() + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, cmkTemplate), + Check: acceptance.ComposeTestCheckFunc( + // You must look for the parent resource (e.g. Databricks Workspace) + // and then derive if the CMK object has been set or not... + check.That(parent.ResourceName).ExistsInAzure(r), + ), + }, + parent.ImportStep(), + }) +} + +func TestAccDatabricksWorkspaceCustomerManagedKey_remove(t *testing.T) { + if features.FivePointOhBeta() { + t.Skip("Resource no longer exists in 5.0") + } + + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") + parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") + r := DatabricksWorkspaceCustomerManagedKeyResource{} + cmkTemplate := r.cmkTemplate() + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, cmkTemplate), + Check: acceptance.ComposeTestCheckFunc( + check.That(parent.ResourceName).ExistsInAzure(r), + ), + }, + parent.ImportStep(), + { + Config: r.basic(data, ""), + Check: acceptance.ComposeTestCheckFunc( + // Then ensure the encryption settings on the Databricks Workspace + // have been reverted to their default state + check.That(parent.ResourceName).DoesNotExistInAzure(r), + ), + }, + parent.ImportStep(), + }) +} + +func TestAccDatabricksWorkspaceCustomerManagedKey_requiresImport(t *testing.T) { + if features.FivePointOhBeta() { + t.Skip("Resource no longer exists in 5.0") + } + + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") + parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") + r := DatabricksWorkspaceCustomerManagedKeyResource{} + cmkTemplate := r.cmkTemplate() + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data, cmkTemplate), + Check: acceptance.ComposeTestCheckFunc( + check.That(parent.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccDatabricksWorkspaceCustomerManagedKey_noIp(t *testing.T) { + if features.FivePointOhBeta() { + t.Skip("Resource no longer exists in 5.0") + } + + data := acceptance.BuildTestData(t, "azurerm_databricks_workspace_customer_managed_key", "test") + parent := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test") + r := DatabricksWorkspaceCustomerManagedKeyResource{} + cmkTemplate := r.cmkTemplate() + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.noip(data, cmkTemplate), + Check: acceptance.ComposeTestCheckFunc( + check.That(parent.ResourceName).ExistsInAzure(r), + ), + }, + parent.ImportStep(), + { + Config: r.noip(data, ""), + Check: acceptance.ComposeTestCheckFunc( + check.That(parent.ResourceName).DoesNotExistInAzure(r), + check.That(parent.ResourceName).Key("custom_parameters.0.no_public_ip").IsSet(), + ), + }, + parent.ImportStep(), + }) +} + +func (DatabricksWorkspaceCustomerManagedKeyResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := workspaces.ParseWorkspaceID(state.ID) + if err != nil { + return nil, err + } + + resp, err := clients.DataBricks.WorkspacesClient.Get(ctx, *id) + if err != nil { + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + + // This is the only way we can tell if the CMK has actually been provisioned or not... + if resp.Model != nil && resp.Model.Properties.Parameters != nil && resp.Model.Properties.Parameters.Encryption != nil && resp.Model.Properties.Parameters.Encryption.Value != nil && resp.Model.Properties.Parameters.Encryption.Value.KeySource != nil { + if *resp.Model.Properties.Parameters.Encryption.Value.KeySource == workspaces.KeySourceMicrosoftPointKeyvault { + return utils.Bool(true), nil + } + } + + return utils.Bool(false), nil +} + +func (r DatabricksWorkspaceCustomerManagedKeyResource) requiresImport(data acceptance.TestData) string { + cmkTemplate := r.cmkTemplate() + template := r.basic(data, cmkTemplate) + return fmt.Sprintf(` +%s +resource "azurerm_databricks_workspace_customer_managed_key" "import" { + workspace_id = azurerm_databricks_workspace.test.id + key_vault_key_id = azurerm_key_vault_key.test.id +} +`, template) +} + +func (r DatabricksWorkspaceCustomerManagedKeyResource) basic(data acceptance.TestData, cmk string) string { + keyVault := r.keyVaultTemplate(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-db-%[1]d" + location = "%[2]s" +} + +%[3]s + +resource "azurerm_databricks_workspace" "test" { + name = "acctestDBW-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "premium" + + customer_managed_key_enabled = true + infrastructure_encryption_enabled = true +} + +%[4]s +`, data.RandomInteger, "eastus2", keyVault, cmk) +} + +func (r DatabricksWorkspaceCustomerManagedKeyResource) noip(data acceptance.TestData, cmk string) string { + keyVault := r.keyVaultTemplate(data) + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-db-%[1]d" + location = "%[2]s" +} + +%[3]s + +resource "azurerm_databricks_workspace" "test" { + name = "acctestDBW-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + sku = "premium" + + customer_managed_key_enabled = true + + custom_parameters { + no_public_ip = true + } +} + +%[5]s +`, data.RandomInteger, "eastus2", keyVault, data.RandomString, cmk) +} + +func (DatabricksWorkspaceCustomerManagedKeyResource) cmkTemplate() string { + return ` +resource "azurerm_databricks_workspace_customer_managed_key" "test" { + depends_on = [azurerm_key_vault_access_policy.databricks] + + workspace_id = azurerm_databricks_workspace.test.id + key_vault_key_id = azurerm_key_vault_key.test.id +} +` +} + +func (DatabricksWorkspaceCustomerManagedKeyResource) keyVaultTemplate(data acceptance.TestData) string { + return fmt.Sprintf(` +resource "azurerm_key_vault" "test" { + name = "acctest-kv-%[3]s" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "premium" + + soft_delete_retention_days = 7 +} + +resource "azurerm_key_vault_key" "test" { + depends_on = [azurerm_key_vault_access_policy.terraform] + + name = "acctest-key-%[1]d" + key_vault_id = azurerm_key_vault.test.id + key_type = "RSA" + key_size = 2048 + + key_opts = [ + "decrypt", + "encrypt", + "sign", + "unwrapKey", + "verify", + "wrapKey", + ] +} + +resource "azurerm_key_vault_access_policy" "terraform" { + key_vault_id = azurerm_key_vault.test.id + tenant_id = azurerm_key_vault.test.tenant_id + object_id = data.azurerm_client_config.current.object_id + + key_permissions = [ + "Get", + "List", + "Create", + "Decrypt", + "Encrypt", + "GetRotationPolicy", + "Sign", + "UnwrapKey", + "Verify", + "WrapKey", + "Delete", + "Restore", + "Recover", + "Update", + "Purge", + ] +} + +resource "azurerm_key_vault_access_policy" "databricks" { + depends_on = [azurerm_databricks_workspace.test] + + key_vault_id = azurerm_key_vault.test.id + tenant_id = azurerm_databricks_workspace.test.storage_account_identity.0.tenant_id + object_id = azurerm_databricks_workspace.test.storage_account_identity.0.principal_id + + key_permissions = [ + "Get", + "GetRotationPolicy", + "UnwrapKey", + "WrapKey", + "Delete", + ] +} +`, data.RandomInteger, data.Locations.Primary, data.RandomString) +} diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index 2b7317a3b718..a6abc8837e08 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -41,13 +41,12 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { - resources := map[string]*pluginsdk.Resource{ + return map[string]*pluginsdk.Resource{ "azurerm_databricks_workspace": resourceDatabricksWorkspace(), "azurerm_databricks_workspace_root_dbfs_customer_managed_key": resourceDatabricksWorkspaceRootDbfsCustomerManagedKey(), "azurerm_databricks_virtual_network_peering": resourceDatabricksVirtualNetworkPeering(), + "azurerm_databricks_workspace_customer_managed_key": resourceDatabricksWorkspaceCustomerManagedKey(), // TODO: Remove in 5.0 } - - return resources } // DataSources returns the typed DataSources supported by this service From b6727c9afe6a92b306ab84c7bb222f91732549be Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 12:04:12 -0800 Subject: [PATCH 3/7] Update internal/services/datafactory/data_factory_integration_runtime_azure_resource.go Co-authored-by: stephybun --- .../data_factory_integration_runtime_azure_resource.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go index b4ac3d9c661f..460f351e46de 100644 --- a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go +++ b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go @@ -273,7 +273,7 @@ func resourceDataFactoryIntegrationRuntimeAzureDelete(d *pluginsdk.ResourceData, func expandDataFactoryIntegrationRuntimeAzureComputeProperties(d *pluginsdk.ResourceData) *datafactory.IntegrationRuntimeComputeProperties { return &datafactory.IntegrationRuntimeComputeProperties{ - Location: pointer.To(azure.NormalizeLocation(d.Get("location").(string))), + Location: pointer.To(location.Normalize(d.Get("location").(string))), DataFlowProperties: &datafactory.IntegrationRuntimeDataFlowProperties{ ComputeType: datafactory.DataFlowComputeType(d.Get("compute_type").(string)), CoreCount: pointer.To(int32(d.Get("core_count").(int))), From 6df5ec4f30706fc2df63c609d791bf786fd911fd Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 12:30:06 -0800 Subject: [PATCH 4/7] fix import --- .../data_factory_integration_runtime_azure_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go index 460f351e46de..ade53702c68f 100644 --- a/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go +++ b/internal/services/datafactory/data_factory_integration_runtime_azure_resource.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/pointer" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" "github.com/hashicorp/go-azure-sdk/resource-manager/datafactory/2018-06-01/factories" - "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/datafactory/parse" From ea74576bcec3cd38c0d0e3dad48db681aa45de88 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 14:30:41 -0800 Subject: [PATCH 5/7] add flag --- internal/services/databricks/registration.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index a6abc8837e08..f336b4250156 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -4,6 +4,7 @@ package databricks import ( + `github.com/hashicorp/terraform-provider-azurerm/internal/features` "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) @@ -41,12 +42,17 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { - return map[string]*pluginsdk.Resource{ + resources := map[string]*pluginsdk.Resource{ "azurerm_databricks_workspace": resourceDatabricksWorkspace(), "azurerm_databricks_workspace_root_dbfs_customer_managed_key": resourceDatabricksWorkspaceRootDbfsCustomerManagedKey(), "azurerm_databricks_virtual_network_peering": resourceDatabricksVirtualNetworkPeering(), - "azurerm_databricks_workspace_customer_managed_key": resourceDatabricksWorkspaceCustomerManagedKey(), // TODO: Remove in 5.0 } + + if features.FivePointOh() { + resources["azurerm_databricks_workspace_customer_managed_key"] = resourceDatabricksWorkspaceCustomerManagedKey() + } + + return resources } // DataSources returns the typed DataSources supported by this service From 26941a6c188fff1b1f0d3d9f4c6f9bb0b9d6c1a4 Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 14:33:22 -0800 Subject: [PATCH 6/7] make fmt --- internal/services/databricks/registration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index f336b4250156..c9758f9d7ab9 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -4,7 +4,7 @@ package databricks import ( - `github.com/hashicorp/terraform-provider-azurerm/internal/features` + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/sdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" ) From f3be4affe57c27b67e0b2472270135c4e3669b8c Mon Sep 17 00:00:00 2001 From: kt Date: Fri, 15 Nov 2024 15:34:51 -0800 Subject: [PATCH 7/7] Update internal/services/databricks/registration.go Co-authored-by: Matthew Frahry --- internal/services/databricks/registration.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/services/databricks/registration.go b/internal/services/databricks/registration.go index c9758f9d7ab9..74b9db9ba4eb 100644 --- a/internal/services/databricks/registration.go +++ b/internal/services/databricks/registration.go @@ -48,7 +48,7 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { "azurerm_databricks_virtual_network_peering": resourceDatabricksVirtualNetworkPeering(), } - if features.FivePointOh() { + if !features.FivePointOhBeta() { resources["azurerm_databricks_workspace_customer_managed_key"] = resourceDatabricksWorkspaceCustomerManagedKey() }