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_postgres_server: support for replicaset scaling #10754

Conversation

aristosvo
Copy link
Collaborator

@aristosvo aristosvo commented Feb 26, 2021

Fixes #10284

Implementation

  • Lock based on (primary) database server id to prevent replica from updating until primary is completed
  • Checks if SKU has changed and if its an scale-up
    • Update of SKU of both the replicas and primary based on scale-up changes in the primary. This is done by a lookup of all the replicas and SKU scale-up of these
  • AccTest which scales up and down successfully

@ghost ghost added size/S size/L and removed size/S labels Feb 26, 2021
@aristosvo aristosvo changed the title AccTest for replicaset scaling azurerm_postgres_server: support for replicaset scaling Feb 27, 2021
@aristosvo aristosvo force-pushed the feature/postgres-primary-secondary-scaling branch from 9ead6e0 to 2879ac3 Compare February 27, 2021 17:14
@NillsF
Copy link
Contributor

NillsF commented Feb 28, 2021

I ran the tests that @aristosvo created, and the tests are failing for me.

I tried debugging the failures and some other tests in the TestAccPostgreSQLServer also failed for me. I'm getting mixed results. Not sure if the issue is on my side or in the TF provider.

Full results of my tests below:

~/terraform-provider-azurerm$ TF_ACC=1 go test -v ./azurerm/internal/services/postgres/ -run=TestAccPostgreSQLServer_* -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2021/02/27 23:36:07 [DEBUG] not using binary driver name, it's no longer needed
2021/02/27 23:36:07 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccPostgreSQLServerKey_basic
=== PAUSE TestAccPostgreSQLServerKey_basic
=== RUN   TestAccPostgreSQLServerKey_updateKey
=== PAUSE TestAccPostgreSQLServerKey_updateKey
=== RUN   TestAccPostgreSQLServerKey_requiresImport
=== PAUSE TestAccPostgreSQLServerKey_requiresImport
=== RUN   TestAccPostgreSQLServer_basicNinePointFive
=== PAUSE TestAccPostgreSQLServer_basicNinePointFive
=== RUN   TestAccPostgreSQLServer_basicNinePointFiveDeprecated
=== PAUSE TestAccPostgreSQLServer_basicNinePointFiveDeprecated
=== RUN   TestAccPostgreSQLServer_basicNinePointSix
=== PAUSE TestAccPostgreSQLServer_basicNinePointSix
=== RUN   TestAccPostgreSQLServer_basicTenPointZero
=== PAUSE TestAccPostgreSQLServer_basicTenPointZero
=== RUN   TestAccPostgreSQLServer_gpTenPointZero
=== PAUSE TestAccPostgreSQLServer_gpTenPointZero
=== RUN   TestAccPostgreSQLServer_moTenPointZero
=== PAUSE TestAccPostgreSQLServer_moTenPointZero
=== RUN   TestAccPostgreSQLServer_basicEleven
=== PAUSE TestAccPostgreSQLServer_basicEleven
=== RUN   TestAccPostgreSQLServer_basicWithIdentity
=== PAUSE TestAccPostgreSQLServer_basicWithIdentity
=== RUN   TestAccPostgreSQLServer_autogrowOnly
=== PAUSE TestAccPostgreSQLServer_autogrowOnly
=== RUN   TestAccPostgreSQLServer_requiresImport
=== PAUSE TestAccPostgreSQLServer_requiresImport
=== RUN   TestAccPostgreSQLServer_complete
=== PAUSE TestAccPostgreSQLServer_complete
=== RUN   TestAccPostgreSQLServer_updatedDeprecated
=== PAUSE TestAccPostgreSQLServer_updatedDeprecated
=== RUN   TestAccPostgreSQLServer_updated
=== PAUSE TestAccPostgreSQLServer_updated
=== RUN   TestAccPostgreSQLServer_completeDeprecatedUpdate
=== PAUSE TestAccPostgreSQLServer_completeDeprecatedUpdate
=== RUN   TestAccPostgreSQLServer_updateSKU
=== PAUSE TestAccPostgreSQLServer_updateSKU
=== RUN   TestAccPostgreSQLServer_createReplica
=== PAUSE TestAccPostgreSQLServer_createReplica
=== RUN   TestAccPostgreSQLServer_scaleReplica
=== PAUSE TestAccPostgreSQLServer_scaleReplica
=== RUN   TestAccPostgreSQLServer_createPointInTimeRestore
=== PAUSE TestAccPostgreSQLServer_createPointInTimeRestore
=== RUN   TestAccPostgreSQLServer_threatDetectionEmptyAttrs
=== PAUSE TestAccPostgreSQLServer_threatDetectionEmptyAttrs
=== CONT  TestAccPostgreSQLServerKey_basic
=== CONT  TestAccPostgreSQLServer_requiresImport
=== CONT  TestAccPostgreSQLServer_createReplica
=== CONT  TestAccPostgreSQLServer_autogrowOnly
--- PASS: TestAccPostgreSQLServer_requiresImport (297.98s)
=== CONT  TestAccPostgreSQLServer_basicWithIdentity
=== CONT  TestAccPostgreSQLServer_createReplica
    testing.go:620: Step 3/4 error: Error running apply:
        Error: retrieving PostgreSQL Server "acctest-psql-server-210227233607504686" (Resource Group "acctestRG-psql-210227233607504686"): postgresql.ServersClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.DBForPostgreSQL/servers/acctest-psql-server-210227233607504686' under resource group 'acctestRG-psql-210227233607504686' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

          on config005028830/terraform_plugin_test.tf line 12, in resource "azurerm_postgresql_server" "test":
          12: resource "azurerm_postgresql_server" "test" {


--- PASS: TestAccPostgreSQLServer_autogrowOnly (326.23s)
=== CONT  TestAccPostgreSQLServer_basicEleven
--- FAIL: TestAccPostgreSQLServer_createReplica (425.91s)
=== CONT  TestAccPostgreSQLServer_moTenPointZero
--- PASS: TestAccPostgreSQLServer_basicWithIdentity (286.63s)
=== CONT  TestAccPostgreSQLServer_gpTenPointZero
--- PASS: TestAccPostgreSQLServer_moTenPointZero (165.27s)
=== CONT  TestAccPostgreSQLServer_updated
--- PASS: TestAccPostgreSQLServer_basicEleven (286.52s)
=== CONT  TestAccPostgreSQLServer_updateSKU
--- PASS: TestAccPostgreSQLServer_gpTenPointZero (225.93s)
=== CONT  TestAccPostgreSQLServer_completeDeprecatedUpdate
=== CONT  TestAccPostgreSQLServer_updated
    testing.go:620: Step 3/8 error: Error running apply:
        Error: retrieving PostgreSQL Server "acctest-psql-server-210227233607507869" (Resource Group "acctestRG-psql-210227233607507869"): postgresql.ServersClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.DBForPostgreSQL/servers/acctest-psql-server-210227233607507869' under resource group 'acctestRG-psql-210227233607507869' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

          on config105191985/terraform_plugin_test.tf line 11, in resource "azurerm_postgresql_server" "test":
          11: resource "azurerm_postgresql_server" "test" {


=== CONT  TestAccPostgreSQLServer_updateSKU
    testing.go:620: Step 3/6 error: Error running apply:
        Error: retrieving PostgreSQL Server "acctest-psql-server-210227233607507176" (Resource Group "acctestRG-psql-210227233607507176"): postgresql.ServersClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.DBForPostgreSQL/servers/acctest-psql-server-210227233607507176' under resource group 'acctestRG-psql-210227233607507176' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

          on config992777928/terraform_plugin_test.tf line 11, in resource "azurerm_postgresql_server" "test":
          11: resource "azurerm_postgresql_server" "test" {


--- FAIL: TestAccPostgreSQLServer_updated (362.58s)
=== CONT  TestAccPostgreSQLServer_updatedDeprecated
--- FAIL: TestAccPostgreSQLServer_updateSKU (423.97s)
=== CONT  TestAccPostgreSQLServer_basicNinePointFiveDeprecated
--- PASS: TestAccPostgreSQLServer_completeDeprecatedUpdate (326.05s)
=== CONT  TestAccPostgreSQLServer_basicTenPointZero
=== CONT  TestAccPostgreSQLServer_updatedDeprecated
    testing.go:620: Step 3/6 error: Error running apply:
        Error: retrieving PostgreSQL Server "acctest-psql-server-210227233607509799" (Resource Group "acctestRG-psql-210227233607509799"): postgresql.ServersClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.DBForPostgreSQL/servers/acctest-psql-server-210227233607509799' under resource group 'acctestRG-psql-210227233607509799' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

          on config118414856/terraform_plugin_test.tf line 11, in resource "azurerm_postgresql_server" "test":
          11: resource "azurerm_postgresql_server" "test" {


--- FAIL: TestAccPostgreSQLServer_updatedDeprecated (302.06s)
=== CONT  TestAccPostgreSQLServer_basicNinePointSix
--- PASS: TestAccPostgreSQLServer_basicNinePointFiveDeprecated (257.48s)
=== CONT  TestAccPostgreSQLServerKey_requiresImport
--- PASS: TestAccPostgreSQLServer_basicTenPointZero (285.07s)
=== CONT  TestAccPostgreSQLServer_basicNinePointFive
--- PASS: TestAccPostgreSQLServer_basicNinePointSix (287.94s)
=== CONT  TestAccPostgreSQLServer_complete
--- PASS: TestAccPostgreSQLServer_basicNinePointFive (289.81s)
=== CONT  TestAccPostgreSQLServerKey_updateKey
--- PASS: TestAccPostgreSQLServer_complete (170.83s)
=== CONT  TestAccPostgreSQLServer_createPointInTimeRestore
=== CONT  TestAccPostgreSQLServerKey_basic
    testing_new.go:21: WARNING: destroy failed, so remote objects may still exist and be subject to billing
    testing_new.go:21: failed to destroy:
        Error: Error updating Access Policy (Object ID "831c4b6d-ce7c-4b53-82ef-8c60d3d1a7a7" / Application ID "") for Key Vault "acctestkvo804e" (Resource Group "acctestRG-210227233607500657"): keyvault.VaultsClient#UpdateAccessPolicy: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded



        Error: failed waiting for Key Vault Access Policy (Object ID: "61bf2238-f37c-474c-85eb-0c6e46a0e4e0") to apply: timeout while waiting for state to become 'notfound' (last state: 'found', timeout: 30m0s)



--- FAIL: TestAccPostgreSQLServerKey_basic (2007.11s)
=== CONT  TestAccPostgreSQLServer_threatDetectionEmptyAttrs
=== CONT  TestAccPostgreSQLServer_createPointInTimeRestore
    testing.go:620: Step 3/4 error: Error running apply:
        Error: retrieving PostgreSQL Server "acctest-psql-server-210227233607507312" (Resource Group "acctestRG-psql-210227233607507312"): postgresql.ServersClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The Resource 'Microsoft.DBForPostgreSQL/servers/acctest-psql-server-210227233607507312' under resource group 'acctestRG-psql-210227233607507312' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"

          on config903749563/terraform_plugin_test.tf line 12, in resource "azurerm_postgresql_server" "test":
          12: resource "azurerm_postgresql_server" "test" {


--- PASS: TestAccPostgreSQLServer_threatDetectionEmptyAttrs (168.93s)
=== CONT  TestAccPostgreSQLServer_scaleReplica
--- FAIL: TestAccPostgreSQLServer_createPointInTimeRestore (481.06s)
=== CONT  TestAccPostgreSQLServer_scaleReplica
    testing.go:620: Step 3/6 error: Error running apply:
        Error: updating PostgreSQL Server Replica "acctest-psql-server-210227233607507872-replica" (Resource Group "acctestRG-psql-210227233607507872"): postgresql.ServersClient#Update: Failure sending request: StatusCode=0 -- Original Error: Code="FeatureSwitchNotEnabled" Message="Requested feature is not enabled"

          on config075372477/terraform_plugin_test.tf line 12, in resource "azurerm_postgresql_server" "test":
          12: resource "azurerm_postgresql_server" "test" {


--- FAIL: TestAccPostgreSQLServer_scaleReplica (619.81s)
=== CONT  TestAccPostgreSQLServerKey_requiresImport
    testing_new.go:21: WARNING: destroy failed, so remote objects may still exist and be subject to billing
    testing_new.go:21: failed to destroy:
        Error: failed waiting for Key Vault Access Policy (Object ID: "bc726d12-ec68-4857-b24c-380bdb2e503a") to apply: timeout while waiting for state to become 'notfound' (last state: 'found', timeout: 30m0s)



        Error: Error updating Access Policy (Object ID "831c4b6d-ce7c-4b53-82ef-8c60d3d1a7a7" / Application ID "") for Key Vault "acctestkvvlfsp" (Resource Group "acctestRG-210227233607507327"): keyvault.VaultsClient#UpdateAccessPolicy: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded



--- FAIL: TestAccPostgreSQLServerKey_requiresImport (2015.08s)
=== CONT  TestAccPostgreSQLServerKey_updateKey
    testing_new.go:21: WARNING: destroy failed, so remote objects may still exist and be subject to billing
    testing_new.go:21: failed to destroy:
        Error: failed waiting for Key Vault Access Policy (Object ID: "831c4b6d-ce7c-4b53-82ef-8c60d3d1a7a7") to apply: timeout while waiting for state to become 'notfound' (last state: 'found', timeout: 30m0s)



        Error: Error updating Access Policy (Object ID "27d11f38-4960-467f-8400-bbdac0d25b67" / Application ID "") for Key Vault "acctestkv2jzrg" (Resource Group "acctestRG-210227233607500069"): keyvault.VaultsClient#UpdateAccessPolicy: Failure sending request: StatusCode=0 -- Original Error: context deadline exceeded



--- FAIL: TestAccPostgreSQLServerKey_updateKey (2049.70s)
FAIL
FAIL    github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres    3761.291s
FAIL

@aristosvo aristosvo force-pushed the feature/postgres-primary-secondary-scaling branch from 52e31a4 to 5c68e6e Compare February 28, 2021 19:50
@aristosvo
Copy link
Collaborator Author

aristosvo commented Feb 28, 2021

The acctest for the new functionality has succeeded anyway with a few minor updates:

❯ TF_ACC=1 go test -v ./azurerm/internal/services/postgres/ -run=TestAccPostgreSQLServer_scaleReplica -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2021/02/28 20:25:44 [DEBUG] not using binary driver name, it's no longer needed
2021/02/28 20:25:45 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccPostgreSQLServer_scaleReplica
=== PAUSE TestAccPostgreSQLServer_scaleReplica
=== CONT  TestAccPostgreSQLServer_scaleReplica
--- PASS: TestAccPostgreSQLServer_scaleReplica (1320.66s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres 1324.093s

@aristosvo aristosvo marked this pull request as ready for review March 1, 2021 18:29
@aristosvo aristosvo force-pushed the feature/postgres-primary-secondary-scaling branch 2 times, most recently from 0671126 to e837b66 Compare March 1, 2021 19:00
@aristosvo aristosvo force-pushed the feature/postgres-primary-secondary-scaling branch from e837b66 to bbd0a78 Compare March 1, 2021 19:01
@ghost ghost added size/M and removed size/L labels Mar 1, 2021
@aristosvo
Copy link
Collaborator Author

Test update to reuse test code, createReplica test works again:

❯ TF_ACC=1 go test -v ./azurerm/internal/services/postgres/ -run=TestAccPostgreSQLServer_createReplica -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2021/03/01 20:38:49 [DEBUG] not using binary driver name, it's no longer needed
2021/03/01 20:38:50 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccPostgreSQLServer_createReplica
=== PAUSE TestAccPostgreSQLServer_createReplica
=== CONT  TestAccPostgreSQLServer_createReplica
--- PASS: TestAccPostgreSQLServer_createReplica (702.49s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres    705.972s

Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@aristosvo, thanks for this PR and it's looking really good. I left a very minor comment I would like updated if you don't mind and if you could add some documentation that would be great! 🚀

if indexOfSku(old) < indexOfSku(new) {
listReplicas, err := replicasClient.ListByServer(ctx, id.ResourceGroup, id.Name)
if err != nil {
return fmt.Errorf("request error for list of replicas for PostgreSQL Server %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("request error for list of replicas for PostgreSQL Server %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)
return fmt.Errorf("listing replicas for PostgreSQL Server %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err)

@WodansSon
Copy link
Collaborator

WodansSon commented Mar 5, 2021

@aristosvo, I am still seeing acceptance tests failing. Also, could we get a test with more than one replica server in it as well? This is so close, just have a few little tweaks to work out and I think we could get this in the next release. 🚀

@WodansSon WodansSon added this to the v2.51.0 milestone Mar 5, 2021
@WodansSon
Copy link
Collaborator

@aristosvo, I figured out why a lot of test cases were failing. There appears to be a bug in the RP where it will return the future saying that the resource is available, but it isn't actually accessible yet so you will need to add a state wait function to the code to hang out for a while until it is actually available. In the postgresql_server_resource.go file just after it returns from the future.WaitForCompletionRef(ctx, client.Client) call should be somewhere around line 542:

	log.Printf("[DEBUG] Waiting for PostgreSQL Server %q (Resource Group %q) to become available", name, resourceGroup)
	stateConf := &resource.StateChangeConf{
		Pending:    []string{string(postgresql.ServerStateInaccessible)},
		Target:     []string{string(postgresql.ServerStateReady)},
		Refresh:    postgreSqlStateRefreshFunc(ctx, client, resourceGroup, name),
		MinTimeout: 15 * time.Second,
		Timeout:    d.Timeout(schema.TimeoutCreate),
	}

	if _, err = stateConf.WaitForState(); err != nil {
		return fmt.Errorf("waiting for PostgreSQL Server %q (Resource Group %q)to become available: %+v", name, resourceGroup, err)
	}

Then at the very bottom of that same file and this code to expose the actual state wait function:

func postgreSqlStateRefreshFunc(ctx context.Context, client *postgresql.ServersClient, resourceGroup string, name string) resource.StateRefreshFunc {
	return func() (interface{}, string, error) {
		res, err := client.Get(ctx, resourceGroup, name)
		if !utils.ResponseWasNotFound(res.Response) && err != nil {
			return nil, "", fmt.Errorf("retrieving status of PostgreSQL Server %s (Resource Group %q): %+v", name, resourceGroup, err)
		}

		// This is an issue with the RP, there is a 10 to 15 second lag before the
		// service will actually return the server
		if utils.ResponseWasNotFound(res.Response) {
			return res, string(postgresql.ServerStateInaccessible), nil
		}

		return res, string(res.ServerProperties.UserVisibleState), nil
	}
}

You will also have to add the follow to your import statement at the top of the file:

import (
	"context"

	"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
)

Totally not your fault, or your codes fault, but since you're in there might as well fix this too. 🙂

@ghost ghost added size/L documentation and removed size/M labels Mar 5, 2021
@aristosvo
Copy link
Collaborator Author

aristosvo commented Mar 5, 2021

@WodansSon Thanks for your comments!

I believe I implemented them all, added a small note in the documentation about the functionality.

AccTest for multiple replicas passed:

TF_ACC=1 go test -v ./azurerm/internal/services/postgres/ -run=TestAccPostgreSQLServer_scaleReplica -timeout 180m -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
2021/03/05 10:52:09 [DEBUG] not using binary driver name, it's no longer needed
2021/03/05 10:52:10 [DEBUG] not using binary driver name, it's no longer needed
=== RUN   TestAccPostgreSQLServer_scaleReplicas
=== PAUSE TestAccPostgreSQLServer_scaleReplicas
=== CONT  TestAccPostgreSQLServer_scaleReplicas
--- PASS: TestAccPostgreSQLServer_scaleReplicas (1563.61s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/postgres       1567.103s

@aristosvo aristosvo requested a review from WodansSon March 5, 2021 10:24
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@aristosvo, this is looking good and you implemented the suggestions perfectly, that you so much for pushing the updates. I have one last question, in the note you added to the documentation it looks like there maybe a typo, so I wanted to check with you if it was intended or not. Other than that the LGTM! 🚀

website/docs/r/postgresql_server.html.markdown Outdated Show resolved Hide resolved
@WodansSon
Copy link
Collaborator

I ran the tests and there is currently only one test case that still fails and that is because it's a bad test. If you are up to it you can fix that to in this PR and then all of the server tests will pass with a 100% pass rate! I investigated the TestAccPostgreSQLServer_updated test and it's because the test is not configured correctly, so if you want to fix it replace the existing TestAccPostgreSQLServer_updated test case in the postgresql_server_resource_test.go file with this (it should be around line 219 in the file):

func TestAccPostgreSQLServer_updated(t *testing.T) {
	data := acceptance.BuildTestData(t, "azurerm_postgresql_server", "test")
	r := PostgreSQLServerResource{}
	data.ResourceTest(t, r, []resource.TestStep{
		{
			Config: r.gp(data, "9.6"),
			Check: resource.ComposeTestCheckFunc(
				check.That(data.ResourceName).ExistsInAzure(r),
			),
		},
		data.ImportStep("administrator_login_password"),
		{
			Config: r.complete(data, "9.6"),
			Check: resource.ComposeTestCheckFunc(
				check.That(data.ResourceName).ExistsInAzure(r),
			),
		},
		data.ImportStep("administrator_login_password"),
		{
			Config: r.complete2(data, "9.6"),
			Check: resource.ComposeTestCheckFunc(
				check.That(data.ResourceName).ExistsInAzure(r),
			),
		},
		data.ImportStep("administrator_login_password"),
		{
			Config: r.complete(data, "9.6"),
			Check: resource.ComposeTestCheckFunc(
				check.That(data.ResourceName).ExistsInAzure(r),
			),
		},
		data.ImportStep("administrator_login_password"),
	})
}

Then you will need to fix the configuration file complete2, this test configuration has invalid settings which was one of the reasons the test was failing. So update the configuration file, which is also in the postgresql_server_resource_test.go around line 629, with the below updated configuration code:

func (PostgreSQLServerResource) complete2(data acceptance.TestData, version string) string {
	return fmt.Sprintf(`
provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-psql-%[1]d"
  location = "%[2]s"
}

resource "azurerm_storage_account" "test" {
  name                     = "accsa%[1]d"
  resource_group_name      = azurerm_resource_group.test.name
  location                 = azurerm_resource_group.test.location
  account_tier             = "Standard"
  account_replication_type = "GRS"
}

resource "azurerm_postgresql_server" "test" {
  name                = "acctest-psql-server-%[1]d"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name

  administrator_login          = "acctestun"
  administrator_login_password = "H@Sh1CoR3!updated"

  sku_name   = "GP_Gen5_4"
  version    = "%[3]s"
  storage_mb = 640000

  backup_retention_days        = 14
  geo_redundant_backup_enabled = false
  auto_grow_enabled            = false

  infrastructure_encryption_enabled = false
  public_network_access_enabled     = true
  ssl_enforcement_enabled           = false

  threat_detection_policy {
    enabled              = true
    disabled_alerts      = ["Sql_Injection"]
    email_account_admins = true
    email_addresses      = ["kt@example.com"]

    retention_days = 7
  }
}
`, data.RandomInteger, data.Locations.Primary, version)
}

Once you do that all of the server tests will pass again! Thanks for your help!

Co-authored-by: WS <20408400+WodansSon@users.noreply.github.com>
Copy link
Collaborator

@WodansSon WodansSon left a comment

Choose a reason for hiding this comment

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

@aristosvo, thanks for pushing those changes this LGTM now! 🚀

@WodansSon
Copy link
Collaborator

image

@WodansSon WodansSon merged commit f3732c9 into hashicorp:master Mar 6, 2021
WodansSon added a commit that referenced this pull request Mar 6, 2021
@aristosvo
Copy link
Collaborator Author

@WodansSon Thanks!🎉💃🏼🍻

I planned to include the final test fix, but didn't have a keyboard at hand when I saw it 😂 Saw your other PR for it, anyway👍👍

@aristosvo aristosvo deleted the feature/postgres-primary-secondary-scaling branch March 6, 2021 15:07
@ghost
Copy link

ghost commented Mar 12, 2021

This has been released in version 2.51.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.51.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Apr 5, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Apr 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform does not handle updating a PostgreSQL Server Replica
4 participants