From 30ab2a2eea61cc34f439ddfe7cf840abf746ab1f Mon Sep 17 00:00:00 2001 From: George Peng Date: Wed, 10 Jul 2024 20:55:59 -0400 Subject: [PATCH] Add Apigee environment scope KVMs resource support (#8826) --- .../apigee/EnvironmentKeyvaluemap.yaml | 76 +++++++ .../apigee/EnvironmentKeyvaluemapEntry.yaml | 81 ++++++++ .../apigee_environment_keyvaluemaps.go | 49 +++++ .../apigee_environment_keyvaluemaps.go.erb | 18 ++ ...ee_environment_keyvaluemaps_entries.go.erb | 18 ++ .../apigee_environment_keyvaluemaps.go.erb | 10 + ...igee_environment_keyvaluemaps_basic.tf.erb | 55 +++++ ..._environment_keyvaluemaps_beta_test.tf.erb | 174 ++++++++++++++++ ...ironment_keyvaluemaps_entries_basic.tf.erb | 68 +++++++ ...ment_keyvaluemaps_entries_beta_test.tf.erb | 189 ++++++++++++++++++ ...vironment_keyvaluemaps_entries_test.tf.erb | 110 ++++++++++ ...pigee_environment_keyvaluemaps_test.tf.erb | 96 +++++++++ 12 files changed, 944 insertions(+) create mode 100644 mmv1/products/apigee/EnvironmentKeyvaluemap.yaml create mode 100644 mmv1/products/apigee/EnvironmentKeyvaluemapEntry.yaml create mode 100644 mmv1/templates/terraform/custom_create/apigee_environment_keyvaluemaps.go create mode 100644 mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb create mode 100644 mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb create mode 100644 mmv1/templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_basic.tf.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_beta_test.tf.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_basic.tf.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_beta_test.tf.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_test.tf.erb create mode 100644 mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_test.tf.erb diff --git a/mmv1/products/apigee/EnvironmentKeyvaluemap.yaml b/mmv1/products/apigee/EnvironmentKeyvaluemap.yaml new file mode 100644 index 000000000000..9f6e10c8dff8 --- /dev/null +++ b/mmv1/products/apigee/EnvironmentKeyvaluemap.yaml @@ -0,0 +1,76 @@ +# Copyright 2023 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::Resource +name: 'EnvironmentKeyvaluemaps' +description: | + Collection of key/value string pairs. +references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Using key value maps': 'https://cloud.google.com/apigee/docs/api-platform/cache/key-value-maps' + api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments.keyvaluemaps/create' + +base_url: '{{env_id}}/keyvaluemaps' +create_url: '{{env_id}}/keyvaluemaps' +delete_url: '{{env_id}}/keyvaluemaps/{{name}}' +self_link: '{{env_id}}/keyvaluemaps/{{name}}/entries' +import_format: ['{{env_id}}/keyvaluemaps/{{name}}', '{{env_id}}/{{name}}'] +skip_sweeper: true +examples: + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_basic' + primary_resource_id: 'apigee_environment_keyvaluemaps' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_test: true + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_test' + primary_resource_id: 'apigee_environment_keyvaluemaps' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_docs: true + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_beta_test' + primary_resource_id: 'apigee_environment_keyvaluemaps' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_docs: true + min_version: beta +immutable: true +timeouts: !ruby/object:Api::Timeouts + insert_minutes: 1 + delete_minutes: 1 +autogen_async: true +custom_code: !ruby/object:Provider::Terraform::CustomCode + custom_import: templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb + custom_create: 'templates/terraform/custom_create/apigee_environment_keyvaluemaps.go' + decoder: templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb +parameters: + - !ruby/object:Api::Type::String + name: 'envId' + description: | + The Apigee environment group associated with the Apigee environment, + in the format `organizations/{{org_name}}/environments/{{env_name}}`. + required: true + immutable: true + url_param_only: true +properties: + - !ruby/object:Api::Type::String + name: 'name' + description: | + Required. ID of the key value map. + required: true + immutable: true diff --git a/mmv1/products/apigee/EnvironmentKeyvaluemapEntry.yaml b/mmv1/products/apigee/EnvironmentKeyvaluemapEntry.yaml new file mode 100644 index 000000000000..60a42db49fba --- /dev/null +++ b/mmv1/products/apigee/EnvironmentKeyvaluemapEntry.yaml @@ -0,0 +1,81 @@ +# Copyright 2023 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::Resource +name: 'EnvironmentKeyvaluemapsEntries' +description: | + Creates key value entries in a key value map scoped to an environment. +references: !ruby/object:Api::Resource::ReferenceLinks + guides: + 'Using key value maps': 'https://cloud.google.com/apigee/docs/api-platform/cache/key-value-maps' + api: 'https://cloud.google.com/apigee/docs/reference/apis/apigee/rest/v1/organizations.keyvaluemaps.entries/create' + +base_url: '{{env_keyvaluemap_id}}/entries' +create_url: '{{env_keyvaluemap_id}}/entries' +delete_url: '{{env_keyvaluemap_id}}/entries/{{name}}' +self_link: '{{env_keyvaluemap_id}}/entries/{{name}}' +import_format: + ['{{env_keyvaluemap_id}}/entries/{{name}}', '{{env_keyvaluemap_id}}/{{name}}'] +skip_sweeper: true +examples: + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_entries_basic' + primary_resource_id: 'apigee_environment_keyvaluemaps_entries' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_test: true + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_entries_test' + primary_resource_id: 'apigee_environment_keyvaluemaps_entries' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_docs: true + - !ruby/object:Provider::Terraform::Examples + name: 'apigee_environment_keyvaluemaps_entries_beta_test' + primary_resource_id: 'apigee_environment_keyvaluemaps_entries' + test_env_vars: + org_id: :ORG_ID + billing_account: :BILLING_ACCT + skip_docs: true + min_version: beta +timeouts: !ruby/object:Api::Timeouts + insert_minutes: 1 + delete_minutes: 1 +immutable: true +autogen_async: true +custom_code: !ruby/object:Provider::Terraform::CustomCode + custom_import: templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb +parameters: + - !ruby/object:Api::Type::String + name: 'env_keyvaluemap_id' + description: | + The Apigee environment keyvalumaps Id associated with the Apigee environment, + in the format `organizations/{{org_name}}/environments/{{env_name}}/keyvaluemaps/{{keyvaluemap_name}}`. + required: true + immutable: true + url_param_only: true +properties: + - !ruby/object:Api::Type::String + name: 'name' + description: | + Required. Resource URI that can be used to identify the scope of the key value map entries. + required: true + immutable: true + - !ruby/object:Api::Type::String + name: 'value' + description: | + Required. Data or payload that is being retrieved and associated with the unique key. + required: true + immutable: true diff --git a/mmv1/templates/terraform/custom_create/apigee_environment_keyvaluemaps.go b/mmv1/templates/terraform/custom_create/apigee_environment_keyvaluemaps.go new file mode 100644 index 000000000000..449c590700c5 --- /dev/null +++ b/mmv1/templates/terraform/custom_create/apigee_environment_keyvaluemaps.go @@ -0,0 +1,49 @@ +userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent) +if err != nil { + return err +} + +obj := make(map[string]interface{}) +nameProp, err := expandApigeeEnvironmentKeyvaluemapsName(d.Get("name"), d, config) +if err != nil { + return err +} else if v, ok := d.GetOkExists("name"); !tpgresource.IsEmptyValue(reflect.ValueOf(nameProp)) && (ok || !reflect.DeepEqual(v, nameProp)) { + obj["name"] = nameProp +} + +url, err := tpgresource.ReplaceVars(d, config, "{{ApigeeBasePath}}{{env_id}}/keyvaluemaps") +if err != nil { + return err +} + +log.Printf("[DEBUG] Creating new EnvironmentKeyvaluemaps: %#v", obj) +billingProject := "" + +// err == nil indicates that the billing_project value was found +if bp, err := tpgresource.GetBillingProject(d, config); err == nil { + billingProject = bp +} + +res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{ + Config: config, + Method: "POST", + Project: billingProject, + RawURL: url, + UserAgent: userAgent, + Body: obj, + Timeout: d.Timeout(schema.TimeoutCreate), +}) +if err != nil { + return fmt.Errorf("Error creating EnvironmentKeyvaluemaps: %s", err) +} + +// Store the ID now +id, err := tpgresource.ReplaceVars(d, config, "{{env_id}}/keyvaluemaps/{{name}}") +if err != nil { + return fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) + +log.Printf("[DEBUG] Finished creating EnvironmentKeyvaluemaps %q: %#v", d.Id(), res) + +return resourceApigeeEnvironmentKeyvaluemapsRead(d, meta) \ No newline at end of file diff --git a/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb b/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb new file mode 100644 index 000000000000..873a7d5f8b98 --- /dev/null +++ b/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps.go.erb @@ -0,0 +1,18 @@ +config := meta.(*transport_tpg.Config) + +// current import_formats cannot import fields with forward slashes in their value +if err := tpgresource.ParseImportId([]string{ + "(?P.+)/keyvaluemaps/(?P.+)", + "(?P.+)/(?P.+)", + }, d, config); err != nil { + return nil, err + } + +// Replace import id for the resource id +id, err := tpgresource.ReplaceVars(d, config, "{{env_id}}/keyvaluemaps/{{name}}") +if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) + +return []*schema.ResourceData{d}, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb b/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb new file mode 100644 index 000000000000..43fe2de5a983 --- /dev/null +++ b/mmv1/templates/terraform/custom_import/apigee_environment_keyvaluemaps_entries.go.erb @@ -0,0 +1,18 @@ +config := meta.(*transport_tpg.Config) + +// current import_formats cannot import fields with forward slashes in their value +if err := tpgresource.ParseImportId([]string{ + "(?P.+)/entries/(?P.+)", + "(?P.+)/(?P.+)", + }, d, config); err != nil { + return nil, err + } + +// Replace import id for the resource id +id, err := tpgresource.ReplaceVars(d, config, "{{env_keyvaluemap_id}}/entries/{{name}}") +if err != nil { + return nil, fmt.Errorf("Error constructing id: %s", err) +} +d.SetId(id) + +return []*schema.ResourceData{d}, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb b/mmv1/templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb new file mode 100644 index 000000000000..50674a259175 --- /dev/null +++ b/mmv1/templates/terraform/decoders/apigee_environment_keyvaluemaps.go.erb @@ -0,0 +1,10 @@ +config := meta.(*transport_tpg.Config) +name, err := tpgresource.ReplaceVars(d, config, "{{name}}") +if err != nil { + return nil, err +} +res["name"] = name +// "encrypted" field is retained for backward compatibility and the value of encrypted will always be true. Apigee X and hybrid do not support unencrypted key value maps. +res["encrypted"] = true + +return res, nil \ No newline at end of file diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_basic.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_basic.tf.erb new file mode 100644 index 000000000000..b1d659831ecb --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_basic.tf.erb @@ -0,0 +1,55 @@ +data "google_client_config" "current" {} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = data.google_client_config.current.project + authorized_network = google_compute_network.apigee_network.id + depends_on = [google_service_networking_connection.apigee_vpc_connection] +} + +resource "google_apigee_environment" "apigee_environment" { + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test-instance" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "<%= ctx[:primary_resource_id] %>" { + env_id = google_apigee_environment.apigee_environment.id + name = "tf-test-env-kvms" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +} diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_beta_test.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_beta_test.tf.erb new file mode 100644 index 000000000000..c492ac5c7ee4 --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_beta_test.tf.erb @@ -0,0 +1,174 @@ +resource "google_project" "project" { + provider = google-beta + + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" + billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>" + } + + resource "google_project_service" "apigee" { + provider = google-beta + + project = google_project.project.project_id + service = "apigee.googleapis.com" + } + + resource "google_project_service" "compute" { + provider = google-beta + + project = google_project.project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.apigeeconnect] + } + + resource "google_project_service" "servicenetworking" { + provider = google-beta + + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" + depends_on = [google_project_service.compute] + } + + resource "google_project_service" "kms" { + provider = google-beta + + project = google_project.project.project_id + service = "cloudkms.googleapis.com" + depends_on = [google_project_service.servicenetworking] + } + + resource "google_project_service" "apigeeconnect" { + provider = google-beta + + project = google_project.project.project_id + service = "apigeeconnect.googleapis.com" + depends_on = [google_project_service.apigee] +} + + resource "google_compute_network" "apigee_network" { + provider = google-beta + + name = "apigee-network" + project = google_project.project.project_id + depends_on = [google_project_service.compute] + } + + resource "google_compute_global_address" "apigee_range" { + provider = google-beta + + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id + } + + resource "google_service_networking_connection" "apigee_vpc_connection" { + provider = google-beta + + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] + depends_on = [google_project_service.servicenetworking] + } + + resource "google_kms_key_ring" "apigee_keyring" { + provider = google-beta + + name = "apigee-keyring" + location = "us-central1" + project = google_project.project.project_id + depends_on = [google_project_service.kms] + } + + resource "google_kms_crypto_key" "apigee_key" { + provider = google-beta + + name = "apigee-key" + key_ring = google_kms_key_ring.apigee_keyring.id + } + + resource "google_project_service_identity" "apigee_sa" { + provider = google-beta + + project = google_project.project.project_id + service = google_project_service.apigee.service + } + + resource "google_kms_crypto_key_iam_binding" "apigee_sa_keyuser" { + provider = google-beta + + crypto_key_id = google_kms_crypto_key.apigee_key.id + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + + members = [ + "serviceAccount:${google_project_service_identity.apigee_sa.email}", + ] + } + + resource "google_apigee_organization" "apigee_org" { + provider = google-beta + + display_name = "apigee-org" + description = "Terraform-managed Apigee Org" + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_type = "CLOUD" + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_kms_crypto_key_iam_binding.apigee_sa_keyuser, + ] + } + +resource "google_apigee_environment" "apigee_environment" { + provider = google-beta + + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env%{random_suffix}" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + provider = google-beta + + name = "tf-test%{random_suffix}" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + provider = google-beta + + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "<%= ctx[:primary_resource_id] %>" { + provider = google-beta + + env_id = google_apigee_environment.apigee_environment.id + name = "tf-test-env-kvms%{random_suffix}" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +} diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_basic.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_basic.tf.erb new file mode 100644 index 000000000000..2eaac2c37cf7 --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_basic.tf.erb @@ -0,0 +1,68 @@ +data "google_client_config" "current" {} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = data.google_client_config.current.project + authorized_network = google_compute_network.apigee_network.id + depends_on = [google_service_networking_connection.apigee_vpc_connection] +} + +resource "google_apigee_environment" "apigee_environment" { + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test-instance" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "apigee_environment_keyvaluemaps" { + env_id = google_apigee_environment.create_apigee_environment.id + name = "tf-test-env-kvms" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +} + +resource "google_apigee_environment_keyvaluemaps_entries" "<%= ctx[:primary_resource_id] %>" { + env_keyvaluemap_id = google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps.id + name = "testName" + value = "testValue" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment, + google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps + ] +} diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_beta_test.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_beta_test.tf.erb new file mode 100644 index 000000000000..64d2e5a7757c --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_beta_test.tf.erb @@ -0,0 +1,189 @@ +resource "google_project" "project" { + provider = google-beta + + project_id = "tf-test%{random_suffix}" + name = "tf-test%{random_suffix}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" + billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>" + } + + resource "google_project_service" "apigee" { + provider = google-beta + + project = google_project.project.project_id + service = "apigee.googleapis.com" + } + + resource "google_project_service" "compute" { + provider = google-beta + + project = google_project.project.project_id + service = "compute.googleapis.com" + depends_on = [google_project_service.apigeeconnect] + } + + resource "google_project_service" "servicenetworking" { + provider = google-beta + + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" + depends_on = [google_project_service.compute] + } + + resource "google_project_service" "kms" { + provider = google-beta + + project = google_project.project.project_id + service = "cloudkms.googleapis.com" + depends_on = [google_project_service.servicenetworking] + } + + resource "google_project_service" "apigeeconnect" { + provider = google-beta + + project = google_project.project.project_id + service = "apigeeconnect.googleapis.com" + depends_on = [google_project_service.apigee] +} + + resource "google_compute_network" "apigee_network" { + provider = google-beta + + name = "apigee-network" + project = google_project.project.project_id + depends_on = [google_project_service.compute] + } + + resource "google_compute_global_address" "apigee_range" { + provider = google-beta + + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id + } + + resource "google_service_networking_connection" "apigee_vpc_connection" { + provider = google-beta + + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] + depends_on = [google_project_service.servicenetworking] + } + + resource "google_kms_key_ring" "apigee_keyring" { + provider = google-beta + + name = "apigee-keyring" + location = "us-central1" + project = google_project.project.project_id + depends_on = [google_project_service.kms] + } + + resource "google_kms_crypto_key" "apigee_key" { + provider = google-beta + + name = "apigee-key" + key_ring = google_kms_key_ring.apigee_keyring.id + } + + resource "google_project_service_identity" "apigee_sa" { + provider = google-beta + + project = google_project.project.project_id + service = google_project_service.apigee.service + } + + resource "google_kms_crypto_key_iam_binding" "apigee_sa_keyuser" { + provider = google-beta + + crypto_key_id = google_kms_crypto_key.apigee_key.id + role = "roles/cloudkms.cryptoKeyEncrypterDecrypter" + + members = [ + "serviceAccount:${google_project_service_identity.apigee_sa.email}", + ] + } + + resource "google_apigee_organization" "apigee_org" { + provider = google-beta + + display_name = "apigee-org" + description = "Terraform-managed Apigee Org" + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_type = "CLOUD" + runtime_database_encryption_key_name = google_kms_crypto_key.apigee_key.id + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_kms_crypto_key_iam_binding.apigee_sa_keyuser, + ] + } + +resource "google_apigee_environment" "apigee_environment" { + provider = google-beta + + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env%{random_suffix}" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + provider = google-beta + + name = "tf-test%{random_suffix}" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + provider = google-beta + + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "apigee_environment_keyvaluemaps" { + provider = google-beta + + env_id = google_apigee_environment.apigee_environment.id + name = "tf-test-env-kvms%{random_suffix}" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +} + +resource "google_apigee_environment_keyvaluemaps_entries" "<%= ctx[:primary_resource_id] %>" { + provider = google-beta + + env_keyvaluemap_id = google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps.id + name = "testName" + value = "testValue" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment, + google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps + ] +} diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_test.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_test.tf.erb new file mode 100644 index 000000000000..28fe4dc2d515 --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_entries_test.tf.erb @@ -0,0 +1,110 @@ +resource "google_project" "project" { + project_id = "tf-test-%{random_suffix}" + name = "tf-test-%{random_suffix}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" + billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>" +} + +resource "google_project_service" "apigee" { + project = google_project.project.project_id + service = "apigee.googleapis.com" +} + +resource "google_project_service" "compute" { + project = google_project.project.project_id + service = "compute.googleapis.com" + depends_on = [ google_project_service.servicenetworking ] +} + +resource "google_project_service" "servicenetworking" { + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" + depends_on = [ google_project_service.apigee ] +} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" + project = google_project.project.project_id + depends_on = [ google_project_service.compute ] +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_type = "CLOUD" + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_project_service.apigee + ] +} + +resource "google_apigee_environment" "apigee_environment" { + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env%{random_suffix}" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test%{random_suffix}" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "apigee_environment_keyvaluemaps" { + env_id = google_apigee_environment.apigee_environment.id + name = "tf-test-env-kvms%{random_suffix}" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +} + +resource "google_apigee_environment_keyvaluemaps_entries" "<%= ctx[:primary_resource_id] %>" { + + env_keyvaluemap_id = google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps.id + name = "testName" + value = "testValue" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment, + google_apigee_environment_keyvaluemaps.apigee_environment_keyvaluemaps + ] +} diff --git a/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_test.tf.erb b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_test.tf.erb new file mode 100644 index 000000000000..dcf201842557 --- /dev/null +++ b/mmv1/templates/terraform/examples/apigee_environment_keyvaluemaps_test.tf.erb @@ -0,0 +1,96 @@ +resource "google_project" "project" { + project_id = "tf-test-%{random_suffix}" + name = "tf-test-%{random_suffix}" + org_id = "<%= ctx[:test_env_vars]['org_id'] %>" + billing_account = "<%= ctx[:test_env_vars]['billing_account'] %>" +} + +resource "google_project_service" "apigee" { + project = google_project.project.project_id + service = "apigee.googleapis.com" +} + +resource "google_project_service" "compute" { + project = google_project.project.project_id + service = "compute.googleapis.com" + depends_on = [ google_project_service.servicenetworking ] +} + +resource "google_project_service" "servicenetworking" { + project = google_project.project.project_id + service = "servicenetworking.googleapis.com" + depends_on = [ google_project_service.apigee ] +} + +resource "google_compute_network" "apigee_network" { + name = "apigee-network" + project = google_project.project.project_id + depends_on = [ google_project_service.compute ] +} + +resource "google_compute_global_address" "apigee_range" { + name = "apigee-range" + purpose = "VPC_PEERING" + address_type = "INTERNAL" + prefix_length = 16 + network = google_compute_network.apigee_network.id + project = google_project.project.project_id +} + +resource "google_service_networking_connection" "apigee_vpc_connection" { + network = google_compute_network.apigee_network.id + service = "servicenetworking.googleapis.com" + reserved_peering_ranges = [google_compute_global_address.apigee_range.name] +} + +resource "google_apigee_organization" "apigee_org" { + analytics_region = "us-central1" + project_id = google_project.project.project_id + authorized_network = google_compute_network.apigee_network.id + billing_type = "EVALUATION" + runtime_type = "CLOUD" + properties { + property { + name = "features.hybrid.enabled" + value = "true" + } + property { + name = "features.mart.connect.enabled" + value = "true" + } + } + + depends_on = [ + google_service_networking_connection.apigee_vpc_connection, + google_project_service.apigee + ] +} + +resource "google_apigee_environment" "apigee_environment" { + org_id = google_apigee_organization.apigee_org.id + name = "tf-test-env%{random_suffix}" + description = "Apigee Environment" + display_name = "Apigee Environment" +} + +resource "google_apigee_instance" "apigee_instance" { + name = "tf-test%{random_suffix}" + location = "us-central1" + org_id = google_apigee_organization.apigee_org.id +} + +resource "google_apigee_instance_attachment" "apigee_instance_attachment" { + instance_id = google_apigee_instance.apigee_instance.id + environment = google_apigee_environment.apigee_environment.name +} + +resource "google_apigee_environment_keyvaluemaps" "<%= ctx[:primary_resource_id] %>" { + env_id = google_apigee_environment.apigee_environment.id + name = "tf-test-env-kvms%{random_suffix}" + depends_on = [ + google_apigee_organization.apigee_org, + google_apigee_environment.apigee_environment, + google_apigee_instance.apigee_instance, + google_apigee_instance_attachment.apigee_instance_attachment + ] +}