hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.63k forks source link

Cannot move azurerm_sql_database into azurerm_mssql_elasticpool due to edition #2389

Closed steve-hawkins closed 5 years ago

steve-hawkins commented 5 years ago

Community Note

Terraform (and AzureRM Provider) Version

Terraform v0.11.10
+ provider.azurerm v1.19.0
+ provider.random v2.0.0

Affected Resource(s)

Terraform Configuration Files

Start with the following:-

resource "azurerm_resource_group" "example" {
  name     = "example"
  location = "westeurope"
}

resource "random_string" "password" {
  length           = 16
  upper            = true
  lower            = true
  number           = true
  special          = true
  min_upper        = 1
  min_lower        = 1
  min_numeric      = 1
  min_special      = 1
  override_special = "#$%&()-_=+<>:"
}

resource "azurerm_sql_server" "example" {
    name                         = "example"
    resource_group_name          = "${azurerm_resource_group.example.name}"
    location                     = "${azurerm_resource_group.example.location}"
    version                      = "12.0"
    administrator_login          = "example"
    administrator_login_password = "${random_string.password.result}"
}

resource "azurerm_sql_database" "example" {
  name                = "example"
  resource_group_name = "${azurerm_resource_group.example.name}"
  location            = "${azurerm_resource_group.example.location}"
  server_name         = "${azurerm_sql_server.example.name}"

  create_mode                      = "Default"
  edition                          = "Standard"
  requested_service_objective_name = "S0"
}

Then try to change to the following:-

resource "azurerm_resource_group" "example" {
  name     = "example"
  location = "westeurope"
}

resource "random_string" "password" {
  length           = 16
  upper            = true
  lower            = true
  number           = true
  special          = true
  min_upper        = 1
  min_lower        = 1
  min_numeric      = 1
  min_special      = 1
  override_special = "#$%&()-_=+<>:"
}

resource "azurerm_sql_server" "example" {
    name                         = "example"
    resource_group_name          = "${azurerm_resource_group.example.name}"
    location                     = "${azurerm_resource_group.example.location}"
    version                      = "12.0"
    administrator_login          = "example"
    administrator_login_password = "${random_string.password.result}"
}

resource "azurerm_mssql_elasticpool" "example" {
  name                = "example"
  resource_group_name = "${azurerm_resource_group.example.name}"
  location            = "${azurerm_resource_group.example.location}"
  server_name         = "${azurerm_sql_server.example.name}"

  sku {
    name     = "GP_Gen5"
    capacity = 2
    tier     = "GeneralPurpose"
    family   = "Gen5"
  }

  per_database_settings {
    min_capacity = 0
    max_capacity = 2
  }
}

resource "azurerm_sql_database" "example" {
  name                = "example"
  resource_group_name = "${azurerm_resource_group.example.name}"
  location            = "${azurerm_resource_group.example.location}"
  server_name         = "${azurerm_sql_server.example.name}"

  create_mode                      = "Default"
  elastic_pool_name                = "${azurerm_sql_server.example.name}"
  requested_service_objective_name = "ElasticPool"
  depends_on                       = ["azurerm_mssql_elasticpool.example"]
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Migrate from individually managed DTU based databases to vCore based elastic pool

Actual Behavior

* azurerm_sql_database.SharedWorkstream: 1 error(s) occurred:

* azurerm_sql_database.SharedWorkstream: Code="40861" Message="The database edition 'Standard' cannot be different than the elastic pool service tier which is 'GeneralPurpose'."

Steps to Reproduce

  1. terraform apply first set of config mentioned above
  2. terraform apply second set of config mentioned above

Important Factoids

References

WodansSon commented 5 years ago

@steve-hawkins thank you for reporting this issue, however this is not a supported scenario all resources need to be either vCore based or DTU based. That said using the files you supplied above, I did get this to work by switching the elasticpool to a StandardPool like this:

resource "azurerm_mssql_elasticpool" "example" {
  name                = "example-repro-elasticpool"
  resource_group_name = "${azurerm_resource_group.example.name}"
  location            = "${azurerm_resource_group.example.location}"
  server_name         = "${azurerm_sql_server.example.name}"

  sku {
    name     = "StandardPool"
    capacity = 100
    tier     = "Standard"
  }

  per_database_settings {
    min_capacity = 0
    max_capacity = 100
  }
}

I also noticed a typo in the original files...

From this:

elastic_pool_name                = "${azurerm_sql_server.example.name}"

To this:

elastic_pool_name                = "${azurerm_mssql_elasticpool.example.name}"

Hope this helps.

ghost commented 5 years ago

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!