From e959b3402bb0031388945183c7b9e06980e40190 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 16 Aug 2019 09:14:37 -0700 Subject: [PATCH 1/5] Add back SQL format using an unstable sort. --- products/sql/terraform.yaml | 2 ++ provider/terraform/import.rb | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/products/sql/terraform.yaml b/products/sql/terraform.yaml index 807b23c38601..4181fcac3f48 100644 --- a/products/sql/terraform.yaml +++ b/products/sql/terraform.yaml @@ -20,6 +20,8 @@ overrides: !ruby/object:Overrides::ResourceOverrides import_format: ["projects/{{project}}/instances/{{instance}}/databases/{{name}}", "{{project}}/{{instance}}/{{name}}", "instances/{{instance}}/databases/{{name}}", + # support for a legacy import format + "{{instance}}:{{name}}", "{{instance}}/{{name}}", "{{name}}"] timeouts: !ruby/object:Api::Timeouts diff --git a/provider/terraform/import.rb b/provider/terraform/import.rb index 9e43d588a321..07886694eaf4 100644 --- a/provider/terraform/import.rb +++ b/provider/terraform/import.rb @@ -65,8 +65,10 @@ def import_id_formats(resource) short_id_default_format = field_markers.join('/') # Regexes should be unique and ordered from most specific to least specific + # Searching for {{ finds the number of values in the regexes, since the split + # marker may vary for formats defined in import_formats. (id_formats + [short_id_format, short_id_default_project_format, short_id_default_format]) - .uniq.reject(&:empty?).sort_by { |i| i.count('/') }.reverse + .uniq.reject(&:empty?).sort_by { |i| i.count('{{') }.reverse end end end From 66ee50377f2ca0912939fb4451587e06f0083141 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 16 Aug 2019 11:26:08 -0700 Subject: [PATCH 2/5] Sort by second term to make sure {{name}} is last --- provider/terraform/import.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/provider/terraform/import.rb b/provider/terraform/import.rb index 07886694eaf4..e6b06aa2344e 100644 --- a/provider/terraform/import.rb +++ b/provider/terraform/import.rb @@ -65,10 +65,10 @@ def import_id_formats(resource) short_id_default_format = field_markers.join('/') # Regexes should be unique and ordered from most specific to least specific - # Searching for {{ finds the number of values in the regexes, since the split - # marker may vary for formats defined in import_formats. + # We sort by number of `/` characters (the standard block separator) + # followed by number of variables (`{{`) to make `{{name}}` appear last. (id_formats + [short_id_format, short_id_default_project_format, short_id_default_format]) - .uniq.reject(&:empty?).sort_by { |i| i.count('{{') }.reverse + .uniq.reject(&:empty?).sort_by { |i| [i.count('/'), i.count('{{')] }.reverse end end end From 95697f3688da78cd5b362937411ad78773bf1e49 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 16 Aug 2019 12:55:34 -0700 Subject: [PATCH 3/5] Also delete old docs --- .../website/docs/r/sql_database.html.markdown | 83 ------------------- 1 file changed, 83 deletions(-) delete mode 100644 third_party/terraform/website/docs/r/sql_database.html.markdown diff --git a/third_party/terraform/website/docs/r/sql_database.html.markdown b/third_party/terraform/website/docs/r/sql_database.html.markdown deleted file mode 100644 index 8395517fb67d..000000000000 --- a/third_party/terraform/website/docs/r/sql_database.html.markdown +++ /dev/null @@ -1,83 +0,0 @@ ---- -layout: "google" -page_title: "Google: google_sql_database" -sidebar_current: "docs-google-sql-database-x" -description: |- - Creates a new SQL database in Google Cloud SQL. ---- - -# google\_sql\_database - -Creates a new Google SQL Database on a Google SQL Database Instance. For more information, see -the [official documentation](https://cloud.google.com/sql/), -or the [JSON API](https://cloud.google.com/sql/docs/admin-api/v1beta4/databases). - -## Example Usage - -Example creating a SQL Database. - -```hcl -resource "random_id" "db_name_suffix" { - byte_length = 4 -} - -resource "google_sql_database_instance" "master" { - name = "master-instance-${random_id.db_name_suffix.hex}" - - settings { - tier = "D0" - } -} - -resource "google_sql_database" "users" { - name = "users-db" - instance = "${google_sql_database_instance.master.name}" - charset = "latin1" - collation = "latin1_swedish_ci" -} -``` - -## Argument Reference - -The following arguments are supported: - -* `name` - (Required) The name of the database. - -* `instance` - (Required) The name of containing instance. - -- - - - -* `project` - (Optional) The ID of the project in which the resource belongs. If it - is not provided, the provider project is used. - -* `charset` - (Optional) The charset value. See MySQL's - [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html) - and Postgres' [Character Set Support](https://www.postgresql.org/docs/9.6/static/multibyte.html) - for more details and supported values. Postgres databases are in beta - and have limited `charset` support; they only support a value of `UTF8` at creation time. - -* `collation` - (Optional) The collation value. See MySQL's - [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html) - and Postgres' [Collation Support](https://www.postgresql.org/docs/9.6/static/collation.html) - for more details and supported values. Postgres databases are in beta - and have limited `collation` support; they only support a value of `en_US.UTF8` at creation time. - -## Attributes Reference - -In addition to the arguments listed above, the following computed attributes are -exported: - -* `self_link` - The URI of the created resource. - -## Import - -SQL databases can be imported using one of any of these accepted formats: - -``` -$ terraform import google_sql_database.database projects/{{project}}/instances/{{instance}}/databases/{{name}} -$ terraform import google_sql_database.database {{project}}/{{instance}}/{{name}} -$ terraform import google_sql_database.database instances/{{name}}/databases/{{name}} -$ terraform import google_sql_database.database {{instance}}/{{name}} -$ terraform import google_sql_database.database {{name}} - -``` From b680050766a61811c1413d237f68e2df6c10e18d Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 16 Aug 2019 14:11:58 -0700 Subject: [PATCH 4/5] Update docs --- products/sql/api.yaml | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/products/sql/api.yaml b/products/sql/api.yaml index bdf7599c7395..53a2e1164e4b 100644 --- a/products/sql/api.yaml +++ b/products/sql/api.yaml @@ -416,10 +416,20 @@ objects: properties: - !ruby/object:Api::Type::String name: 'charset' - description: 'The MySQL charset value.' + description: | + The charset value. See MySQL's + [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html) + and Postgres' [Character Set Support](https://www.postgresql.org/docs/9.6/static/multibyte.html) + for more details and supported values. Postgres databases only support + a value of `UTF8` at creation time. - !ruby/object:Api::Type::String name: 'collation' - description: 'The MySQL collation value.' + description: | + The collation value. See MySQL's + [Supported Character Sets and Collations](https://dev.mysql.com/doc/refman/5.7/en/charset-charsets.html) + and Postgres' [Collation Support](https://www.postgresql.org/docs/9.6/static/collation.html) + for more details and supported values. Postgres databases only support + a value of `en_US.UTF8` at creation time. - !ruby/object:Api::Type::String name: 'name' required: true From 54ad969cd1d59d47ba2cf017f7d2ef93c24839d0 Mon Sep 17 00:00:00 2001 From: Riley Karson Date: Fri, 16 Aug 2019 15:32:14 -0700 Subject: [PATCH 5/5] Add example --- products/sql/terraform.yaml | 7 +++++++ .../terraform/examples/sql_database_basic.tf.erb | 12 ++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 templates/terraform/examples/sql_database_basic.tf.erb diff --git a/products/sql/terraform.yaml b/products/sql/terraform.yaml index 4181fcac3f48..0488eec48868 100644 --- a/products/sql/terraform.yaml +++ b/products/sql/terraform.yaml @@ -24,6 +24,13 @@ overrides: !ruby/object:Overrides::ResourceOverrides "{{instance}}:{{name}}", "{{instance}}/{{name}}", "{{name}}"] + examples: + - !ruby/object:Provider::Terraform::Examples + name: "sql_database_basic" + primary_resource_id: "database" + vars: + database_name: "my-database" + database_instance_name: "my-database-instance" timeouts: !ruby/object:Api::Timeouts insert_minutes: 15 update_minutes: 10 diff --git a/templates/terraform/examples/sql_database_basic.tf.erb b/templates/terraform/examples/sql_database_basic.tf.erb new file mode 100644 index 000000000000..fad36f7266a1 --- /dev/null +++ b/templates/terraform/examples/sql_database_basic.tf.erb @@ -0,0 +1,12 @@ +resource "google_sql_database" "<%= ctx[:primary_resource_id] %>" { + name = "<%= ctx[:vars]['database_name'] %>" + instance = "${google_sql_database_instance.instance.name}" +} + +resource "google_sql_database_instance" "instance" { + name = "<%= ctx[:vars]['database_instance_name'] %>" + region = "us-central" + settings { + tier = "D0" + } +}