Skip to content

Commit

Permalink
Update postgres flexserver api version to 2021-06-01
Browse files Browse the repository at this point in the history
- set attribute cmk_enabled to deprecated and empty value
- update documentation set `cmk_enabled` to deprecated
- add test to check that `cmk_enabled` is empty
- secure pointer dereferences
  • Loading branch information
Nick Metz committed Jul 6, 2021
1 parent 81e12e2 commit 2bd9717
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ func dataSourcePostgresqlFlexibleServer() *pluginsdk.Resource {
Computed: true,
},

"cmk_enabled": {
Type: pluginsdk.TypeString,
Computed: true,
Deprecated: "This attribute has been removed from the API and will be removed in version 3.0 of the provider.",
},

"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -101,16 +107,27 @@ func dataSourceArmPostgresqlFlexibleServerRead(d *pluginsdk.ResourceData, meta i
d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))

// `cmk_enabled` has been removed from API since 2021-06-01
// and should be removed in version 3.0 of the provider.
d.Set("cmk_enabled", "")

if props := resp.ServerProperties; props != nil {
d.Set("administrator_login", props.AdministratorLogin)
d.Set("storage_mb", (*props.Storage.StorageSizeGB * 1024))
d.Set("version", props.Version)
d.Set("fqdn", props.FullyQualifiedDomainName)
d.Set("public_network_access_enabled", props.Network.PublicNetworkAccess == postgresqlflexibleservers.ServerPublicNetworkAccessStateEnabled)
d.Set("backup_retention_days", props.Backup.BackupRetentionDays)

if props.Network.DelegatedSubnetResourceID != nil {
d.Set("delegated_subnet_id", props.Network.DelegatedSubnetResourceID)
if storage := props.Storage; storage != nil && storage.StorageSizeGB != nil {
d.Set("storage_mb", (*props.Storage.StorageSizeGB * 1024))
}

if backup := props.Backup; backup != nil {
d.Set("backup_retention_days", props.Backup.BackupRetentionDays)
}

if network := props.Network; network != nil {
d.Set("delegated_subnet_id", network.DelegatedSubnetResourceID)
d.Set("public_network_access_enabled", network.PublicNetworkAccess == postgresqlflexibleservers.ServerPublicNetworkAccessStateEnabled)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestAccDataSourcePostgresqlflexibleServer_basic(t *testing.T) {
check.That(data.ResourceName).Key("backup_retention_days").Exists(),
check.That(data.ResourceName).Key("fqdn").Exists(),
check.That(data.ResourceName).Key("public_network_access_enabled").Exists(),
check.That(data.ResourceName).Key("cmk_enabled").IsEmpty(),
),
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ func resourcePostgresqlFlexibleServer() *pluginsdk.Resource {
ValidateFunc: validation.IntBetween(7, 35),
},

"cmk_enabled": {
Type: pluginsdk.TypeString,
Computed: true,
Deprecated: "This attribute has been removed from the API and will be removed in version 3.0 of the provider.",
},

"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -330,26 +336,27 @@ func resourcePostgresqlFlexibleServerRead(d *pluginsdk.ResourceData, meta interf
d.Set("name", id.Name)
d.Set("resource_group_name", id.ResourceGroup)
d.Set("location", location.NormalizeNilable(resp.Location))

// `cmk_enabled` has been removed from API since 2021-06-01
// and should be removed in version 3.0 of the provider.
d.Set("cmk_enabled", "")

if props := resp.ServerProperties; props != nil {
d.Set("administrator_login", props.AdministratorLogin)
d.Set("zone", props.AvailabilityZone)
d.Set("version", props.Version)
d.Set("fqdn", props.FullyQualifiedDomainName)
d.Set("public_network_access_enabled", props.Network.PublicNetworkAccess == postgresqlflexibleservers.ServerPublicNetworkAccessStateEnabled)

if props.SourceServerResourceID != nil {
d.Set("source_server_id", props.SourceServerResourceID)
}

if props.Network.DelegatedSubnetResourceID != nil {
d.Set("delegated_subnet_id", props.Network.DelegatedSubnetResourceID)
if network := props.Network; network != nil {
d.Set("public_network_access_enabled", network.PublicNetworkAccess == postgresqlflexibleservers.ServerPublicNetworkAccessStateEnabled)
d.Set("delegated_subnet_id", network.DelegatedSubnetResourceID)
}

if err := d.Set("maintenance_window", flattenArmServerMaintenanceWindow(props.MaintenanceWindow)); err != nil {
return fmt.Errorf("setting `maintenance_window`: %+v", err)
}

if storage := props.Storage; storage != nil {
if storage := props.Storage; storage != nil && storage.StorageSizeGB != nil {
d.Set("storage_mb", (*storage.StorageSizeGB * 1024))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestAccPostgresqlflexibleServer_basic(t *testing.T) {
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("zone").Exists(),
check.That(data.ResourceName).Key("cmk_enabled").IsEmpty(),
check.That(data.ResourceName).Key("fqdn").Exists(),
check.That(data.ResourceName).Key("public_network_access_enabled").Exists(),
),
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `backup_retention_days` - The backup retention days for the PostgreSQL Flexible Server.

* `cmk_enabled` - The status showing whether the data encryption is enabled with a customer-managed key.

~> **Note:** Attribute `cmk_enabled` has been deprecated and will be removed in version 3.0 of the provider.

* `delegated_subnet_id` - The ID of the virtual network subnet to create the PostgreSQL Flexible Server.

* `fqdn` - The FQDN of the PostgreSQL Flexible Server.
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/postgresql_flexible_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `id` - The ID of the PostgreSQL Flexible Server.

* `cmk_enabled` - The status showing whether the data encryption is enabled with a customer-managed key.

~> **Note:** Attribute `cmk_enabled` has been deprecated and will be removed in version 3.0 of the provider.

* `fqdn` - The FQDN of the PostgreSQL Flexible Server.

* `public_network_access_enabled` - Is public network access enabled?
Expand Down

0 comments on commit 2bd9717

Please sign in to comment.