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

Update google_sql_database and google_sql_user to not do Read actions when instance is not active #11866

Merged
merged 12 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmv1/products/sql/Database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async:
collection_url_key: 'items'
custom_code:
pre_delete: 'templates/terraform/pre_delete/sql_database_deletion_policy.tmpl'
pre_read: 'templates/terraform/pre_read/sql_database_activation_policy.tmpl'
SarahFrench marked this conversation as resolved.
Show resolved Hide resolved
# Sweeper skipped as this resource has customized deletion.
exclude_sweeper: true
read_error_transform: 'transformSQLDatabaseReadError'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
instance := d.Get("instance").(string)
databaseInstance, err := config.NewSqlAdminClient(userAgent).Instances.Get(project, instance).Do()
if err != nil {
return err
}
if databaseInstance.Settings.ActivationPolicy != "ALWAYS" {
return nil
}
12 changes: 7 additions & 5 deletions mmv1/third_party/terraform/services/sql/resource_sql_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error {
instance := d.Get("instance").(string)
name := d.Get("name").(string)
host := d.Get("host").(string)
databaseInstance, err := config.NewSqlAdminClient(userAgent).Instances.Get(project, instance).Do()
if err != nil {
return err
}
if databaseInstance.Settings.ActivationPolicy != "ALWAYS" {
return nil
}

var users *sqladmin.UsersListResponse
err = nil
Expand All @@ -342,11 +349,6 @@ func resourceSqlUserRead(d *schema.ResourceData, meta interface{}) error {
}

var user *sqladmin.User
databaseInstance, err := config.NewSqlAdminClient(userAgent).Instances.Get(project, instance).Do()
if err != nil {
return err
}

for _, currentUser := range users.Items {
var username string
if !(strings.Contains(databaseInstance.DatabaseVersion, "POSTGRES") || currentUser.Type == "CLOUD_IAM_GROUP") {
Expand Down
Loading