Skip to content

Commit

Permalink
azurerm_cosmosdb_postgresql_cluster: add server names information t… (
Browse files Browse the repository at this point in the history
#25240)

* `azurerm_cosmosdb_postgresql_cluster`: add server names information to attributes

* `azurerm_cosmosdb_postgresql_cluster`: fix naming convention and wrong nil handling
  • Loading branch information
reastyn authored Mar 15, 2024
1 parent 2cdbe51 commit eddb603
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/services/cosmos/cosmosdb_postgresql_cluster_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type CosmosDbPostgreSQLClusterModel struct {
SourceLocation string `tfschema:"source_location"`
SourceResourceId string `tfschema:"source_resource_id"`
MaintenanceWindow []MaintenanceWindow `tfschema:"maintenance_window"`
ServerNames []ServerNameItem `tfschema:"servers"`
NodeCount int64 `tfschema:"node_count"`
NodePublicIPAccessEnabled bool `tfschema:"node_public_ip_access_enabled"`
NodeServerEdition string `tfschema:"node_server_edition"`
Expand All @@ -48,6 +49,11 @@ type CosmosDbPostgreSQLClusterModel struct {
EarliestRestoreTime string `tfschema:"earliest_restore_time"`
}

type ServerNameItem struct {
Name string `tfschema:"name"`
FullyQualifiedDomainName string `tfschema:"fqdn"`
}

type MaintenanceWindow struct {
DayOfWeek int64 `tfschema:"day_of_week"`
StartHour int64 `tfschema:"start_hour"`
Expand Down Expand Up @@ -304,6 +310,22 @@ func (r CosmosDbPostgreSQLClusterResource) Attributes() map[string]*pluginsdk.Sc
Type: pluginsdk.TypeString,
Computed: true,
},
"servers": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"fqdn": {
Type: pluginsdk.TypeString,
Computed: true,
},
"name": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
},
},
}
}

Expand Down Expand Up @@ -558,6 +580,7 @@ func (r CosmosDbPostgreSQLClusterResource) Read() sdk.ResourceFunc {
state.CoordinatorServerEdition = pointer.From(props.CoordinatorServerEdition)
state.CoordinatorStorageQuotaInMb = pointer.From(props.CoordinatorStorageQuotaInMb)
state.CoordinatorVCoreCount = pointer.From(props.CoordinatorVCores)
state.ServerNames = flattenServerNames(props.ServerNames)
state.HaEnabled = pointer.From(props.EnableHa)
state.NodeCount = pointer.From(props.NodeCount)
state.NodePublicIPAccessEnabled = pointer.From(props.NodeEnablePublicIPAccess)
Expand Down Expand Up @@ -636,3 +659,20 @@ func flattenMaintenanceWindow(input *clusters.MaintenanceWindow) []MaintenanceWi
},
}
}

func flattenServerNames(input *[]clusters.ServerNameItem) []ServerNameItem {
var output []ServerNameItem

if input == nil {
return output
}

for _, v := range *input {
output = append(output, ServerNameItem{
FullyQualifiedDomainName: *v.FullyQualifiedDomainName,
Name: *v.Name,
})
}

return output
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func TestAccCosmosDbPostgreSQLCluster_basic(t *testing.T) {
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("servers.0.fqdn").IsNotEmpty(),
check.That(data.ResourceName).Key("servers.0.name").IsNotEmpty(),
),
},
data.ImportStep("administrator_login_password"),
Expand Down
10 changes: 10 additions & 0 deletions website/docs/r/cosmosdb_postgresql_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `earliest_restore_time` - The earliest restore point time (ISO8601 format) for the Azure Cosmos DB for PostgreSQL Cluster.

* `servers` - A `servers` block as defined below.

---

A `servers` block exports the following:

* `fqdn` - The Fully Qualified Domain Name of the server.

* `name` - The name of the server.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
Expand Down

0 comments on commit eddb603

Please sign in to comment.