-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_sql_server creates a new resource each time if username is created and read in the same deployment #1864
Comments
hi @iszekely Thanks for opening this issue :) Taking a look into this the ID for the Key Vault Secret contains the version at the end which is used for tracking. I believe in the instance above the Version is changing for the secret and thus the ID is changing, which is changing the value of the Key Vault Secret. Would you be able to confirm if there's something changing the value of the Key Vault Secret out of band? Thanks! |
Obviously our first guess was the same: a new version of the key vault secret is generated due to the usage of random_string. I double-checked it again, and nothing changes. The random_string is stored in the TF state, so NO new version is generated. If you create a key vault, fill in the env.tfvars, and run the steps to reproduce, you can see it happening very easily. Thanks you! |
This isn't an issue with the provider, this has to do with terraform core runtime and the way plan itself works. Since during plan it doesn't call any API's or ask Azure about property values it is basically, comparing the state file with the HCL file. Let's use the below HCL file for example and see what is going on: resource "azurerm_key_vault_secret" "test_sql_username" {
name = "test-sql-username"
value = "sqladmin"
vault_uri = "https://<vault>.vault.azure.net/"
}
data "azurerm_key_vault_secret" "test_sql_username" {
name = "test-sql-username"
vault_uri = "https://<vault>.vault.azure.net/"
depends_on = [ "azurerm_key_vault_secret.test_sql_username" ]
}
resource "azurerm_sql_server" "test_sql_server" {
name = "tftestsqlsrv"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
version = "12.0"
administrator_login = "${data.azurerm_key_vault_secret.test_sql_username.value}"
administrator_login_password = "${data.azurerm_key_vault_secret.test_sql_password.value}"
} Assuming we already ran the above HCL file once and it successfully created the resources as expected. We then run
This is where the bug is in the terraform core runtime, what should happen here is it should expand the
I am closing this issue as it is an |
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 👉 [email protected]. Thanks! |
Community Note
Terraform Version
Affected Resource(s)
Terraform Configuration Files
main.tf
variables.tf
env.tfvars
Expected Behavior
The administrator username and password are created as key vault secrets, and then read as data sources. After consecutive executions Terraform should report that everything is up-to-date:
Actual Behavior
At first execution everything get created as expected. At second execution both the
id
and theadministrator_login
(although it is constant) trigger a new resource creation. Theadministrator_login_password
also shows an attribute change, but that could be done in-place.The database and the firewall rules are also destroyed with the server, but does not get recreated. After the third execution the
azurerm_sql_server
gets created again, but this time the database and the firewall rules also show up.So there are two problems:
azurerm_key_vault_secret
resource and data source, and theazurerm_sql_server
resourceazurerm_sql_server
,azurerm_sql_database
, andazurerm_sql_firewall_rule
If I create the two secrets in the key vault by hand and remove the two
azurerm_key_vault_secret
resources, everything just works fine. Even changes in them are noticed and appropriate changes performed.Steps to Reproduce
env.tfvars
terraform apply
Everything gets created as expected.terraform apply
The server is destroyed and a new server gets created.terraform apply
The server is destroyed and a new server, database, and firewall rules get created.References
The text was updated successfully, but these errors were encountered: