-
Notifications
You must be signed in to change notification settings - Fork 1.8k
google_sql_database_instance deletes root@% user even when password is set via Terraform #22562
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
Comments
Could you be more directly on the instructions since you are providing many shared codes this may cause confusion. Please just specify and confirm the code you are using and confirm if the |
I have updated the description with the actual Terraform Code, debug output for Terraform Apply and terraform state file. Please note, I masked any information that I thought were sensitive, such as Project IDs. |
Thanks @kthirumalasetty I checked the logs, but after deleting the default user it was created the new |
@ggtisc Thank you for your response. I am a bit confused about the newly created "root_user" you’re referring to. In our Terraform code, we are not creating a new user named root_user, and there is no such user present in our logs, Cloud SQL console, or the Terraform state file. If you review the Terraform resources I shared earlier, you’ll see that we are setting the password for the default "root" user by specifying the root_password parameter within the google_sql_database_instance resource. According to the documentation (https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/sql_database_instance), only "root" users without a password should be deleted. However, as shown in our logs, Cloud SQL console, and Terraform state file, the root user—with the password properly set—is still being deleted. To clarify, I am resending the main.tf, apply output, and the Terraform state file for your reference (with parts of the project IDs masked). |
After checking this issue with @hao-nan-li it seems that there is a possibility that this issue has an internal configuration which is conflicting with the user. For this reason I'm forwarding this issue for a deep review |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.11.4
on darwin_arm64
Affected Resource(s)
google_sql_database_instance
Terraform Configuration
Debug Output
During terraform apply, instance creation succeeds, but the root@% user is deleted from the MySQL instance, even though a password was specified via root_password.
No errors are thrown.
After creation, connecting to the instance shows the root@% user is missing.
apply_debug.txt
terraform_tfstate.txt
Screenshot from Cloud SQL UI:

Expected Behavior
When a root_password is provided in the google_sql_database_instance block, the root@% user should be preserved on the SQL instance after creation.
Actual Behavior
Despite providing a root_password, Terraform deletes the root@% user during SQL instance creation.
Steps to reproduce
terraform apply
Important Factoids
References
Related Terraform documentation: google_sql_database_instance
b/416552133
The text was updated successfully, but these errors were encountered: