diff --git a/blueprints/apigee/bigquery-analytics/README.md b/blueprints/apigee/bigquery-analytics/README.md index 5261f72e..3eeeaaf7 100644 --- a/blueprints/apigee/bigquery-analytics/README.md +++ b/blueprints/apigee/bigquery-analytics/README.md @@ -53,14 +53,13 @@ Do the following to verify that everything works as expected. 4. At 4am (UTC) every day the Cloud Scheduler will run and will export the analytics to the BigQuery table. Double-check they are there. - ## Variables | name | description | type | required | default | |---|---|:---:|:---:|:---:| | [envgroups](variables.tf#L24) | Environment groups (NAME => [HOSTNAMES]). | map(list(string)) | ✓ | | -| [environments](variables.tf#L30) | Environments. | map(object({…})) | ✓ | | -| [instances](variables.tf#L46) | Instance. | map(object({…})) | ✓ | | +| [environments](variables.tf#L30) | Environments. | map(object({…})) | ✓ | | +| [instances](variables.tf#L45) | Instance. | map(object({…})) | ✓ | | | [project_id](variables.tf#L91) | Project ID. | string | ✓ | | | [psc_config](variables.tf#L97) | PSC configuration. | map(string) | ✓ | | | [datastore_name](variables.tf#L17) | Datastore. | string | | "gcs" | @@ -74,7 +73,6 @@ Do the following to verify that everything works as expected. | name | description | sensitive | |---|---|:---:| | [ip_address](outputs.tf#L17) | IP address. | | - ## Test @@ -92,13 +90,13 @@ module "test" { environments = { apis-test = { envgroups = ["test"] - regions = ["europe-west1"] } } instances = { europe-west1 = { runtime_ip_cidr_range = "10.0.4.0/22" troubleshooting_ip_cidr_range = "10.1.0.0/28" + environments = ["apis-test"] } } psc_config = { diff --git a/blueprints/apigee/bigquery-analytics/variables.tf b/blueprints/apigee/bigquery-analytics/variables.tf index 53f329b0..3552d58e 100644 --- a/blueprints/apigee/bigquery-analytics/variables.tf +++ b/blueprints/apigee/bigquery-analytics/variables.tf @@ -38,7 +38,6 @@ variable "environments" { })) iam = optional(map(list(string))) envgroups = optional(list(string)) - regions = optional(list(string)) })) nullable = false } @@ -52,6 +51,7 @@ variable "instances" { troubleshooting_ip_cidr_range = string disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) + environments = optional(list(string)) })) nullable = false } diff --git a/blueprints/apigee/network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/apigee.tf b/blueprints/apigee/network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/apigee.tf index 2923f1f6..afad0f0d 100644 --- a/blueprints/apigee/network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/apigee.tf +++ b/blueprints/apigee/network-patterns/nb-glb-psc-neg-sb-psc-ilbl7-hybrid-neg/apigee.tf @@ -76,11 +76,11 @@ module "apigee" { environments = { (local.environment) = { envgroups = [local.envgroup] - regions = [var.region] } } instances = { (var.region) = { + environments = [local.environment] runtime_ip_cidr_range = var.apigee_runtime_ip_cidr_range troubleshooting_ip_cidr_range = var.apigee_troubleshooting_ip_cidr_range } diff --git a/modules/apigee/README.md b/modules/apigee/README.md index 4d33df10..7692d6f4 100644 --- a/modules/apigee/README.md +++ b/modules/apigee/README.md @@ -54,7 +54,7 @@ module "apigee" { } } } -# tftest modules=1 resources=5 inventory=minimal-cloud.yaml +# tftest modules=1 resources=6 inventory=minimal-cloud.yaml ``` ### Minimal example with existing organization (CLOUD) @@ -80,7 +80,7 @@ module "apigee" { } } } -# tftest modules=1 resources=4 inventory=minimal-cloud-no-org.yaml +# tftest modules=1 resources=5 inventory=minimal-cloud-no-org.yaml ``` ### Disable VPC Peering (CLOUD) @@ -114,7 +114,7 @@ module "apigee" { } } } -# tftest modules=1 resources=5 inventory=no-peering.yaml +# tftest modules=1 resources=6 inventory=no-peering.yaml ``` @@ -142,13 +142,11 @@ module "apigee" { display_name = "APIs test" description = "APIs Test" envgroups = ["test"] - regions = ["europe-west1"] } apis-prod = { display_name = "APIs prod" description = "APIs prod" envgroups = ["prod"] - regions = ["europe-west3"] iam = { "roles/viewer" = ["group:devops@myorg.com"] } @@ -158,10 +156,12 @@ module "apigee" { europe-west1 = { runtime_ip_cidr_range = "10.0.4.0/22" troubleshooting_ip_cidr_range = "10.1.1.0.0/28" + environments = ["apis-test"] } europe-west3 = { runtime_ip_cidr_range = "10.0.8.0/22" troubleshooting_ip_cidr_range = "10.1.16.0/28" + environments = ["apis-prod"] enable_nat = true } } @@ -320,8 +320,8 @@ module "apigee" { | [addons_config](variables.tf#L17) | Addons configuration. | object({…}) | | null | | [endpoint_attachments](variables.tf#L29) | Endpoint attachments. | map(object({…})) | | {} | | [envgroups](variables.tf#L39) | Environment groups (NAME => [HOSTNAMES]). | map(list(string)) | | {} | -| [environments](variables.tf#L46) | Environments. | map(object({…})) | | {} | -| [instances](variables.tf#L65) | Instances ([REGION] => [INSTANCE]). | map(object({…})) | | {} | +| [environments](variables.tf#L46) | Environments. | map(object({…})) | | {} | +| [instances](variables.tf#L64) | Instances ([REGION] => [INSTANCE]). | map(object({…})) | | {} | | [organization](variables.tf#L89) | Apigee organization. If set to null the organization must already exist. | object({…}) | | null | ## Outputs diff --git a/modules/apigee/main.tf b/modules/apigee/main.tf index 015b4794..cd1f7197 100644 --- a/modules/apigee/main.tf +++ b/modules/apigee/main.tf @@ -112,15 +112,16 @@ resource "google_apigee_nat_address" "apigee_nat" { } resource "google_apigee_instance_attachment" "instance_attachments" { - for_each = merge(concat([for k1, v1 in var.environments : { - for v2 in coalesce(v1.regions, []) : - "${k1}-${v2}" => { - environment = k1 - region = v2 + for_each = merge(concat([for k1, v1 in var.instances : { + for v2 in coalesce(v1.environments, []) : + "${v2}-${k1}" => { + instance = k1 + environment = v2 } }])...) - instance_id = google_apigee_instance.instances[each.value.region].id - environment = google_apigee_environment.environments[each.value.environment].name + instance_id = google_apigee_instance.instances[each.value.instance].id + environment = try(google_apigee_environment.environments[each.value.environment].name, + "${local.org_id}/environments/${each.value.environment}") } resource "google_apigee_endpoint_attachment" "endpoint_attachments" { @@ -131,7 +132,7 @@ resource "google_apigee_endpoint_attachment" "endpoint_attachments" { service_attachment = each.value.service_attachment } -resource "google_apigee_addons_config" "test_organization" { +resource "google_apigee_addons_config" "addons_config" { for_each = toset(var.addons_config == null ? [] : [""]) org = local.org_name addons_config { diff --git a/modules/apigee/variables.tf b/modules/apigee/variables.tf index e256d290..78549507 100644 --- a/modules/apigee/variables.tf +++ b/modules/apigee/variables.tf @@ -56,7 +56,6 @@ variable "environments" { })) iam = optional(map(list(string))) envgroups = optional(list(string)) - regions = optional(list(string)) })) default = {} nullable = false @@ -73,6 +72,7 @@ variable "instances" { disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) enable_nat = optional(bool, false) + environments = optional(list(string)) })) validation { condition = alltrue([ diff --git a/tests/modules/apigee/all_psc_mode.tfvars b/tests/modules/apigee/all_psc_mode.tfvars index 48dc7aee..41bafabb 100644 --- a/tests/modules/apigee/all_psc_mode.tfvars +++ b/tests/modules/apigee/all_psc_mode.tfvars @@ -17,21 +17,23 @@ environments = { display_name = "APIs test" description = "APIs Test" envgroups = ["test"] - regions = ["europe-west1"] } apis-prod = { display_name = "APIs prod" description = "APIs prod" envgroups = ["prod"] - regions = ["europe-west3"] iam = { "roles/viewer" = ["group:devops@myorg.com"] } } } instances = { - europe-west1 = {} - europe-west3 = {} + europe-west1 = { + environments = ["europe-west1"] + } + europe-west3 = { + environments = ["europe-west3"] + } } endpoint_attachments = { endpoint-backend-1 = { diff --git a/tests/modules/apigee/all_vpc_mode.tfvars b/tests/modules/apigee/all_vpc_mode.tfvars index 4ebca42a..03626f76 100644 --- a/tests/modules/apigee/all_vpc_mode.tfvars +++ b/tests/modules/apigee/all_vpc_mode.tfvars @@ -18,13 +18,11 @@ environments = { display_name = "APIs test" description = "APIs Test" envgroups = ["test"] - regions = ["europe-west1"] } apis-prod = { display_name = "APIs prod" description = "APIs prod" envgroups = ["prod"] - regions = ["europe-west3"] iam = { "roles/viewer" = ["group:devops@myorg.com"] } @@ -34,10 +32,12 @@ instances = { europe-west1 = { runtime_ip_cidr_range = "10.0.4.0/22" troubleshooting_ip_cidr_range = "10.1.0.0/28" + environments = ["apis-test"] } europe-west3 = { runtime_ip_cidr_range = "10.0.6.0/22" troubleshooting_ip_cidr_range = "10.1.0.16/28" + environments = ["apis-prod"] } } endpoint_attachments = {