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

Azure MySQL Flexible Server source_server_id imported incorrectly for replica server, forces recreation #27503

Open
1 task done
kamilzzz opened this issue Sep 25, 2024 · 0 comments · May be fixed by #27442
Open
1 task done

Comments

@kamilzzz
Copy link

kamilzzz commented Sep 25, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.

Terraform Version

1.9.5

AzureRM Provider Version

4.2.0

Affected Resource(s)/Data Source(s)

azurerm_mysql_flexible_server

Terraform Configuration Files

terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.3.0"
    }
    random = {
      source  = "hashicorp/random"
      version = "=3.6.2"
    }
    azapi = {
      source  = "azure/azapi"
      version = "=1.15.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "random_string" "suffix" {
  length  = 6
  upper   = false
  special = false
}

locals {
  location            = "germanywestcentral"
  resource_group_name = "mysql"
}

resource "azurerm_mysql_flexible_server" "primary" {
  name                = "mysql-primary-${random_string.suffix.result}"
  location            = local.location
  resource_group_name = local.resource_group_name

  administrator_login    = "abcadmin"
  administrator_password = "abcp@ss123"

  sku_name = "GP_Standard_D2ds_v4"

  lifecycle {
    ignore_changes = [zone]
  }
}

resource "azurerm_mysql_flexible_server" "replica" {
  name                = "mysql-replica-${random_string.suffix.result}"
  location            = local.location
  resource_group_name = local.resource_group_name

  create_mode      = "Replica"
  source_server_id = azurerm_mysql_flexible_server.primary.id

  lifecycle {
    ignore_changes = [zone, create_mode]
  }
}

Debug Output/Panic Output

# azurerm_mysql_flexible_server.replica must be replaced
-/+ resource "azurerm_mysql_flexible_server" "replica" {
[...]
      + source_server_id              = "/subscriptions/XXX/resourceGroups/YYY/providers/Microsoft.DBforMySQL/flexibleServers/mysql-primary-ZZZ" # forces replacement

Expected Behaviour

source_server_id property to be properly imported.

Actual Behaviour

source_server_id property is not imported properly. It always imports as an empty string.
Next plan/apply forces recreation which is not desired.

Steps to Reproduce

  1. terraform apply configuration from above
  2. terraform state rm 'azurerm_mysql_flexible_server.replica'
  3. terraform import 'azurerm_mysql_flexible_server.replica' 'replica-resource-id'
  4. Run terraform plan
  5. Observe source_server_id proeprty was not imported (empty string in the state) and that plan tries to recreate replica

Important Factoids

No response

References

There was a previous issue regarding this topic created by me - #27272 with follow up PR which meant to fix it - #27295, but that PR was incorrect.

I created a new PR to fix this issue - #27442

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant