From 5685a8502e10cb869d839b3682cdf5f9a56016d1 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Fri, 26 Aug 2022 11:40:02 -0700 Subject: [PATCH 01/13] Added datastream connection profile --- mmv1/products/datastream/api.yaml | 221 ++++++++++++++++++ mmv1/products/datastream/terraform.yaml | 48 ++++ ...datastream_connection_profile_basic.tf.erb | 3 + .../datastream_connection_profile_full.tf.erb | 15 ++ 4 files changed, 287 insertions(+) create mode 100644 mmv1/products/datastream/api.yaml create mode 100644 mmv1/products/datastream/terraform.yaml create mode 100644 mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb create mode 100644 mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml new file mode 100644 index 000000000000..486fdd619dcd --- /dev/null +++ b/mmv1/products/datastream/api.yaml @@ -0,0 +1,221 @@ +# Copyright 2020 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" + 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. + 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' + conflicts: + - gcs_profile + - mysql_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' + conflicts: + - oracle_profile + - mysql_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::Integer + name: 'rootPath' + description: | + The root path inside the Cloud Storage bucket. + - !ruby/object:Api::Type::NestedObject + name: 'mysqlProfile' + conflicts: + - gcs_profile + - oracle_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: '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..2379651dbb36 --- /dev/null +++ b/mmv1/products/datastream/terraform.yaml @@ -0,0 +1,48 @@ +# Copyright 2020 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 + autogen_async: true + timeouts: !ruby/object:Api::Timeouts + insert_minutes: 20 + delete_minutes: 20 + properties: + oracleProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + mysqlProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + mysqlProfile.sslConfig.clientKey: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + mysqlProfile.sslConfig.clientCertificate: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + mysqlProfile.sslConfig.caCertificate: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + forwardSshConnectivity.password: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + forwardSshConnectivity.privateKey: !ruby/object:Overrides::Terraform::PropertyOverride + sensitive: true + examples: + - !ruby/object:Provider::Terraform::Examples + name: "datastream_connection_profile_basic" + primary_resource_id: "default" + # vars: + # property_name_1: "property_a" + # property_name_2: "property_b" + - !ruby/object:Provider::Terraform::Examples + name: "datastream_connection_profile_full" + primary_resource_id: "default" + # vars: + # property_name_1: "property_a" + # property_name_2: "property_b" 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..7a9c6a03701b --- /dev/null +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb @@ -0,0 +1,3 @@ +resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { + display_name = "Connection profile" +} \ 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..e62d6d1acbe1 --- /dev/null +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb @@ -0,0 +1,15 @@ +resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { + display_name = "Connection profile" + + 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 From 59ae10ba242ac8313516091486ec1d1b08510265 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 29 Aug 2022 11:44:17 -0700 Subject: [PATCH 02/13] Updated resource and tests to get to passing basic/full tests --- mmv1/products/datastream/api.yaml | 69 +++++++++++++++++-- mmv1/products/datastream/terraform.yaml | 33 +++++++-- ...e_forward_ssh_connectivity_password.go.erb | 18 +++++ ...orward_ssh_connectivity_private_key.go.erb | 18 +++++ ...tion_profile_mysql_profile_password.go.erb | 18 +++++ ...l_profile_ssl_config_ca_certificate.go.erb | 18 +++++ ...ofile_ssl_config_client_certificate.go.erb | 18 +++++ ...mysql_profile_ssl_config_client_key.go.erb | 18 +++++ ...ion_profile_oracle_profile_password.go.erb | 18 +++++ ...profile_postgresql_profile_password.go.erb | 18 +++++ ...datastream_connection_profile_basic.tf.erb | 9 ++- .../datastream_connection_profile_full.tf.erb | 8 ++- 12 files changed, 248 insertions(+), 15 deletions(-) create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_password.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_forward_ssh_connectivity_private_key.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_password.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_ca_certificate.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_certificate.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_mysql_profile_ssl_config_client_key.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_oracle_profile_password.go.erb create mode 100644 mmv1/templates/terraform/custom_flatten/datastream_connection_profile_postgresql_profile_password.go.erb diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml index 486fdd619dcd..065da5faf8d4 100644 --- a/mmv1/products/datastream/api.yaml +++ b/mmv1/products/datastream/api.yaml @@ -44,6 +44,10 @@ 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' @@ -55,6 +59,20 @@ objects: name: 'name' output: true description: The resource's name. + - !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 - !ruby/object:Api::Type::KeyValuePairs name: 'labels' description: Labels. @@ -64,9 +82,11 @@ objects: description: Display name. - !ruby/object:Api::Type::NestedObject name: 'oracleProfile' - conflicts: + exactly_one_of: + - oracle_profile - gcs_profile - mysql_profile + - postgresql_profile description: | Oracle database profile. properties: @@ -100,9 +120,11 @@ objects: description: Connection string attributes - !ruby/object:Api::Type::NestedObject name: 'gcsProfile' - conflicts: + exactly_one_of: - oracle_profile + - gcs_profile - mysql_profile + - postgresql_profile description: | Cloud Storage bucket profile. properties: @@ -111,15 +133,17 @@ objects: required: true description: | The Cloud Storage bucket name. - - !ruby/object:Api::Type::Integer + - !ruby/object:Api::Type::String name: 'rootPath' description: | The root path inside the Cloud Storage bucket. - !ruby/object:Api::Type::NestedObject name: 'mysqlProfile' - conflicts: - - gcs_profile + exactly_one_of: - oracle_profile + - gcs_profile + - mysql_profile + - postgresql_profile description: | MySQL database profile. properties: @@ -185,6 +209,41 @@ objects: 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: | diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml index 2379651dbb36..09e02bd30df9 100644 --- a/mmv1/products/datastream/terraform.yaml +++ b/mmv1/products/datastream/terraform.yaml @@ -14,6 +14,8 @@ --- !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}}"] autogen_async: true timeouts: !ruby/object:Api::Timeouts insert_minutes: 20 @@ -21,28 +23,47 @@ overrides: !ruby/object:Overrides::ResourceOverrides 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: - # property_name_1: "property_a" - # property_name_2: "property_b" + vars: + connection_profile_id: "my-profile" - !ruby/object:Provider::Terraform::Examples name: "datastream_connection_profile_full" primary_resource_id: "default" - # vars: - # property_name_1: "property_a" - # property_name_2: "property_b" + # 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" 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 index 7a9c6a03701b..516b5b93b2c9 100644 --- a/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_basic.tf.erb @@ -1,3 +1,10 @@ resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { - display_name = "Connection profile" + 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 index e62d6d1acbe1..4446b36eb872 100644 --- a/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_full.tf.erb @@ -1,15 +1,17 @@ resource "google_datastream_connection_profile" "<%= ctx[:primary_resource_id] %>" { - display_name = "Connection profile" + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "<%= ctx[:vars]['connection_profile_id'] %>" gcs_profile { - bucket = "my-bucket" + bucket = "my-bucket" root_path = "/path" } forward_ssh_connectivity { hostname = "google.com" username = "my-user" - port = 8022 + port = 8022 password = "swordfish" } } \ No newline at end of file From d5b0dbf3e97639bb32d5da233e984ab3e6f92480 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Mon, 29 Aug 2022 11:57:41 -0700 Subject: [PATCH 03/13] Added update test --- ...urce_datastream_connection_profile_test.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go 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..c7cf05f68a56 --- /dev/null +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -0,0 +1,41 @@ +package google + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccDatastreamConnectionProfile_update(t *testing.T) { + t.Parallel() + + context := map[string]interface{}{ + "random_suffix": randString(t, 10), + } + + vcrTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t), + Steps: []resource.TestStep{ + { + Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBasicExample(context), + }, + { + ResourceName: "google_datastream_connection_profile.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, + }, + { + Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileFullExample(context), + }, + { + ResourceName: "google_datastream_connection_profile.default", + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "forward_ssh_connectivity.0.password"}, + }, + }, + }) +} From d74bf4827f42f22815a289effd88234d0a980b78 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 09:14:10 -0700 Subject: [PATCH 04/13] Corrected license dates --- mmv1/products/datastream/api.yaml | 2 +- mmv1/products/datastream/terraform.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml index 065da5faf8d4..718c1b63bbb5 100644 --- a/mmv1/products/datastream/api.yaml +++ b/mmv1/products/datastream/api.yaml @@ -1,4 +1,4 @@ -# Copyright 2020 Google Inc. +# 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 diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml index 09e02bd30df9..492c39c4dda0 100644 --- a/mmv1/products/datastream/terraform.yaml +++ b/mmv1/products/datastream/terraform.yaml @@ -1,4 +1,4 @@ -# Copyright 2020 Google Inc. +# 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 From 5266ca2d67f04ceef85e2eb4a18983677bbfb40a Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 09:21:45 -0700 Subject: [PATCH 05/13] Moved url params into parameters array --- mmv1/products/datastream/api.yaml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml index 718c1b63bbb5..ef348315f742 100644 --- a/mmv1/products/datastream/api.yaml +++ b/mmv1/products/datastream/api.yaml @@ -54,11 +54,7 @@ objects: 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. - properties: - - !ruby/object:Api::Type::String - name: 'name' - output: true - description: The resource's name. + parameters: - !ruby/object:Api::Type::String name: connectionProfileId description: |- @@ -73,6 +69,11 @@ objects: 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. From d7cdfd3bc1ef853e78d22931488a74720d920acd Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 09:26:51 -0700 Subject: [PATCH 06/13] Removed long timeouts --- mmv1/products/datastream/terraform.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml index 492c39c4dda0..4d657b933056 100644 --- a/mmv1/products/datastream/terraform.yaml +++ b/mmv1/products/datastream/terraform.yaml @@ -17,9 +17,6 @@ overrides: !ruby/object:Overrides::ResourceOverrides id_format: projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}} import_format: ["projects/{{project}}/locations/{{location}}/connectionProfiles/{{connection_profile_id}}"] autogen_async: true - timeouts: !ruby/object:Api::Timeouts - insert_minutes: 20 - delete_minutes: 20 properties: oracleProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride sensitive: true From b5a58a6b38823b561e33a91bf6666a5176347253 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 09:56:38 -0700 Subject: [PATCH 07/13] Ensured that update test actually tests update --- ...urce_datastream_connection_profile_test.go | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) 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 index c7cf05f68a56..7530e2146377 100644 --- a/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -1,6 +1,7 @@ package google import ( + "fmt" "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" @@ -19,7 +20,7 @@ func TestAccDatastreamConnectionProfile_update(t *testing.T) { CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t), Steps: []resource.TestStep{ { - Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileBasicExample(context), + Config: testAccDatastreamConnectionProfile_update(context), }, { ResourceName: "google_datastream_connection_profile.default", @@ -28,14 +29,60 @@ func TestAccDatastreamConnectionProfile_update(t *testing.T) { ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, }, { - Config: testAccDatastreamConnectionProfile_datastreamConnectionProfileFullExample(context), + Config: testAccDatastreamConnectionProfile_update2(context, true), }, { ResourceName: "google_datastream_connection_profile.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "forward_ssh_connectivity.0.password"}, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, + }, + { + // 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 { + lifecycleBlock := "" + if preventDestroy { + lifecycleBlock = ` + lifecycle { + prevent_destroy = true + }` + } + return fmt.Sprintf(` +resource "google_datastream_connection_profile" "default" { + display_name = "Connection profile" + location = "us-central1" + connection_profile_id = "tf-test-my-profile%s" + + gcs_profile { + bucket = "my-other-bucket" + root_path = "/path" + } + %s +} +`, context["random_suffix"], lifecycleBlock) +} From 065f680d36c0a653e9d8542257d60663f96c15c5 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 10:21:49 -0700 Subject: [PATCH 08/13] Made update test move from gcs bucket to postgresql database instance --- ...urce_datastream_connection_profile_test.go | 58 ++++++++++++++----- 1 file changed, 45 insertions(+), 13 deletions(-) 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 index 7530e2146377..2bc32d15d61e 100644 --- a/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -1,13 +1,14 @@ package google import ( - "fmt" "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{}{ @@ -15,8 +16,11 @@ func TestAccDatastreamConnectionProfile_update(t *testing.T) { } vcrTest(t, resource.TestCase{ - PreCheck: func() { testAccPreCheck(t) }, - Providers: testAccProviders, + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + ExternalProviders: map[string]resource.ExternalProvider{ + "random": {}, + }, CheckDestroy: testAccCheckDatastreamConnectionProfileDestroyProducer(t), Steps: []resource.TestStep{ { @@ -63,26 +67,54 @@ resource "google_datastream_connection_profile" "default" { `, context) } - func testAccDatastreamConnectionProfile_update2(context map[string]interface{}, preventDestroy bool) string { - lifecycleBlock := "" + context["lifecycle_block"] = "" if preventDestroy { - lifecycleBlock = ` + context["lifecycle_block"] = ` lifecycle { prevent_destroy = true }` } - return fmt.Sprintf(` + 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" + } + + 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%{random_suffix}" + 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%s" + connection_profile_id = "tf-test-my-profile%{random_suffix}" - gcs_profile { - bucket = "my-other-bucket" - root_path = "/path" + 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 } - %s + %{lifecycle_block} } -`, context["random_suffix"], lifecycleBlock) +`, context) } From 1163d50c7a7c79862cc690c1857b8101b69e184d Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Tue, 30 Aug 2022 15:42:56 -0700 Subject: [PATCH 09/13] Switched to handwritten operation due to unexpected error structure --- mmv1/products/datastream/api.yaml | 17 ---- mmv1/products/datastream/terraform.yaml | 1 - .../terraform/utils/datastream_operation.go | 85 +++++++++++++++++++ 3 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 mmv1/third_party/terraform/utils/datastream_operation.go diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml index ef348315f742..29f9961046ea 100644 --- a/mmv1/products/datastream/api.yaml +++ b/mmv1/products/datastream/api.yaml @@ -23,23 +23,6 @@ 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' diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml index 4d657b933056..83a68e7d4c08 100644 --- a/mmv1/products/datastream/terraform.yaml +++ b/mmv1/products/datastream/terraform.yaml @@ -16,7 +16,6 @@ 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}}"] - autogen_async: true properties: oracleProfile.password: !ruby/object:Overrides::Terraform::PropertyOverride sensitive: true 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() +} From b90ea5e621ac07929c2b69336d89f42858fa9e33 Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Wed, 31 Aug 2022 09:53:11 -0700 Subject: [PATCH 10/13] Added authorized networks to sql database instance --- mmv1/products/datastream/terraform.yaml | 9 +++ ...astream_connection_profile_postgres.tf.erb | 63 +++++++++++++++++++ ...urce_datastream_connection_profile_test.go | 30 ++++++++- 3 files changed, 99 insertions(+), 3 deletions(-) create mode 100644 mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb diff --git a/mmv1/products/datastream/terraform.yaml b/mmv1/products/datastream/terraform.yaml index 83a68e7d4c08..8bfa3dd79c70 100644 --- a/mmv1/products/datastream/terraform.yaml +++ b/mmv1/products/datastream/terraform.yaml @@ -63,3 +63,12 @@ overrides: !ruby/object:Overrides::ResourceOverrides - "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/examples/datastream_connection_profile_postgres.tf.erb b/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb new file mode 100644 index 000000000000..420e43d3d903 --- /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 index 2bc32d15d61e..93cc422fdbce 100644 --- a/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -81,8 +81,32 @@ resource "google_sql_database_instance" "instance" { database_version = "POSTGRES_14" region = "us-central1" settings { - tier = "db-f1-micro" - } + 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" } @@ -98,7 +122,7 @@ resource "random_password" "pwd" { } resource "google_sql_user" "user" { - name = "user%{random_suffix}" + name = "user" instance = google_sql_database_instance.instance.name password = random_password.pwd.result } From 0c0883bb2b954716166cb9055b68baeca3f815cf Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Wed, 31 Aug 2022 11:06:47 -0700 Subject: [PATCH 11/13] fixed whitespace --- .../examples/datastream_connection_profile_postgres.tf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb b/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb index 420e43d3d903..331479017807 100644 --- a/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb +++ b/mmv1/templates/terraform/examples/datastream_connection_profile_postgres.tf.erb @@ -5,7 +5,7 @@ resource "google_sql_database_instance" "instance" { settings { tier = "db-f1-micro" - ip_configuration { + ip_configuration { // Datastream IPs will vary by region. authorized_networks { From 799ad3379b352f80da1e4862be284bf3438521da Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Thu, 1 Sep 2022 13:41:17 -0700 Subject: [PATCH 12/13] Re-added async definitions Async definitions are used to figure out whether to call async code even if the async code isn't autogenerated --- mmv1/products/datastream/api.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/mmv1/products/datastream/api.yaml b/mmv1/products/datastream/api.yaml index 29f9961046ea..ef348315f742 100644 --- a/mmv1/products/datastream/api.yaml +++ b/mmv1/products/datastream/api.yaml @@ -23,6 +23,23 @@ 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' From 8ace30783b1cc2247d11994611f77fe9761bd37e Mon Sep 17 00:00:00 2001 From: Stephen Lewis Date: Thu, 1 Sep 2022 14:04:17 -0700 Subject: [PATCH 13/13] Added postgresql password to importstateverifyignore --- .../tests/resource_datastream_connection_profile_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 93cc422fdbce..ed0424bcefe0 100644 --- a/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go +++ b/mmv1/third_party/terraform/tests/resource_datastream_connection_profile_test.go @@ -39,7 +39,7 @@ func TestAccDatastreamConnectionProfile_update(t *testing.T) { ResourceName: "google_datastream_connection_profile.default", ImportState: true, ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"connection_profile_id", "location"}, + ImportStateVerifyIgnore: []string{"connection_profile_id", "location", "postgresql_profile.0.password"}, }, { // Disable prevent_destroy