Skip to content

azurerm_postgresql_flexible_server: add support for cluster#31315

Merged
mbfrahry merged 12 commits intohashicorp:mainfrom
wuxu92:pg-flexible-server-cluster
Feb 6, 2026
Merged

azurerm_postgresql_flexible_server: add support for cluster#31315
mbfrahry merged 12 commits intohashicorp:mainfrom
wuxu92:pg-flexible-server-cluster

Conversation

@wuxu92
Copy link
Collaborator

@wuxu92 wuxu92 commented Dec 8, 2025

Community Note

  • Please vote on this PR by adding a 👍 reaction to the original PR to help the community and maintainers prioritize for review
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for PR followers and do not help prioritize for review

Description

https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/concepts-elastic-clusters

some items confirmed from service team but not mentioned in swagger or product doc:

  1. the elastic cluster only support PG 17+, and can't do major version upgrade if enabled
  2. only support to increase of cluster size, can't decrease it
  3. there is a server side validation on the cluster size, currently it 1-20, but the server team plans to going up to 32 in a few months
  4. the default server name is not configurable in Azure Portal and it can't be changed once set.

PR Checklist

  • I have followed the guidelines in our Contributing Documentation.
  • I have checked to ensure there aren't other open Pull Requests for the same update/change.
  • I have checked if my changes close any open issues. If so please include appropriate closing keywords below.
  • I have updated/added Documentation as required written in a helpful and kind way to assist users that may be unfamiliar with the resource / data source.
  • I have used a meaningful PR title to help maintainers and other users understand this change and help prevent duplicate work.
    For example: “resource_name_here - description of change e.g. adding property new_property_name_here

Changes to existing Resource / Data Source

  • I have added an explanation of what my changes do and why I'd like you to include them (This may be covered by linking to an issue above, but may benefit from additional explanation).
  • I have written new tests for my resource or datasource changes & updated any relevant documentation.
  • I have successfully run tests with my changes locally. If not, please provide details on testing challenges that prevented you running the tests.
  • (For changes that include a state migration only). I have manually tested the migration path between relevant versions of the provider.

Testing

  • My submission includes Test coverage as described in the Contribution Guide and the tests pass. (if this is not possible for any reason, please include details of why you did or could not add test coverage)
--- PASS: TestAccPostgresqlFlexibleServer_cluster (917.55s)
PASS
ok      github.com/hashicorp/terraform-provider-azurerm/internal/services/pos
image

Change Log

Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.

  • azurerm_postgresql_flexible_server - support for the cluster property

This is a (please select all that apply):

  • Bug Fix
  • New Feature (ie adding a service, resource, or data source)
  • Enhancement
  • Breaking Change

Related Issue(s)

Fixes #31212

AI Assistance Disclosure

  • AI Assisted - This contribution was made by, or with the assistance of, AI/LLMs

Rollback Plan

If a change needs to be reverted, we will publish an updated version of the provider.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.

Note

If this PR changes meaningfully during the course of review please update the title and description as required.

@wuxu92 wuxu92 marked this pull request as ready for review December 9, 2025 03:35
@wuxu92 wuxu92 requested review from a team, WodansSon and magodo as code owners December 9, 2025 03:35
@wuxu92 wuxu92 marked this pull request as draft December 9, 2025 22:21
@wuxu92 wuxu92 marked this pull request as ready for review December 10, 2025 03:04
@wuxu92 wuxu92 requested a review from teowa December 10, 2025 04:01
Copy link
Collaborator

@teowa teowa left a comment

Choose a reason for hiding this comment

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

Hi @wuxu92, thank you for the PR. There are a few issues below that may need your attention. Otherwise, it looks good to me.

@teowa
Copy link
Collaborator

teowa commented Dec 10, 2025

Thanks @wuxu92 , LGTM!

magodo
magodo previously requested changes Dec 12, 2025
Copy link
Collaborator

@magodo magodo left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!
I have left some additional mostly minor comments that once addressed this should be good to merge 👍

@magodo
Copy link
Collaborator

magodo commented Dec 15, 2025

Thanks! LGTM!

@ProbstenHias
Copy link

ProbstenHias commented Jan 27, 2026

@wuxu92
Hi
Are you still working on this feauture?
With cosmosdb posgres being depreated, we are really looking forward to this feature!

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

Hey @wuxu92, this PR looks great but left some comments around some potential issues


versionOld, versionNew := diff.GetChange("version")
// version should be set since cluster only support pg17+
if version, err := strconv.ParseInt(versionNew.(string), 10, 32); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

This is great since the API errors but doesn't really explain why

│ Message: "Unsupported value \"12\" for parameter PGServerVersion"

// Confirmed with service team: the max size will be 32 whilst current is 20
ValidateFunc: validation.IntBetween(1, 32),
},
"default_database_name": {
Copy link
Member

Choose a reason for hiding this comment

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

It looks like a database name is provided for this if not specifed. Let's Default this to postgres

 ~ cluster {
          - default_database_name = "postgres" -> null
            # (1 unchanged attribute hidden)
        }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the heads-up, schema updated


"cluster": {
Type: pluginsdk.TypeList,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

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

This should be ForceNew since we can't add it after it's created or remove it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

newClusterObj := newCluster.([]interface{})
if len(oldClusterObj) > 0 && len(newClusterObj) > 0 {
// below type assertions are safe since schema ensure the types
oldClusterSize := oldClusterObj[0].(map[string]interface{})["size"].(int)
Copy link
Member

Choose a reason for hiding this comment

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

These can panic since we're only checking the length of oldClusterObj. Unfortunately, the following type assertions aren't safe because Terraform can set any of the following to nil. So we should take the time to ensure it's not nil before casting.

if len(input) == 0 {
return nil
}
v := input[0].(map[string]interface{})
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 a nil check when we check the len(input) to prevent a potential panic

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, nil check added.

"size": {
Type: pluginsdk.TypeInt,
Required: true,
// Confirmed with service team: the max size will be 32 whilst current is 20
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 causes an error from the api side, we should look to lock this to 20 until they add it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

validate updated

}

// can't downgrade cluster size
oldCluster, newCluster := diff.GetChange("cluster")
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 wrap this block in diff.HasChange("cluster") so we don't do these checks unless the cluster has changed

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

got it, updated.

Copy link
Member

@mbfrahry mbfrahry left a comment

Choose a reason for hiding this comment

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

LGTM!

@mbfrahry mbfrahry added this to the v4.60.0 milestone Feb 6, 2026
@mbfrahry mbfrahry dismissed magodo’s stale review February 6, 2026 23:01

Review addressed

@mbfrahry mbfrahry merged commit 3792f53 into hashicorp:main Feb 6, 2026
38 checks passed
@rapiccolo
Copy link

Hi @mbfrahry, Is this gonna be available in which version of the azurerm provider? Thanks!

anurag-hashicorp pushed a commit to anurag-hashicorp/terraform-provider-azurerm that referenced this pull request Feb 19, 2026
…icorp#31315)

[ENHANCEMENT] `azurerm_postgresql_flexible_server` - add support for `cluster`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for Elastic clusters in Azure Database for PostgreSQL

7 participants