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

Fix for SQL database import formats #2199

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 12 additions & 2 deletions products/sql/api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions products/sql/terraform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ 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}}"]
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
Expand Down
4 changes: 3 additions & 1 deletion provider/terraform/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
# 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
Expand Down
12 changes: 12 additions & 0 deletions templates/terraform/examples/sql_database_basic.tf.erb
Original file line number Diff line number Diff line change
@@ -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"
}
}
83 changes: 0 additions & 83 deletions third_party/terraform/website/docs/r/sql_database.html.markdown

This file was deleted.