Skip to content

Commit

Permalink
storage: remove deprecated properties for v4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
manicminer committed Jul 24, 2024
1 parent e7ae70c commit f3c23e3
Show file tree
Hide file tree
Showing 8 changed files with 197 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -25,7 +26,7 @@ import (
)

func resourceStorageAccountCustomerManagedKey() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceStorageAccountCustomerManagedKeyCreateUpdate,
Read: resourceStorageAccountCustomerManagedKeyRead,
Update: resourceStorageAccountCustomerManagedKeyCreateUpdate,
Expand All @@ -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"},
},

Expand Down Expand Up @@ -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 {
Expand Down
21 changes: 17 additions & 4 deletions internal/services/storage/storage_account_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
45 changes: 38 additions & 7 deletions internal/services/storage/storage_account_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var (
)

func resourceStorageAccount() *pluginsdk.Resource {
return &pluginsdk.Resource{
resource := &pluginsdk.Resource{
Create: resourceStorageAccountCreate,
Read: resourceStorageAccountRead,
Update: resourceStorageAccountUpdate,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)),
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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))
Expand Down
54 changes: 27 additions & 27 deletions internal/services/storage/storage_account_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,15 @@ 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(),
{
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"),
),
},
})
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down
Loading

0 comments on commit f3c23e3

Please sign in to comment.