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 not imported for replica server, forces recreation #27272

Closed
1 task done
kamilzzz opened this issue Sep 3, 2024 · 3 comments · Fixed by #27295 or #27442
Closed
1 task done

Comments

@kamilzzz
Copy link
Contributor

kamilzzz commented Sep 3, 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.2.8

AzureRM Provider Version

3.116.0

Affected Resource(s)/Data Source(s)

azurerm_mysql_flexible_server

Terraform Configuration Files

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

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]
  }
}
-------------
Replica definition
-------------
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-gwc-ZZZ" # forces replacement

Expected Behaviour

source_server_id property to be properly imported.

Actual Behaviour

source_server_id property is not imported.
Next plan/apply forces recreation which is not desired.

Looking at the source code source_server_id is not imported. Looks like there is the same behaviour with PostgreSQL Server resource. Is this somehow expected?

Steps to Reproduce

  1. terraform apply "Primary only" configuration from above
  2. Create MySQL replica using Azure Portal/Azure CLI
  3. terraform import 'azurerm_mysql_flexible_server.replica' <replica-resource-id>
  4. Add "Replica definition" terraform configuration from above
  5. Run terraform plan
  6. Observe source_server_id proeprty was not imported (null in the state) and that plan tries to recreate replica

Important Factoids

No response

References

No response

@neil-yechenwei
Copy link
Contributor

Thanks for raising this issue. Seems TF doesn't store the value of source_server_id in the read func of azurerm_mysql_flexible_server.

@kamilzzz
Copy link
Contributor Author

kamilzzz commented Sep 18, 2024

@neil-yechenwei This is still not working correctly with 4.2.0 version.

I just did a simple import of manually created MySQL Flexible Server replica and source_server_id is again empty in the state file.

I am not sure your fix entirely correct, I have no experience with implementing providers but is this line from your fix correct?
d.Set("source_server_id", d.Get("source_server_id").(string))

Shouldn't it get value from props. object similarly how rest of the properties are set?

Copy link

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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.