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

Support Self Service Maintenance feature #6131

Merged
merged 36 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
2f21578
Changes for SSM terraform
2tricpony Jun 14, 2022
cb08b34
Change description of some fields.
2tricpony Jun 14, 2022
6e0a876
Merge branch 'GoogleCloudPlatform:main' into main
2tricpony Jun 14, 2022
f890112
Add a test case for maintenance version suppress diff functionality
2tricpony Jul 19, 2022
a036a42
Add test case for suppress diff functionality
2tricpony Jul 19, 2022
d15bed2
Make availableMaintenanceVersions optional=false
2tricpony Jul 19, 2022
d126eb5
Update mmv1/third_party/terraform/website/docs/r/sql_database_instanc…
2tricpony Aug 9, 2022
b5f5b45
Update mmv1/third_party/terraform/website/docs/r/sql_database_instanc…
2tricpony Aug 9, 2022
036fd77
Modifying test cases
2tricpony Aug 10, 2022
37ea61d
Acceptance test for maintenance version.
2tricpony Aug 10, 2022
d97c2eb
Fix spacing
2tricpony Aug 10, 2022
9badea9
Update mmv1/third_party/terraform/website/docs/r/sql_database_instanc…
2tricpony Aug 16, 2022
7f32388
Address comments from review.
2tricpony Aug 17, 2022
fe2954c
Fix Indentation
2tricpony Aug 17, 2022
2612558
Update mmv1/third_party/terraform/tests/resource_sql_database_instanc…
2tricpony Aug 22, 2022
fa2b40f
Update mmv1/third_party/terraform/tests/resource_sql_database_instanc…
2tricpony Aug 22, 2022
7d19060
Merge branch 'main' into main
2tricpony Aug 22, 2022
58996f1
Resolve merge issue.
2tricpony Aug 22, 2022
ae1b30b
Make separate patch call for maintenance version updates.
2tricpony Aug 24, 2022
85b7801
Merge branch 'GoogleCloudPlatform:main' into main
2tricpony Aug 24, 2022
19cf115
Fix error
2tricpony Aug 24, 2022
c0dd9d5
Update mmv1/third_party/terraform/website/docs/r/sql_database_instanc…
2tricpony Sep 1, 2022
a956cf4
Addressing comments.
2tricpony Sep 1, 2022
909bd35
Addressing review comments
2tricpony Sep 12, 2022
3c52e8b
Add a comment.
2tricpony Sep 12, 2022
6f0eac2
Fix provider crash issue.
2tricpony Sep 12, 2022
bc42349
Fix case where patch request was not properly sent.
2tricpony Sep 15, 2022
04cfe58
Remove suppressDiff functionality for maintenance version
2tricpony Sep 19, 2022
2e8918b
Merge branch 'GoogleCloudPlatform:main' into main
2tricpony Sep 19, 2022
f6a879a
Fix an accidental commit.
2tricpony Sep 19, 2022
4b30e36
Fix test issue.
2tricpony Sep 19, 2022
d77cb6f
Rollforward changes for suppressDiffFunc
2tricpony Sep 21, 2022
81ca557
Fix to suppress diff for equal maintenance version.
2tricpony Sep 26, 2022
3e313ed
Doc changes
2tricpony Sep 26, 2022
294bad0
Merge branch 'GoogleCloudPlatform:main' into main
2tricpony Sep 26, 2022
767fef9
Update mmv1/third_party/terraform/website/docs/r/sql_database_instanc…
2tricpony Sep 26, 2022
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
16 changes: 16 additions & 0 deletions mmv1/products/sql/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ objects:
- :FIRST_GEN
- :SECOND_GEN
- :EXTERNAL
- !ruby/object:Api::Type::String
name: 'maintenanceVersion'
output: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like maintenanceVersion is not an output-only field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right. It can be updated after instance creation.

description: |
The current software version on the instance. This attribute can not
be set during creation. Refer to available_maintenance_versions
attribute to see what maintenance_versions are available for upgrade.
When this attribute gets updated, it will cause an instance restart.

- !ruby/object:Api::Type::Array
name: 'availableMaintenanceVersions'
output: true
description: |
The list of all maintenance versions applicable on the instance. This
attribute can not be updated.
item_type: Api::Type::String
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
- !ruby/object:Api::Type::String
name: 'connectionName'
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,22 @@ is set to true.`,
Computed: true,
Description: `The connection name of the instance to be used in connection strings. For example, when connecting with Cloud SQL Proxy.`,
},

"maintenance_version": {
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
Type: schema.TypeString,
Computed: true,
Optional: true,
DiffSuppressFunc: maintenanceVersionDiffSuppress,
Description: `Maintenance version.`,
},
"available_maintenance_versions": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is an output-only field, we probably want to remove Optional: true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: `Available Maintenance versions.`,
},
"database_version": {
Type: schema.TypeString,
Required: true,
Expand All @@ -468,7 +483,6 @@ is set to true.`,
Sensitive: true,
Description: `Initial root password. Required for MS SQL Server, ignored by MySQL and PostgreSQL.`,
},

"ip_address": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -1183,6 +1197,12 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
if err := d.Set("connection_name", instance.ConnectionName); err != nil {
return fmt.Errorf("Error setting connection_name: %s", err)
}
if err := d.Set("maintenance_version", instance.MaintenanceVersion); err != nil {
return fmt.Errorf("Error setting maintenance_version: %s", err)
}
if err := d.Set("available_maintenance_versions", instance.AvailableMaintenanceVersions); err != nil {
return fmt.Errorf("Error setting available_maintenance_version: %s", err)
}
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
if err := d.Set("service_account_email_address", instance.ServiceAccountEmailAddress); err != nil {
return fmt.Errorf("Error setting service_account_email_address: %s", err)
}
Expand Down Expand Up @@ -1261,8 +1281,14 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
return err
}

var maintenance_version string
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
if v, ok := d.GetOk("maintenance_version"); ok {
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
maintenance_version = v.(string)
}

// Update only updates the settings, so they are all we need to set.
instance := &sqladmin.DatabaseInstance{
MaintenanceVersion: maintenance_version,
2tricpony marked this conversation as resolved.
Show resolved Hide resolved
Settings: expandSqlDatabaseInstanceSettings(d.Get("settings").([]interface{})),
}

Expand Down Expand Up @@ -1300,6 +1326,15 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
return resourceSqlDatabaseInstanceRead(d, meta)
}

func maintenanceVersionDiffSuppress(_, old, new string, _ *schema.ResourceData) bool {
if old > new {
log.Printf("[DEBUG] Maintenance version in configuration [%s] is older than current maintenance version [%s] on instance. Suppressing diff", new, old)
return true
} else {
return false
}
}
2tricpony marked this conversation as resolved.
Show resolved Hide resolved

func resourceSqlDatabaseInstanceDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
userAgent, err := generateUserAgentString(d, config.userAgent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ includes an up-to-date reference of supported versions.
created. This is done because after a name is used, it cannot be reused for
up to [one week](https://cloud.google.com/sql/docs/delete-instance).

* maintenance_version - (Optional, Computed) The current software version on the instance. This attribute can not be set during creation. Refer to available_maintenance_versions attribute to see what maintenance_versions are available for upgrade. When this attribute gets updated, it will cause an instance restart.
2tricpony marked this conversation as resolved.
Show resolved Hide resolved

* `master_instance_name` - (Optional) The name of the existing instance that will
act as the master in the replication setup. Note, this requires the master to
have `binary_log_enabled` set, as well as existing backups.
Expand Down Expand Up @@ -425,6 +427,8 @@ instance.
support accessing the [first address in the list in a terraform output](https://github.com/hashicorp/terraform-provider-google/issues/912)
when the resource is configured with a `count`.

* available_maintenance_versions - The list of all maintenance versions applicable on the instance. This attribute can not be updated.
2tricpony marked this conversation as resolved.
Show resolved Hide resolved

* `public_ip_address` - The first public (`PRIMARY`) IPv4 address assigned. This is
a workaround for an [issue fixed in Terraform 0.12](https://github.com/hashicorp/terraform/issues/17048)
but also provides a convenient way to access an IP of a specific type without
Expand Down