Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_cosmosdb_postgresql_cluster: add server names information t… #25240

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:"server_names"`
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,
},
"server_names": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can shorten this to servers, _names is implicit and one of the attributes in the block is already called name

Suggested change
"server_names": {
"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 = formatServerNames(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,19 @@ func flattenMaintenanceWindow(input *clusters.MaintenanceWindow) []MaintenanceWi
},
}
}

func formatServerNames(input *[]clusters.ServerNameItem) []ServerNameItem {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but for consistency could we rename this to

Suggested change
func formatServerNames(input *[]clusters.ServerNameItem) []ServerNameItem {
func flattenServerNames(input *[]clusters.ServerNameItem) []ServerNameItem {

if input == nil {
return nil
}

var output []ServerNameItem
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be setting an empty value into state instead of nil here

Suggested change
if input == nil {
return nil
}
var output []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("server_names.0.fqdn").IsNotEmpty(),
check.That(data.ResourceName).Key("server_names.0.name").IsNotEmpty(),
),
},
data.ImportStep("administrator_login_password"),
Expand Down
2 changes: 2 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,8 @@ 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.

* `server_names` - The name of the servers and its fully qualified domain name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a block it should be

Suggested change
* `server_names` - The name of the servers and its fully qualified domain name
* `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