diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml new file mode 100644 index 000000000000..ef348315f742 --- /dev/null +++ b/mmv1/products/datastream/api.yaml @@ -0,0 +1,281 @@ +# Copyright 2022 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- !ruby/object:Api::Product +name: Datastream +versions: + - !ruby/object:Api::Product::Version + name: ga + base_url: https://datastream.googleapis.com/v1/ +scopes: + - https://www.googleapis.com/auth/cloud-platform +apis_required: + - !ruby/object:Api::Product::ApiReference + name: Datastream API + url: https://console.cloud.google.com/apis/library/datastream.googleapis.com +async: !ruby/object:Api::OpAsync + operation: !ruby/object:Api::OpAsync::Operation + path: 'name' + base_url: '{{op_id}}' + wait_ms: 1000 + result: !ruby/object:Api::OpAsync::Result + path: 'response' + resource_inside_response: true + status: !ruby/object:Api::OpAsync::Status + path: 'done' + complete: true + allowed: + - true + - false + error: !ruby/object:Api::OpAsync::Error + path: 'error' + message: 'message' +objects: + - !ruby/object:Api::Resource + name: 'ConnectionProfile' + base_url: "projects/{{project}}/locations/{{location}}/connectionProfiles" + create_url: "projects/{{project}}/locations/{{location}}/connectionProfiles?connectionProfileId={{connection_profile_id}}" + self_link: "projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}" + update_verb: :PATCH + update_mask: true + references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Official Documentation': 'https://cloud.google.com/datastream/docs/create-connection-profiles' + api: 'https://cloud.google.com/datastream/docs/reference/rest/v1/projects.locations.connectionProfiles' + description: | + A set of reusable connection configurations to be used as a source or destination for a stream. + parameters: + - !ruby/object:Api::Type::String + name: connectionProfileId + description: |- + The connection profile identifier. + required: true + input: true + url_param_only: true + - !ruby/object:Api::Type::String + name: 'location' + description: | + The name of the location this repository is located in. + required: true + input: true + url_param_only: true + properties: + - !ruby/object:Api::Type::String + name: 'name' + output: true + description: The resource's name. + - !ruby/object:Api::Type::KeyValuePairs + name: 'labels' + description: Labels. + - !ruby/object:Api::Type::String + name: 'displayName' + required: true + description: Display name. + - !ruby/object:Api::Type::NestedObject + name: 'oracleProfile' + exactly_one_of: + - oracle_profile + - gcs_profile + - mysql_profile + - postgresql_profile + description: | + Oracle database profile. + properties: + - !ruby/object:Api::Type::String + name: 'hostname' + required: true + description: | + Hostname for the Oracle connection. + - !ruby/object:Api::Type::Integer + name: 'port' + default_value: 1521 + description: | + Port for the Oracle connection. + - !ruby/object:Api::Type::String + name: 'username' + required: true + description: | + Username for the Oracle connection. + - !ruby/object:Api::Type::String + name: 'password' + required: true + description: | + Password for the Oracle connection. + - !ruby/object:Api::Type::String + name: 'databaseService' + required: true + description: | + Database for the Oracle connection. + - !ruby/object:Api::Type::KeyValuePairs + name: 'connectionAttributes' + description: Connection string attributes + - !ruby/object:Api::Type::NestedObject + name: 'gcsProfile' + exactly_one_of: + - oracle_profile + - gcs_profile + - mysql_profile + - postgresql_profile + description: | + Cloud Storage bucket profile. + properties: + - !ruby/object:Api::Type::String + name: 'bucket' + required: true + description: | + The Cloud Storage bucket name. + - !ruby/object:Api::Type::String + name: 'rootPath' + description: | + The root path inside the Cloud Storage bucket. + - !ruby/object:Api::Type::NestedObject + name: 'mysqlProfile' + exactly_one_of: + - oracle_profile + - gcs_profile + - mysql_profile + - postgresql_profile + description: | + MySQL database profile. + properties: + - !ruby/object:Api::Type::String + name: 'hostname' + required: true + description: | + Hostname for the MySQL connection. + - !ruby/object:Api::Type::Integer + name: 'port' + default_value: 3306 + description: | + Port for the MySQL connection. + - !ruby/object:Api::Type::String + name: 'username' + required: true + description: | + Username for the MySQL connection. + - !ruby/object:Api::Type::String + name: 'password' + required: true + input: true + description: | + Password for the MySQL connection. + - !ruby/object:Api::Type::NestedObject + name: 'sslConfig' + description: | + SSL configuration for the MySQL connection. + properties: + - !ruby/object:Api::Type::String + name: 'clientKey' + input: true + description: | + PEM-encoded private key associated with the Client Certificate. + If this field is used then the 'client_certificate' and the + 'ca_certificate' fields are mandatory. + - !ruby/object:Api::Type::Boolean + name: 'clientKeySet' + output: true + description: | + Indicates whether the clientKey field is set. + - !ruby/object:Api::Type::String + name: 'clientCertificate' + input: true + description: | + PEM-encoded certificate that will be used by the replica to + authenticate against the source database server. If this field + is used then the 'clientKey' and the 'caCertificate' fields are + mandatory. + - !ruby/object:Api::Type::Boolean + name: 'clientCertificateSet' + output: true + description: | + Indicates whether the clientCertificate field is set. + - !ruby/object:Api::Type::String + name: 'caCertificate' + input: true + description: | + PEM-encoded certificate of the CA that signed the source database + server's certificate. + - !ruby/object:Api::Type::Boolean + name: 'caCertificateSet' + output: true + description: | + Indicates whether the clientKey field is set. + - !ruby/object:Api::Type::NestedObject + name: 'postgresqlProfile' + exactly_one_of: + - oracle_profile + - gcs_profile + - mysql_profile + - postgresql_profile + description: | + PostgreSQL database profile. + properties: + - !ruby/object:Api::Type::String + name: 'hostname' + required: true + description: | + Hostname for the PostgreSQL connection. + - !ruby/object:Api::Type::Integer + name: 'port' + default_value: 5432 + description: | + Port for the PostgreSQL connection. + - !ruby/object:Api::Type::String + name: 'username' + required: true + description: | + Username for the PostgreSQL connection. + - !ruby/object:Api::Type::String + name: 'password' + required: true + description: | + Password for the PostgreSQL connection. + - !ruby/object:Api::Type::String + name: 'database' + required: true + description: | + Database for the PostgreSQL connection. + - !ruby/object:Api::Type::NestedObject + name: 'forwardSshConnectivity' + description: | + Forward SSH tunnel connectivity. + properties: + - !ruby/object:Api::Type::String + name: 'hostname' + required: true + description: | + Hostname for the SSH tunnel. + - !ruby/object:Api::Type::String + name: 'username' + required: true + description: | + Username for the SSH tunnel. + - !ruby/object:Api::Type::Integer + name: 'port' + default_value: 22 + description: | + Port for the SSH tunnel. + - !ruby/object:Api::Type::String + name: 'password' + input: true + description: | + SSH password. + conflicts: + - forward_ssh_connectivity.private_key + - !ruby/object:Api::Type::String + name: 'privateKey' + input: true + description: | + SSH private key. + conflicts: + - forward_ssh_connectivity.private_key diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml new file mode 100644 index 000000000000..8bfa3dd79c70 --- /dev/null +++ b/mmv1/products/datastream/terraform.yaml @@ -0,0 +1,74 @@ +# Copyright 2022 Google Inc. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- !ruby/object:Provider::Terraform::Config +overrides: !ruby/object:Overrides::ResourceOverrides + ConnectionProfile: !ruby/object:Overrides::Terraform::ResourceOverride + id_format: projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}} + import_format: ["projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}"] + properties: + oracleProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.erb + mysqlProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.erb + mysqlProfile.sslConfig.clientKey: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.erb + mysqlProfile.sslConfig.clientCertificate: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.erb + mysqlProfile.sslConfig.caCertificate: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.erb + postgresqlProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.erb + forwardSshConnectivity.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.erb + forwardSshConnectivity.privateKey: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + custom_flatten: templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.erb + examples: + - !ruby/object:Provider::Terraform::Examples + name: "datastream_connection_profile_basic" + primary_resource_id: "default" + vars: + connection_profile_id: "my-profile" + - !ruby/object:Provider::Terraform::Examples + name: "datastream_connection_profile_full" + primary_resource_id: "default" + # Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 + ignore_read_extra: + - "forward_ssh_connectivity.0.password" + vars: + connection_profile_id: "my-profile" + - !ruby/object:Provider::Terraform::Examples + name: "datastream_connection_profile_postgres" + primary_resource_id: "default" + vars: + connection_profile_id: "my-profile" + database_instance_name: "my-instance" + deletion_protection: "true" + # This is covered by the update tests. + skip_test: true diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.erb new file mode 100644 index 000000000000..cd39e081bcfe --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("forward_ssh_connectivity.0.password") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.erb new file mode 100644 index 000000000000..06033101dbbb --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("forward_ssh_connectivity.0.private_key") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.erb new file mode 100644 index 000000000000..d5f3358d70aa --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("mysql_profile.0.password") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.erb new file mode 100644 index 000000000000..256f5be79214 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("mysql_profile.0.ssl_config.0.ca_certificate") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.erb new file mode 100644 index 000000000000..36f4d34ab025 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("mysql_profile.0.ssl_config.0.client_certificate") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.erb new file mode 100644 index 000000000000..66d728fa21ac --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("mysql_profile.0.ssl_config.0.client_key") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.erb new file mode 100644 index 000000000000..38beb8337ff5 --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("oracle_profile.0.password") +} diff --git a/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.erb b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.erb new file mode 100644 index 000000000000..87a7137470bf --- /dev/null +++ b/mmv1/templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.erb @@ -0,0 +1,18 @@ +<%# The license inside this block applies to this file. + # Copyright 2022 Google Inc. + # Licensed under the Apache License, Version 2.0 (the "License"); + # you may not use this file except in compliance with the License. + # You may obtain a copy of the License at + # + # http://www.apache.org/licenses/LICENSE-2.0 + # + # Unless required by applicable law or agreed to in writing, software + # distributed under the License is distributed on an "AS IS" BASIS, + # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + # See the License for the specific language governing permissions and + # limitations under the License. +-%> +<%# Workaround for https://github.com/hashicorp/terraform-provider-google/issues/12410 %> +func flatten<%= prefix -%><%= titlelize_property(property) -%>(v interface{}, d *schema.ResourceData, config *Config) interface{} { + return d.Get("postgresql_profile.0.password") +} diff --git a/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb b/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb new file mode 100644 index 000000000000..516b5b93b2c9 --- /dev/null +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb @@ -0,0 +1,10 @@ +resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]['connection_profile_id'] %>" + + gcs_profile { + bucket = "my-bucket" + root_path = "/path" + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb b/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb new file mode 100644 index 000000000000..4446b36eb872 --- /dev/null +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb @@ -0,0 +1,17 @@ +resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]['connection_profile_id'] %>" + + gcs_profile { + bucket = "my-bucket" + root_path = "/path" + } + + forward_ssh_connectivity { + hostname = "google.com" + username = "my-user" + port = 8022 + password = "swordfish" + } +} \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb b/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb new file mode 100644 index 000000000000..331479017807 --- /dev/null +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb @@ -0,0 +1,63 @@ +resource "google_sql_database_instance" "instance" { + name = "<%= ctx[:vars]['database_instance_name'] %>" + database_version = "POSTGRES_14" + region = "us-central1" + settings { + tier = "db-f1-micro" + + ip_configuration { + + // Datastream IPs will vary by region. + authorized_networks { + value = "34.71.242.81" + } + + authorized_networks { + value = "34.72.28.29" + } + + authorized_networks { + value = "34.67.6.157" + } + + authorized_networks { + value = "34.67.234.134" + } + + authorized_networks { + value = "34.72.239.218" + } + } + } + + deletion_protection = "<%= ctx[:vars]['deletion_protection'] %>" +} + +resource "google_sql_database" "db" { + instance = google_sql_database_instance.instance.name + name = "db" +} + +resource "random_password" "pwd" { + length = 16 + special = false +} + +resource "google_sql_user" "user" { + name = "user" + instance = google_sql_database_instance.instance.name + password = random_password.pwd.result +} + +resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]['connection_profile_id'] %>" + + postgresql_profile { + hostname = google_sql_database_instance.instance.public_ip_address + username = google_sql_user.user.name + password = google_sql_user.user.password + database = google_sql_database.db.name + } +} \ No newline at end of file diff --git a/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go new file mode 100644 index 000000000000..ed0424bcefe0 --- /dev/null +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -0,0 +1,144 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDatastreamConnectionProfile_update(t *testing.T) { + // this test uses the random provider + skipIfVcr(t) + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, + CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDatastreamConnectionProfile_update(context), + }, + { + ResourceName: "google_datastream_connection_profile.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, + }, + { + Config: testAccDatastreamConnectionProfile_update2(context, true), + }, + { + ResourceName: "google_datastream_connection_profile.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "postgresql_profile.0.password"}, + }, + { + // Disable prevent_destroy + Config: testAccDatastreamConnectionProfile_update2(context, false), + }, + }, + }) +} + +func testAccDatastreamConnectionProfile_update(context map[string]interface{}) string { + return Nprintf(` +resource "google_datastream_connection_profile" "default" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "tf-test-my-profile%{random_suffix}" + + gcs_profile { + bucket = "my-bucket" + root_path = "/path" + } + lifecycle { + prevent_destroy = true + } +} +`, context) +} + +func testAccDatastreamConnectionProfile_update2(context map[string]interface{}, preventDestroy bool) string { + context["lifecycle_block"] = "" + if preventDestroy { + context["lifecycle_block"] = ` + lifecycle { + prevent_destroy = true + }` + } + return Nprintf(` +resource "google_sql_database_instance" "instance" { + name = "tf-test-my-database-instance%{random_suffix}" + database_version = "POSTGRES_14" + region = "us-central1" + settings { + tier = "db-f1-micro" + + ip_configuration { + + // Datastream IPs will vary by region. + authorized_networks { + value = "34.71.242.81" + } + + authorized_networks { + value = "34.72.28.29" + } + + authorized_networks { + value = "34.67.6.157" + } + + authorized_networks { + value = "34.67.234.134" + } + + authorized_networks { + value = "34.72.239.218" + } + } + } + + deletion_protection = "false" +} + +resource "google_sql_database" "db" { + instance = google_sql_database_instance.instance.name + name = "db" +} + +resource "random_password" "pwd" { + length = 16 + special = false +} + +resource "google_sql_user" "user" { + name = "user" + instance = google_sql_database_instance.instance.name + password = random_password.pwd.result +} + +resource "google_datastream_connection_profile" "default" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "tf-test-my-profile%{random_suffix}" + + postgresql_profile { + hostname = google_sql_database_instance.instance.public_ip_address + username = google_sql_user.user.name + password = google_sql_user.user.password + database = google_sql_database.db.name + } + %{lifecycle_block} +} +`, context) +} diff --git a/mmv1/third_party/terraform/utils/datastream_operation.go b/mmv1/third_party/terraform/utils/datastream_operation.go new file mode 100644 index 000000000000..0078bd8fb191 --- /dev/null +++ b/mmv1/third_party/terraform/utils/datastream_operation.go @@ -0,0 +1,85 @@ +package google + +import ( + "bytes" + "encoding/json" + "fmt" + datastream "google.golang.org/api/datastream/v1" + "time" +) + +type DatastreamOperationWaiter struct { + Config *Config + UserAgent string + Project string + CommonOperationWaiter +} + +func (w *DatastreamOperationWaiter) QueryOp() (interface{}, error) { + if w == nil { + return nil, fmt.Errorf("Cannot query operation, it's unset or nil.") + } + // Returns the proper get. + url := fmt.Sprintf("%s%s", w.Config.DatastreamBasePath, w.CommonOperationWaiter.Op.Name) + + return sendRequest(w.Config, "GET", w.Project, url, w.UserAgent, nil) +} + +func (w *DatastreamOperationWaiter) Error() error { + if w != nil && w.Op.Error != nil { + return DatastreamError(*w.Op.Error) + } + return nil +} + +func createDatastreamWaiter(config *Config, op map[string]interface{}, project, activity, userAgent string) (*DatastreamOperationWaiter, error) { + w := &DatastreamOperationWaiter{ + Config: config, + UserAgent: userAgent, + Project: project, + } + if err := w.CommonOperationWaiter.SetOp(op); err != nil { + return nil, err + } + return w, nil +} + +// nolint: deadcode,unused +func datastreamOperationWaitTimeWithResponse(config *Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { + w, err := createDatastreamWaiter(config, op, project, activity, userAgent) + if err != nil { + return err + } + if err := OperationWait(w, activity, timeout, config.PollInterval); err != nil { + return err + } + return json.Unmarshal([]byte(w.CommonOperationWaiter.Op.Response), response) +} + +func datastreamOperationWaitTime(config *Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error { + if val, ok := op["name"]; !ok || val == "" { + // This was a synchronous call - there is no operation to wait for. + return nil + } + w, err := createDatastreamWaiter(config, op, project, activity, userAgent) + if err != nil { + // If w is nil, the op was synchronous. + return err + } + return OperationWait(w, activity, timeout, config.PollInterval) +} + +// DatastreamError wraps datastream.Status and implements the +// error interface so it can be returned. +type DatastreamError datastream.Status + +func (e DatastreamError) Error() string { + var buf bytes.Buffer + + for _, err := range e.Details { + buf.Write(err) + buf.WriteString("\n") + } + + return buf.String() +}