Fixed, added back environments to each instance, that way we can also create instances for already existing environments

This commit is contained in:
Miren Esnaola 2023-09-13 12:34:00 +02:00
parent 6818b23b53
commit fdb133f1de
8 changed files with 30 additions and 29 deletions

View File

@ -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.
<!-- BEGIN TFDOC -->
## Variables
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [envgroups](variables.tf#L24) | Environment groups (NAME => [HOSTNAMES]). | <code>map&#40;list&#40;string&#41;&#41;</code> | ✓ | |
| [environments](variables.tf#L30) | Environments. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string&#41;&#10; node_config &#61; optional&#40;object&#40;&#123;&#10; min_node_count &#61; optional&#40;number&#41;&#10; max_node_count &#61; optional&#40;number&#41;&#10; &#125;&#41;&#41;&#10; iam &#61; optional&#40;map&#40;list&#40;string&#41;&#41;&#41;&#10; envgroups &#61; optional&#40;list&#40;string&#41;&#41;&#10; regions &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [instances](variables.tf#L46) | Instance. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string&#41;&#10; runtime_ip_cidr_range &#61; string&#10; troubleshooting_ip_cidr_range &#61; string&#10; disk_encryption_key &#61; optional&#40;string&#41;&#10; consumer_accept_list &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [environments](variables.tf#L30) | Environments. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string&#41;&#10; node_config &#61; optional&#40;object&#40;&#123;&#10; min_node_count &#61; optional&#40;number&#41;&#10; max_node_count &#61; optional&#40;number&#41;&#10; &#125;&#41;&#41;&#10; iam &#61; optional&#40;map&#40;list&#40;string&#41;&#41;&#41;&#10; envgroups &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [instances](variables.tf#L45) | Instance. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string&#41;&#10; runtime_ip_cidr_range &#61; string&#10; troubleshooting_ip_cidr_range &#61; string&#10; disk_encryption_key &#61; optional&#40;string&#41;&#10; consumer_accept_list &#61; optional&#40;list&#40;string&#41;&#41;&#10; environments &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | ✓ | |
| [project_id](variables.tf#L91) | Project ID. | <code>string</code> | ✓ | |
| [psc_config](variables.tf#L97) | PSC configuration. | <code>map&#40;string&#41;</code> | ✓ | |
| [datastore_name](variables.tf#L17) | Datastore. | <code>string</code> | | <code>&#34;gcs&#34;</code> |
@ -74,7 +73,6 @@ Do the following to verify that everything works as expected.
| name | description | sensitive |
|---|---|:---:|
| [ip_address](outputs.tf#L17) | IP address. | |
<!-- END TFDOC -->
## 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 = {

View File

@ -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
}

View File

@ -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
}

View File

@ -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. | <code title="object&#40;&#123;&#10; advanced_api_ops &#61; optional&#40;bool, false&#41;&#10; api_security &#61; optional&#40;bool, false&#41;&#10; connectors_platform &#61; optional&#40;bool, false&#41;&#10; integration &#61; optional&#40;bool, false&#41;&#10; monetization &#61; optional&#40;bool, false&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
| [endpoint_attachments](variables.tf#L29) | Endpoint attachments. | <code title="map&#40;object&#40;&#123;&#10; region &#61; string&#10; service_attachment &#61; string&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [envgroups](variables.tf#L39) | Environment groups (NAME => [HOSTNAMES]). | <code>map&#40;list&#40;string&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [environments](variables.tf#L46) | Environments. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform-managed&#34;&#41;&#10; deployment_type &#61; optional&#40;string&#41;&#10; api_proxy_type &#61; optional&#40;string&#41;&#10; node_config &#61; optional&#40;object&#40;&#123;&#10; min_node_count &#61; optional&#40;number&#41;&#10; max_node_count &#61; optional&#40;number&#41;&#10; &#125;&#41;&#41;&#10; iam &#61; optional&#40;map&#40;list&#40;string&#41;&#41;&#41;&#10; envgroups &#61; optional&#40;list&#40;string&#41;&#41;&#10; regions &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [instances](variables.tf#L65) | Instances ([REGION] => [INSTANCE]). | <code title="map&#40;object&#40;&#123;&#10; name &#61; optional&#40;string&#41;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform-managed&#34;&#41;&#10; runtime_ip_cidr_range &#61; optional&#40;string&#41;&#10; troubleshooting_ip_cidr_range &#61; optional&#40;string&#41;&#10; disk_encryption_key &#61; optional&#40;string&#41;&#10; consumer_accept_list &#61; optional&#40;list&#40;string&#41;&#41;&#10; enable_nat &#61; optional&#40;bool, false&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [environments](variables.tf#L46) | Environments. | <code title="map&#40;object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform-managed&#34;&#41;&#10; deployment_type &#61; optional&#40;string&#41;&#10; api_proxy_type &#61; optional&#40;string&#41;&#10; node_config &#61; optional&#40;object&#40;&#123;&#10; min_node_count &#61; optional&#40;number&#41;&#10; max_node_count &#61; optional&#40;number&#41;&#10; &#125;&#41;&#41;&#10; iam &#61; optional&#40;map&#40;list&#40;string&#41;&#41;&#41;&#10; envgroups &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [instances](variables.tf#L64) | Instances ([REGION] => [INSTANCE]). | <code title="map&#40;object&#40;&#123;&#10; name &#61; optional&#40;string&#41;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform-managed&#34;&#41;&#10; runtime_ip_cidr_range &#61; optional&#40;string&#41;&#10; troubleshooting_ip_cidr_range &#61; optional&#40;string&#41;&#10; disk_encryption_key &#61; optional&#40;string&#41;&#10; consumer_accept_list &#61; optional&#40;list&#40;string&#41;&#41;&#10; enable_nat &#61; optional&#40;bool, false&#41;&#10; environments &#61; optional&#40;list&#40;string&#41;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [organization](variables.tf#L89) | Apigee organization. If set to null the organization must already exist. | <code title="object&#40;&#123;&#10; display_name &#61; optional&#40;string&#41;&#10; description &#61; optional&#40;string, &#34;Terraform-managed&#34;&#41;&#10; authorized_network &#61; optional&#40;string&#41;&#10; runtime_type &#61; optional&#40;string, &#34;CLOUD&#34;&#41;&#10; billing_type &#61; optional&#40;string&#41;&#10; database_encryption_key &#61; optional&#40;string&#41;&#10; analytics_region &#61; optional&#40;string, &#34;europe-west1&#34;&#41;&#10; retention &#61; optional&#40;string&#41;&#10; disable_vpc_peering &#61; optional&#40;bool, false&#41;&#10;&#125;&#41;">object&#40;&#123;&#8230;&#125;&#41;</code> | | <code>null</code> |
## Outputs

View File

@ -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 {

View File

@ -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([

View File

@ -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 = {

View File

@ -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 = {