From f3c23e3f97927503193452c043235d397cf1b575 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 23 Jul 2024 11:00:46 +0100 Subject: [PATCH 1/4] storage: remove deprecated properties for v4.0 --- ...e_account_customer_managed_key_resource.go | 22 ++++-- .../storage/storage_account_data_source.go | 21 ++++- .../storage/storage_account_resource.go | 45 +++++++++-- .../storage/storage_account_resource_test.go | 54 ++++++------- .../storage_share_directory_resource.go | 76 +++++++++++-------- .../storage_share_directory_resource_test.go | 10 +++ .../storage/storage_table_entity_resource.go | 68 ++++++++++------- .../storage_table_entity_resource_test.go | 9 +++ 8 files changed, 197 insertions(+), 108 deletions(-) diff --git a/internal/services/storage/storage_account_customer_managed_key_resource.go b/internal/services/storage/storage_account_customer_managed_key_resource.go index 85e035d1259e..729ed17f0bfb 100644 --- a/internal/services/storage/storage_account_customer_managed_key_resource.go +++ b/internal/services/storage/storage_account_customer_managed_key_resource.go @@ -15,6 +15,7 @@ import ( "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-01-01/storageaccounts" "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/managedhsm/parse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/managedhsm/validate" @@ -25,7 +26,7 @@ import ( ) func resourceStorageAccountCustomerManagedKey() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceStorageAccountCustomerManagedKeyCreateUpdate, Read: resourceStorageAccountCustomerManagedKeyRead, Update: resourceStorageAccountCustomerManagedKeyCreateUpdate, @@ -52,13 +53,9 @@ func resourceStorageAccountCustomerManagedKey() *pluginsdk.Resource { }, "key_vault_id": { - Type: pluginsdk.TypeString, - Optional: true, - ValidateFunc: validation.Any( - // TODO 4.0: revert to only accepting key vault IDs as there is an explicit attribute for managed HSMs - commonids.ValidateKeyVaultID, - managedhsms.ValidateManagedHSMID, - ), + Type: pluginsdk.TypeString, + Optional: true, + ValidateFunc: commonids.ValidateKeyVaultID, ExactlyOneOf: []string{"managed_hsm_key_id", "key_vault_id", "key_vault_uri"}, }, @@ -103,6 +100,15 @@ func resourceStorageAccountCustomerManagedKey() *pluginsdk.Resource { }, }, } + + if !features.FourPointOhBeta() { + resource.Schema["key_vault_id"].ValidateFunc = validation.Any( + commonids.ValidateKeyVaultID, + managedhsms.ValidateManagedHSMID, + ) + } + + return resource } func resourceStorageAccountCustomerManagedKeyCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) error { diff --git a/internal/services/storage/storage_account_data_source.go b/internal/services/storage/storage_account_data_source.go index 482972243ec0..d9a115624136 100644 --- a/internal/services/storage/storage_account_data_source.go +++ b/internal/services/storage/storage_account_data_source.go @@ -18,13 +18,14 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/go-azure-sdk/resource-manager/storage/2023-01-01/storageaccounts" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/features" "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" ) func dataSourceStorageAccount() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Read: dataSourceStorageAccountRead, Timeouts: &pluginsdk.ResourceTimeout{ @@ -77,8 +78,7 @@ func dataSourceStorageAccount() *pluginsdk.Resource { }, }, - // TODO 4.0: change this from enable_* to *_enabled - "enable_https_traffic_only": { + "https_traffic_only_enabled": { Type: pluginsdk.TypeBool, Computed: true, }, @@ -537,6 +537,15 @@ func dataSourceStorageAccount() *pluginsdk.Resource { "tags": commonschema.TagsDataSource(), }, } + + if !features.FourPointOhBeta() { + resource.Schema["enable_https_traffic_only"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeBool, + Computed: true, + } + } + + return resource } func dataSourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) error { @@ -602,12 +611,16 @@ func dataSourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) e if err := d.Set("custom_domain", flattenAccountCustomDomain(props.CustomDomain)); err != nil { return fmt.Errorf("setting `custom_domain`: %+v", err) } - d.Set("enable_https_traffic_only", pointer.From(props.SupportsHTTPSTrafficOnly)) + d.Set("https_traffic_only_enabled", pointer.From(props.SupportsHTTPSTrafficOnly)) d.Set("is_hns_enabled", pointer.From(props.IsHnsEnabled)) d.Set("nfsv3_enabled", pointer.From(props.IsNfsV3Enabled)) d.Set("primary_location", location.NormalizeNilable(props.PrimaryLocation)) d.Set("secondary_location", location.NormalizeNilable(props.SecondaryLocation)) + if !features.FourPointOhBeta() { + d.Set("enable_https_traffic_only", pointer.From(props.SupportsHTTPSTrafficOnly)) + } + // Setting the encryption key type to "Service" in PUT. The following GET will not return the queue/table in the service list of its response. // So defaults to setting the encryption key type to "Service" if it is absent in the GET response. Also, define the default value as "Service" in the schema. infrastructureEncryption := false diff --git a/internal/services/storage/storage_account_resource.go b/internal/services/storage/storage_account_resource.go index 04dbb3fd34cc..b1810c6ac9c4 100644 --- a/internal/services/storage/storage_account_resource.go +++ b/internal/services/storage/storage_account_resource.go @@ -64,7 +64,7 @@ var ( ) func resourceStorageAccount() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceStorageAccountCreate, Read: resourceStorageAccountRead, Update: resourceStorageAccountUpdate, @@ -259,8 +259,7 @@ func resourceStorageAccount() *pluginsdk.Resource { "edge_zone": commonschema.EdgeZoneOptionalForceNew(), - // TODO 4.0: change this from enable_* to *_enabled - "enable_https_traffic_only": { + "https_traffic_only_enabled": { Type: pluginsdk.TypeBool, Optional: true, Default: true, @@ -1260,6 +1259,20 @@ func resourceStorageAccount() *pluginsdk.Resource { }), ), } + + if !features.FourPointOhBeta() { + resource.Schema["https_traffic_only_enabled"].Computed = true + + resource.Schema["enable_https_traffic_only"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeBool, + Optional: true, + Computed: true, + ConflictsWith: []string{"https_traffic_only_enabled"}, + Deprecated: "The property `enable_https_traffic_only` has been superseded by `https_traffic_only_enabled` and will be removed in v4.0 of the AzureRM Provider.", + } + } + + return resource } func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -1298,6 +1311,14 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e return fmt.Errorf("expanding `identity`: %+v", err) } + httpsTrafficOnlyEnabled := d.Get("https_traffic_only_enabled").(bool) + if !features.FourPointOhBeta() { + // nolint staticcheck + if v, ok := d.GetOkExists("enable_https_traffic_only"); ok { + httpsTrafficOnlyEnabled = v.(bool) + } + } + dnsEndpointType := d.Get("dns_endpoint_type").(string) isHnsEnabled := d.Get("is_hns_enabled").(bool) nfsV3Enabled := d.Get("nfsv3_enabled").(bool) @@ -1312,7 +1333,7 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e AllowSharedKeyAccess: pointer.To(d.Get("shared_access_key_enabled").(bool)), DnsEndpointType: pointer.To(storageaccounts.DnsEndpointType(dnsEndpointType)), DefaultToOAuthAuthentication: pointer.To(d.Get("default_to_oauth_authentication").(bool)), - SupportsHTTPSTrafficOnly: pointer.To(d.Get("enable_https_traffic_only").(bool)), + SupportsHTTPSTrafficOnly: pointer.To(httpsTrafficOnlyEnabled), IsNfsV3Enabled: pointer.To(nfsV3Enabled), IsHnsEnabled: pointer.To(isHnsEnabled), IsLocalUserEnabled: pointer.To(d.Get("local_user_enabled").(bool)), @@ -1712,9 +1733,16 @@ func resourceStorageAccountUpdate(d *pluginsdk.ResourceData, meta interface{}) e if d.HasChange("default_to_oauth_authentication") { props.DefaultToOAuthAuthentication = pointer.To(d.Get("default_to_oauth_authentication").(bool)) } - if d.HasChange("enable_https_traffic_only") { - props.SupportsHTTPSTrafficOnly = pointer.To(d.Get("enable_https_traffic_only").(bool)) + + if d.HasChange("https_traffic_only_enabled") { + props.SupportsHTTPSTrafficOnly = pointer.To(d.Get("https_traffic_only_enabled").(bool)) + } + if !features.FourPointOhBeta() { + if d.HasChange("enable_https_traffic_only") { + props.SupportsHTTPSTrafficOnly = pointer.To(d.Get("enable_https_traffic_only").(bool)) + } } + if d.HasChange("large_file_share_enabled") { // largeFileSharesState can only be set to `Enabled` and not `Disabled`, even if it is currently `Disabled` if oldValue, newValue := d.GetChange("large_file_share_enabled"); oldValue.(bool) && !newValue.(bool) { @@ -2033,7 +2061,10 @@ func resourceStorageAccountRead(d *pluginsdk.ResourceData, meta interface{}) err return fmt.Errorf("setting `azure_files_authentication`: %+v", err) } d.Set("cross_tenant_replication_enabled", pointer.From(props.AllowCrossTenantReplication)) - d.Set("enable_https_traffic_only", pointer.From(props.SupportsHTTPSTrafficOnly)) + d.Set("https_traffic_only_enabled", pointer.From(props.SupportsHTTPSTrafficOnly)) + if !features.FourPointOhBeta() { + d.Set("enable_https_traffic_only", pointer.From(props.SupportsHTTPSTrafficOnly)) + } d.Set("is_hns_enabled", pointer.From(props.IsHnsEnabled)) d.Set("nfsv3_enabled", pointer.From(props.IsNfsV3Enabled)) d.Set("primary_location", pointer.From(props.PrimaryLocation)) diff --git a/internal/services/storage/storage_account_resource_test.go b/internal/services/storage/storage_account_resource_test.go index 09482f404dbc..47d499da777a 100644 --- a/internal/services/storage/storage_account_resource_test.go +++ b/internal/services/storage/storage_account_resource_test.go @@ -226,7 +226,7 @@ func TestAccStorageAccount_enableHttpsTrafficOnly(t *testing.T) { Config: r.enableHttpsTrafficOnly(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("enable_https_traffic_only").HasValue("true"), + check.That(data.ResourceName).Key("https_traffic_only_enabled").HasValue("true"), ), }, data.ImportStep(), @@ -234,7 +234,7 @@ func TestAccStorageAccount_enableHttpsTrafficOnly(t *testing.T) { Config: r.enableHttpsTrafficOnlyDisabled(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), - check.That(data.ResourceName).Key("enable_https_traffic_only").HasValue("false"), + check.That(data.ResourceName).Key("https_traffic_only_enabled").HasValue("false"), ), }, }) @@ -2049,10 +2049,10 @@ resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" - enable_https_traffic_only = true + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + https_traffic_only_enabled = true tags = { environment = "production" @@ -2076,10 +2076,10 @@ resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Standard" - account_replication_type = "LRS" - enable_https_traffic_only = false + location = azurerm_resource_group.test.location + account_tier = "Standard" + account_replication_type = "LRS" + https_traffic_only_enabled = false tags = { environment = "production" @@ -2198,13 +2198,13 @@ resource "azurerm_storage_account" "test" { name = "unlikely23exst2acct%s" resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_tier = "Premium" - account_kind = "BlockBlobStorage" - account_replication_type = "LRS" - is_hns_enabled = true - nfsv3_enabled = true - enable_https_traffic_only = false + location = azurerm_resource_group.test.location + account_tier = "Premium" + account_kind = "BlockBlobStorage" + account_replication_type = "LRS" + is_hns_enabled = true + nfsv3_enabled = true + https_traffic_only_enabled = false network_rules { default_action = "Deny" virtual_network_subnet_ids = [azurerm_subnet.test.id] @@ -3009,7 +3009,7 @@ resource "azurerm_storage_account" "test" { location = azurerm_resource_group.test.location account_tier = "Standard" account_replication_type = "LRS" - enable_https_traffic_only = true + https_traffic_only_enabled = true allow_nested_items_to_be_public = true blob_properties { @@ -3444,15 +3444,15 @@ resource "azurerm_resource_group" "test" { location = "%s" } resource "azurerm_storage_account" "test" { - name = "acctestsa%s" - resource_group_name = azurerm_resource_group.test.name - location = azurerm_resource_group.test.location - account_kind = "BlockBlobStorage" - account_tier = "Premium" - account_replication_type = "LRS" - is_hns_enabled = true - min_tls_version = "TLS1_2" - enable_https_traffic_only = true + name = "acctestsa%s" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + account_kind = "BlockBlobStorage" + account_tier = "Premium" + account_replication_type = "LRS" + is_hns_enabled = true + min_tls_version = "TLS1_2" + https_traffic_only_enabled = true } `, data.RandomInteger, data.Locations.Primary, data.RandomString) } diff --git a/internal/services/storage/storage_share_directory_resource.go b/internal/services/storage/storage_share_directory_resource.go index 162cb83b13ce..42412d484cde 100644 --- a/internal/services/storage/storage_share_directory_resource.go +++ b/internal/services/storage/storage_share_directory_resource.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "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/storage/client" "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/helpers" "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate" @@ -27,7 +28,7 @@ import ( ) func resourceStorageShareDirectory() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceStorageShareDirectoryCreate, Read: resourceStorageShareDirectoryRead, Update: resourceStorageShareDirectoryUpdate, @@ -54,39 +55,46 @@ func resourceStorageShareDirectory() *pluginsdk.Resource { }, "storage_share_id": { - Type: pluginsdk.TypeString, - Optional: true, // TODO: make required and forcenew in v4.0 - Computed: true, // TODO: remove computed in v4.0 - ForceNew: true, - ConflictsWith: []string{"share_name", "storage_account_name"}, - ValidateFunc: storageValidate.StorageShareDataPlaneID, - }, - - "share_name": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - Deprecated: "the `share_name` and `storage_account_name` properties have been superseded by the `storage_share_id` property and will be removed in version 4.0 of the AzureRM provider", - ConflictsWith: []string{"storage_share_id"}, - RequiredWith: []string{"storage_account_name"}, - ValidateFunc: validation.StringIsNotEmpty, - }, - - "storage_account_name": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - Deprecated: "the `share_name` and `storage_account_name` properties have been superseded by the `storage_share_id` property and will be removed in version 4.0 of the AzureRM provider", - ConflictsWith: []string{"storage_share_id"}, - RequiredWith: []string{"share_name"}, - ValidateFunc: validation.StringIsNotEmpty, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: storageValidate.StorageShareDataPlaneID, }, "metadata": MetaDataSchema(), }, } + + if !features.FourPointOhBeta() { + resource.Schema["storage_share_id"].Required = false + resource.Schema["storage_share_id"].Optional = true + resource.Schema["storage_share_id"].Computed = true + resource.Schema["storage_share_id"].ConflictsWith = []string{"share_name", "storage_account_name"} + + resource.Schema["storage_account_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + Deprecated: "the `share_name` and `storage_account_name` properties have been superseded by the `storage_share_id` property and will be removed in version 4.0 of the AzureRM provider", + ConflictsWith: []string{"storage_share_id"}, + RequiredWith: []string{"share_name"}, + ValidateFunc: validation.StringIsNotEmpty, + } + + resource.Schema["share_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + Deprecated: "the `share_name` and `storage_account_name` properties have been superseded by the `storage_share_id` property and will be removed in version 4.0 of the AzureRM provider", + ConflictsWith: []string{"storage_share_id"}, + RequiredWith: []string{"storage_account_name"}, + ValidateFunc: validation.StringIsNotEmpty, + } + } + + return resource } func resourceStorageShareDirectoryCreate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -106,8 +114,7 @@ func resourceStorageShareDirectoryCreate(d *pluginsdk.ResourceData, meta interfa if err != nil { return err } - } else { - + } else if !features.FourPointOhBeta() { // TODO: this is needed until `share_name` / `storage_account_name` are removed in favor of `storage_share_id` in v4.0 // we will retrieve the storage account twice but this will make it easier to refactor later storageAccountName := d.Get("storage_account_name").(string) @@ -278,8 +285,11 @@ func resourceStorageShareDirectoryRead(d *pluginsdk.ResourceData, meta interface d.Set("name", id.DirectoryPath) d.Set("storage_share_id", storageShareId.ID()) - d.Set("share_name", id.ShareName) - d.Set("storage_account_name", id.AccountId.AccountName) + + if !features.FourPointOhBeta() { + d.Set("storage_account_name", id.AccountId.AccountName) + d.Set("share_name", id.ShareName) + } if err = d.Set("metadata", FlattenMetaData(props.MetaData)); err != nil { return fmt.Errorf("setting `metadata`: %v", err) diff --git a/internal/services/storage/storage_share_directory_resource_test.go b/internal/services/storage/storage_share_directory_resource_test.go index adeac89208e9..49b5790d4af5 100644 --- a/internal/services/storage/storage_share_directory_resource_test.go +++ b/internal/services/storage/storage_share_directory_resource_test.go @@ -12,6 +12,7 @@ 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" "github.com/tombuildsstuff/giovanni/storage/2023-11-03/file/directories" @@ -51,6 +52,10 @@ func TestAccStorageShareDirectory_basicAzureADAuth(t *testing.T) { func TestAccStorageShareDirectory_basicDeprecated(t *testing.T) { // TODO: remove test in v4.0 + if features.FourPointOhBeta() { + t.Skip("test not applicable in v4.0") + } + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") r := StorageShareDirectoryResource{} @@ -67,6 +72,10 @@ func TestAccStorageShareDirectory_basicDeprecated(t *testing.T) { func TestAccStorageShareDirectory_migrateStorageShareId(t *testing.T) { // TODO: remove test in v4.0 + if features.FourPointOhBeta() { + t.Skip("test not applicable in v4.0") + } + data := acceptance.BuildTestData(t, "azurerm_storage_share_directory", "test") r := StorageShareDirectoryResource{} @@ -269,6 +278,7 @@ resource "azurerm_storage_share_directory" "test" { } func (r StorageShareDirectoryResource) basicDeprecated(data acceptance.TestData) string { + // TODO: remove in v4.0 template := r.template(data) return fmt.Sprintf(` %s diff --git a/internal/services/storage/storage_table_entity_resource.go b/internal/services/storage/storage_table_entity_resource.go index e093b40cf514..75940cd0b94a 100644 --- a/internal/services/storage/storage_table_entity_resource.go +++ b/internal/services/storage/storage_table_entity_resource.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/go-azure-helpers/lang/response" "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/storage/client" "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/helpers" "github.com/hashicorp/terraform-provider-azurerm/internal/services/storage/validate" @@ -26,7 +27,7 @@ import ( ) func resourceStorageTableEntity() *pluginsdk.Resource { - return &pluginsdk.Resource{ + resource := &pluginsdk.Resource{ Create: resourceStorageTableEntityCreate, Read: resourceStorageTableEntityRead, Update: resourceStorageTableEntityUpdate, @@ -46,31 +47,9 @@ func resourceStorageTableEntity() *pluginsdk.Resource { Schema: map[string]*pluginsdk.Schema{ "storage_table_id": { - Type: pluginsdk.TypeString, - Optional: true, // TODO: make required and forcenew in v4.0 - Computed: true, // TODO: remove computed in v4.0 - ConflictsWith: []string{"table_name", "storage_account_name"}, - ValidateFunc: storageValidate.StorageTableDataPlaneID, - }, - - "table_name": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - Deprecated: "the `table_name` and `storage_account_name` properties have been superseded by the `storage_table_id` property and will be removed in version 4.0 of the AzureRM provider", - ConflictsWith: []string{"storage_table_id"}, - RequiredWith: []string{"storage_account_name"}, - ValidateFunc: validate.StorageTableName, - }, - - "storage_account_name": { - Type: pluginsdk.TypeString, - Optional: true, - Computed: true, - Deprecated: "the `table_name` and `storage_account_name` properties have been superseded by the `storage_table_id` property and will be removed in version 4.0 of the AzureRM provider", - ConflictsWith: []string{"storage_table_id"}, - RequiredWith: []string{"table_name"}, - ValidateFunc: validate.StorageAccountName, + Type: pluginsdk.TypeString, + Required: true, + ValidateFunc: storageValidate.StorageTableDataPlaneID, }, "partition_key": { @@ -96,6 +75,34 @@ func resourceStorageTableEntity() *pluginsdk.Resource { }, }, } + + if !features.FourPointOhBeta() { + resource.Schema["storage_table_id"].Optional = true + resource.Schema["storage_table_id"].Computed = true + resource.Schema["storage_table_id"].ConflictsWith = []string{"table_name", "storage_account_name"} + + resource.Schema["table_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + Deprecated: "the `table_name` and `storage_account_name` properties have been superseded by the `storage_table_id` property and will be removed in version 4.0 of the AzureRM provider", + ConflictsWith: []string{"storage_table_id"}, + RequiredWith: []string{"storage_account_name"}, + ValidateFunc: validate.StorageTableName, + } + + resource.Schema["storage_account_name"] = &pluginsdk.Schema{ + Type: pluginsdk.TypeString, + Optional: true, + Computed: true, + Deprecated: "the `table_name` and `storage_account_name` properties have been superseded by the `storage_table_id` property and will be removed in version 4.0 of the AzureRM provider", + ConflictsWith: []string{"storage_table_id"}, + RequiredWith: []string{"table_name"}, + ValidateFunc: validate.StorageAccountName, + } + } + + return resource } func resourceStorageTableEntityCreate(d *pluginsdk.ResourceData, meta interface{}) error { @@ -114,7 +121,7 @@ func resourceStorageTableEntityCreate(d *pluginsdk.ResourceData, meta interface{ if err != nil { return err } - } else { + } else if !features.FourPointOhBeta() { // TODO: this is needed until `table_name` / `storage_account_name` are removed in favor of `storage_table_id` in v4.0 // we will retrieve the storage account twice but this will make it easier to refactor later storageAccountName := d.Get("storage_account_name").(string) @@ -280,11 +287,14 @@ func resourceStorageTableEntityRead(d *pluginsdk.ResourceData, meta interface{}) } d.Set("storage_table_id", storageTableId.ID()) - d.Set("storage_account_name", id.AccountId.AccountName) - d.Set("table_name", id.TableName) d.Set("partition_key", id.PartitionKey) d.Set("row_key", id.RowKey) + if !features.FourPointOhBeta() { + d.Set("storage_account_name", id.AccountId.AccountName) + d.Set("table_name", id.TableName) + } + if err = d.Set("entity", flattenEntity(result.Entity)); err != nil { return fmt.Errorf("setting `entity` for %s: %v", id, err) } diff --git a/internal/services/storage/storage_table_entity_resource_test.go b/internal/services/storage/storage_table_entity_resource_test.go index 643882e3891a..0cdefd10acef 100644 --- a/internal/services/storage/storage_table_entity_resource_test.go +++ b/internal/services/storage/storage_table_entity_resource_test.go @@ -12,6 +12,7 @@ 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" "github.com/tombuildsstuff/giovanni/storage/2023-11-03/table/entities" @@ -51,6 +52,10 @@ func TestAccTableEntity_basicAzureADAuth(t *testing.T) { func TestAccTableEntity_basicDeprecated(t *testing.T) { // TODO: remove test in v4.0 + if features.FourPointOhBeta() { + t.Skip("test not applicable in v4.0") + } + data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test") r := StorageTableEntityResource{} @@ -67,6 +72,10 @@ func TestAccTableEntity_basicDeprecated(t *testing.T) { func TestAccTableEntity_migrateStorageTableId(t *testing.T) { // TODO: remove test in v4.0 + if features.FourPointOhBeta() { + t.Skip("test not applicable in v4.0") + } + data := acceptance.BuildTestData(t, "azurerm_storage_table_entity", "test") r := StorageTableEntityResource{} From e043d466a44cb30abd0abe0bc81afb898a2c1809 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Tue, 23 Jul 2024 11:51:43 +0100 Subject: [PATCH 2/4] storage: document deprecated properties for v4.0 --- website/docs/d/storage_account.html.markdown | 2 +- website/docs/r/storage_account.html.markdown | 2 +- .../docs/r/storage_account_customer_managed_key.html.markdown | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/website/docs/d/storage_account.html.markdown b/website/docs/d/storage_account.html.markdown index 1f8b3ff08ec7..c36dc341e873 100644 --- a/website/docs/d/storage_account.html.markdown +++ b/website/docs/d/storage_account.html.markdown @@ -47,7 +47,7 @@ output "storage_account_tier" { * `dns_endpoint_type` - Which DNS endpoint type is used - either `Standard` or `AzureDnsZone`. -* `enable_https_traffic_only` - Is traffic only allowed via HTTPS? See [here](https://docs.microsoft.com/azure/storage/storage-require-secure-transfer/) +* `https_traffic_only_enabled` - Is traffic only allowed via HTTPS? See [here](https://docs.microsoft.com/azure/storage/storage-require-secure-transfer/) for more information. * `min_tls_version` - The minimum supported TLS version for this storage account. diff --git a/website/docs/r/storage_account.html.markdown b/website/docs/r/storage_account.html.markdown index 909894b398dd..9ae18a6cb400 100644 --- a/website/docs/r/storage_account.html.markdown +++ b/website/docs/r/storage_account.html.markdown @@ -100,7 +100,7 @@ The following arguments are supported: * `edge_zone` - (Optional) Specifies the Edge Zone within the Azure Region where this Storage Account should exist. Changing this forces a new Storage Account to be created. -* `enable_https_traffic_only` - (Optional) Boolean flag which forces HTTPS if enabled, see [here](https://docs.microsoft.com/azure/storage/storage-require-secure-transfer/) for more information. Defaults to `true`. +* `https_traffic_only_enabled` - (Optional) Boolean flag which forces HTTPS if enabled, see [here](https://docs.microsoft.com/azure/storage/storage-require-secure-transfer/) for more information. Defaults to `true`. * `min_tls_version` - (Optional) The minimum supported TLS version for the storage account. Possible values are `TLS1_0`, `TLS1_1`, and `TLS1_2`. Defaults to `TLS1_2` for new storage accounts. diff --git a/website/docs/r/storage_account_customer_managed_key.html.markdown b/website/docs/r/storage_account_customer_managed_key.html.markdown index 32f07379e83b..34e90a39c486 100644 --- a/website/docs/r/storage_account_customer_managed_key.html.markdown +++ b/website/docs/r/storage_account_customer_managed_key.html.markdown @@ -129,7 +129,6 @@ The following arguments are supported: ~> Note: When the principal running Terraform has access to the subscription containing the Key Vault, it's recommended to use the `key_vault_id` property for maximum compatibility, rather than the `key_vault_uri` property. - * `key_vault_uri` - (Optional) URI pointing at the Key Vault. Required when using `federated_identity_client_id`. Exactly one of `managed_hsm_key_id`, `key_vault_id`, or `key_vault_uri` must be specified. * `managed_hsm_key_id` - (Optional) Key ID of a key in a managed HSM. Exactly one of `managed_hsm_key_id`, `key_vault_id`, or `key_vault_uri` must be specified. From ad55a2672d8efef34acf5614a191d052810403ba Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Wed, 24 Jul 2024 14:20:23 +0100 Subject: [PATCH 3/4] azurerm_storage_account: fix v3.x schema --- internal/services/storage/storage_account_resource.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/internal/services/storage/storage_account_resource.go b/internal/services/storage/storage_account_resource.go index b1810c6ac9c4..eeaab9368496 100644 --- a/internal/services/storage/storage_account_resource.go +++ b/internal/services/storage/storage_account_resource.go @@ -1262,6 +1262,7 @@ func resourceStorageAccount() *pluginsdk.Resource { if !features.FourPointOhBeta() { resource.Schema["https_traffic_only_enabled"].Computed = true + resource.Schema["https_traffic_only_enabled"].Default = nil resource.Schema["enable_https_traffic_only"] = &pluginsdk.Schema{ Type: pluginsdk.TypeBool, @@ -1311,8 +1312,11 @@ func resourceStorageAccountCreate(d *pluginsdk.ResourceData, meta interface{}) e return fmt.Errorf("expanding `identity`: %+v", err) } - httpsTrafficOnlyEnabled := d.Get("https_traffic_only_enabled").(bool) - if !features.FourPointOhBeta() { + httpsTrafficOnlyEnabled := true + // nolint staticcheck + if v, ok := d.GetOkExists("https_traffic_only_enabled"); ok { + httpsTrafficOnlyEnabled = v.(bool) + } else if !features.FourPointOhBeta() { // nolint staticcheck if v, ok := d.GetOkExists("enable_https_traffic_only"); ok { httpsTrafficOnlyEnabled = v.(bool) From c9e4fcd5021c5348b106353d6f16b4ebc1b82df0 Mon Sep 17 00:00:00 2001 From: Tom Bamford Date: Wed, 24 Jul 2024 14:21:40 +0100 Subject: [PATCH 4/4] azurerm_storage_table_entity: fix v3.x schema --- internal/services/storage/storage_table_entity_resource.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/services/storage/storage_table_entity_resource.go b/internal/services/storage/storage_table_entity_resource.go index 75940cd0b94a..355abba6422a 100644 --- a/internal/services/storage/storage_table_entity_resource.go +++ b/internal/services/storage/storage_table_entity_resource.go @@ -77,6 +77,7 @@ func resourceStorageTableEntity() *pluginsdk.Resource { } if !features.FourPointOhBeta() { + resource.Schema["storage_table_id"].Required = false resource.Schema["storage_table_id"].Optional = true resource.Schema["storage_table_id"].Computed = true resource.Schema["storage_table_id"].ConflictsWith = []string{"table_name", "storage_account_name"}