-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Changing only the settings.version
attribute in the google_sql_database_instance
resource should not be shown as drift
#17809
Comments
settings.version
attribute in the google_sql_database_instance
resource should not be shown as drift
Hi @verdel! As I understand reading the main conversation between you and imrannayer from the attached link and from this one: You have an existing Please confirm this statement to understand your needs. |
@ggtisc, not quite. I'm creating a The warning that I receive in the command output:
|
Then you have the existing |
@ggtisc, the Terraform code does not change between calls to terraform apply. No changes are made in the In the JSON API documentation, it is written that I thought that one possible reason for the change in I checked in the resource_sql_database_instance.go code all the sub-attributes that are saved in the Terraform state and noticed a discrepancy with the documentation only in one attribute - Unfortunately, I can't yet explain why the real state of a Google Cloud PostgreSQL instance might only differ in I am currently waiting for the settings.version change to be reproduced without changes in other sub-attributes. As I currently do not have my own data to confirm this behavior, in the process of creating this issue, I requested data from another participant(@juliusoh) in the discussion of the issue in the terraform-google-modules/terraform-google-sql-db repository. |
It looks like the 'settrings.version' is being updated randomly without changing any configuration in the involved resources on a |
Let's wait a bit. As soon as I reproduce the issue, I will add additional information, including the output of the command By comparing the outputs, we can see exactly what changes in the |
@ggtisc, I finally received confirmation that the Console output of Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:
# google_sql_database_instance.default has changed
~ resource "google_sql_database_instance" "default" {
id = "test"
name = "test"
# (18 unchanged attributes hidden)
~ settings {
~ version = 99 -> 101
# (14 unchanged attributes hidden)
# (6 unchanged blocks hidden)
}
# (1 unchanged block hidden)
}
Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes.
─────────────────────────────────────────────────────────────────────────────
Changes to Outputs:
~ primary = (sensitive value) Diff between outputs of 10c10
< "etag": "c95ddf6f008ad754520321e587f5fa4d763a0e744c9494c96d70347c9fe79837",
---
> "etag": "c7862a289e42ba50bed4e68c11bc0f6f1cef281b1250f3449335b1d3c6373747",
95c95
< "settingsVersion": "99",
---
> "settingsVersion": "101", The diff shows that only the If necessary, I can provide the debug output of |
I have faced exactly same diff like following several times. Note: Objects have changed outside of Terraform
Terraform detected the following changes made outside of Terraform since the
last "terraform apply" which may have affected this plan:
# module.postgresql.google_sql_database_instance.default has changed
! resource "google_sql_database_instance" "default" {
id = "foo-252027d3"
name = "foo-252027d3"
# (14 unchanged attributes hidden)
! settings {
! version = 46 -> 48
# (12 unchanged attributes hidden)
# (4 unchanged blocks hidden)
}
# (1 unchanged block hidden)
}
Unless you have made equivalent changes to your configuration, or ignored the
relevant attributes using ignore_changes, the following plan may include
actions to undo or respond to these changes. |
Can anyone provide the exact TF Provider Google version and full configuration of the resource they're using? I've run multiple tests with the latest version and an older one ( Here's what I've been doing:
In my tests, changing the version never results in configuration drift. Instead, the correct value is silently updated in the Terraform state, which is the expected behavior. |
The provider version used at the time of creating the issue is mentioned in the issue description along with the Terraform configuration:
I have now rechecked that the issue still exists. I am using the following versions and configuration:
terraform {
required_providers {
google = {
source = "hashicorp/google"
version = "6.1.0"
}
}
}
resource "google_sql_database_instance" "main" {
name = "test-instance"
database_version = "POSTGRES_15"
project = "test-project"
region = "europe-west1"
settings {
tier = "db-f1-micro"
insights_config {
query_insights_enabled = false
query_plans_per_minute = 0
query_string_length = 1024
record_application_tags = false
record_client_address = false
}
maintenance_window {
day = 1
hour = 0
}
}
}
output "version" {
value = google_sql_database_instance.main.settings[0].version
} The issue arises because of the If you don’t create an Here is my comment on the suggestion to use Here’s what the output of
|
@verdel Ok, I see it now. In fact you see the configuration drift just because you output the version value
If you comment the output, you will see no changes even if version got bumped, you may try it by simply adding labels to the instance with gcloud or UI, which bumps the version.
May you try it out? |
Yes, I mentioned this in my previous comment. If the In the issue I opened in the terraform-google-modules/terraform-google-sql-db module, I suggested excluding There are two problem: first, why does The second issue is that Terraform reports changes to both the resource and the output. However, as I understand it, this is just how it works. So, is there anything that can be done in the provider code to ensure that a single change to |
Changes to the
Excluding the settings.version from the output is possible, but usually we are trying to keep inputs and outputs consistent with the API as much as possible, so I would not go this way. I imagine you don't really need the
With that you have the |
I understand. May I refer to your response as the official opinion of the provider development team in the issue I opened in the module's repository? As soon as I have additional information, I will share it here. |
Community Note
Terraform Version
Terraform v1.7.5
on darwin_arm64
Affected Resource(s)
google_sql_database_instance
Terraform Configuration
Debug Output
No response
Expected Behavior
Changing the settings.version attribute should not cause drift in the google_sql_database_instance resource if other attributes in settings are not changed
Actual Behavior
Several users have reported cases where only the
settings.version
attribute was changed, without altering any othersettings
attributes. Since thesettings.version
attribute is a read-only attribute, its external modification should not be reflected as drift in the configuration of thegoogle_sql_database_instance
resource.Here's what the output of the terraform plan command looks like in this case:
Steps to reproduce
terraform apply
orterraform plan
Important Factoids
No response
References
terraform-google-modules/terraform-google-sql-db#548
b/335253065
The text was updated successfully, but these errors were encountered: