Merge pull request #1619 from billabongrob/billabongrob/add-nat
Adding support for NAT in Apigee
This commit is contained in:
commit
5b43ed270d
|
@ -105,5 +105,5 @@ module "test" {
|
||||||
europe-west1 = "10.0.0.0/28"
|
europe-west1 = "10.0.0.0/28"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=10 resources=65
|
# tftest modules=10 resources=64
|
||||||
```
|
```
|
||||||
|
|
|
@ -80,5 +80,5 @@ module "test" {
|
||||||
project_id = "my-project"
|
project_id = "my-project"
|
||||||
hostname = "test.myorg.org"
|
hostname = "test.myorg.org"
|
||||||
}
|
}
|
||||||
# tftest modules=18 resources=62
|
# tftest modules=18 resources=61
|
||||||
```
|
```
|
||||||
|
|
|
@ -79,5 +79,5 @@ module "test" {
|
||||||
onprem_project_id = "my-onprem-project"
|
onprem_project_id = "my-onprem-project"
|
||||||
hostname = "test.myorg.org"
|
hostname = "test.myorg.org"
|
||||||
}
|
}
|
||||||
# tftest modules=14 resources=78
|
# tftest modules=14 resources=77
|
||||||
```
|
```
|
||||||
|
|
|
@ -48,6 +48,7 @@ module "apigee" {
|
||||||
europe-west3 = {
|
europe-west3 = {
|
||||||
runtime_ip_cidr_range = "10.0.8.0/22"
|
runtime_ip_cidr_range = "10.0.8.0/22"
|
||||||
troubleshooting_ip_cidr_range = "10.1.16.0/28"
|
troubleshooting_ip_cidr_range = "10.1.16.0/28"
|
||||||
|
enable_nat = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
endpoint_attachments = {
|
endpoint_attachments = {
|
||||||
|
@ -96,7 +97,7 @@ module "apigee" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=9
|
# tftest modules=1 resources=8
|
||||||
```
|
```
|
||||||
|
|
||||||
### New environment group
|
### New environment group
|
||||||
|
@ -109,7 +110,7 @@ module "apigee" {
|
||||||
test = ["test.example.com"]
|
test = ["test.example.com"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=1
|
||||||
```
|
```
|
||||||
|
|
||||||
### New environment
|
### New environment
|
||||||
|
@ -125,7 +126,7 @@ module "apigee" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=1
|
||||||
```
|
```
|
||||||
|
|
||||||
### New instance
|
### New instance
|
||||||
|
@ -141,7 +142,7 @@ module "apigee" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=1
|
||||||
```
|
```
|
||||||
|
|
||||||
### New endpoint attachment
|
### New endpoint attachment
|
||||||
|
@ -159,7 +160,7 @@ module "apigee" {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# tftest modules=1 resources=2
|
# tftest modules=1 resources=1
|
||||||
```
|
```
|
||||||
|
|
||||||
### Apigee add-ons
|
### Apigee add-ons
|
||||||
|
@ -179,13 +180,13 @@ module "apigee" {
|
||||||
|
|
||||||
| name | description | type | required | default |
|
| name | description | type | required | default |
|
||||||
|---|---|:---:|:---:|:---:|
|
|---|---|:---:|:---:|:---:|
|
||||||
| [project_id](variables.tf#L90) | Project ID. | <code>string</code> | ✓ | |
|
| [project_id](variables.tf#L95) | Project ID. | <code>string</code> | ✓ | |
|
||||||
| [addons_config](variables.tf#L17) | Addons configuration. | <code title="object({ advanced_api_ops = optional(bool, false) api_security = optional(bool, false) connectors_platform = optional(bool, false) integration = optional(bool, false) monetization = optional(bool, false) })">object({…})</code> | | <code>null</code> |
|
| [addons_config](variables.tf#L17) | Addons configuration. | <code title="object({ advanced_api_ops = optional(bool, false) api_security = optional(bool, false) connectors_platform = optional(bool, false) integration = optional(bool, false) monetization = optional(bool, false) })">object({…})</code> | | <code>null</code> |
|
||||||
| [endpoint_attachments](variables.tf#L29) | Endpoint attachments. | <code title="map(object({ region = string service_attachment = string }))">map(object({…}))</code> | | <code>null</code> |
|
| [endpoint_attachments](variables.tf#L29) | Endpoint attachments. | <code title="map(object({ region = string service_attachment = string }))">map(object({…}))</code> | | <code>{}</code> |
|
||||||
| [envgroups](variables.tf#L38) | Environment groups (NAME => [HOSTNAMES]). | <code>map(list(string))</code> | | <code>null</code> |
|
| [envgroups](variables.tf#L39) | Environment groups (NAME => [HOSTNAMES]). | <code>map(list(string))</code> | | <code>{}</code> |
|
||||||
| [environments](variables.tf#L44) | Environments. | <code title="map(object({ display_name = optional(string) description = optional(string, "Terraform-managed") deployment_type = optional(string) api_proxy_type = optional(string) node_config = optional(object({ min_node_count = optional(number) max_node_count = optional(number) })) iam = optional(map(list(string))) envgroups = optional(list(string)) regions = optional(list(string)) }))">map(object({…}))</code> | | <code>null</code> |
|
| [environments](variables.tf#L46) | Environments. | <code title="map(object({ display_name = optional(string) description = optional(string, "Terraform-managed") deployment_type = optional(string) api_proxy_type = optional(string) node_config = optional(object({ min_node_count = optional(number) max_node_count = optional(number) })) iam = optional(map(list(string))) envgroups = optional(list(string)) regions = optional(list(string)) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||||
| [instances](variables.tf#L62) | Instances ([REGION] => [INSTANCE]). | <code title="map(object({ display_name = optional(string) description = optional(string, "Terraform-managed") runtime_ip_cidr_range = string troubleshooting_ip_cidr_range = string disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) }))">map(object({…}))</code> | | <code>null</code> |
|
| [instances](variables.tf#L65) | Instances ([REGION] => [INSTANCE]). | <code title="map(object({ display_name = optional(string) description = optional(string, "Terraform-managed") runtime_ip_cidr_range = string troubleshooting_ip_cidr_range = string disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) enable_nat = optional(bool, false) }))">map(object({…}))</code> | | <code>{}</code> |
|
||||||
| [organization](variables.tf#L75) | Apigee organization. If set to null the organization must already exist. | <code title="object({ display_name = optional(string) description = optional(string, "Terraform-managed") authorized_network = optional(string) runtime_type = optional(string, "CLOUD") billing_type = optional(string) database_encryption_key = optional(string) analytics_region = optional(string, "europe-west1") retention = optional(string) })">object({…})</code> | | <code>null</code> |
|
| [organization](variables.tf#L80) | Apigee organization. If set to null the organization must already exist. | <code title="object({ display_name = optional(string) description = optional(string, "Terraform-managed") authorized_network = optional(string) runtime_type = optional(string, "CLOUD") billing_type = optional(string) database_encryption_key = optional(string) analytics_region = optional(string, "europe-west1") retention = optional(string) })">object({…})</code> | | <code>null</code> |
|
||||||
|
|
||||||
## Outputs
|
## Outputs
|
||||||
|
|
||||||
|
@ -195,8 +196,9 @@ module "apigee" {
|
||||||
| [envgroups](outputs.tf#L22) | Environment groups. | |
|
| [envgroups](outputs.tf#L22) | Environment groups. | |
|
||||||
| [environments](outputs.tf#L27) | Environment. | |
|
| [environments](outputs.tf#L27) | Environment. | |
|
||||||
| [instances](outputs.tf#L32) | Instances. | |
|
| [instances](outputs.tf#L32) | Instances. | |
|
||||||
| [org_id](outputs.tf#L37) | Organization ID. | |
|
| [nat_ips](outputs.tf#L37) | NAT IP addresses used in instances. | |
|
||||||
| [org_name](outputs.tf#L42) | Organization name. | |
|
| [org_id](outputs.tf#L45) | Organization ID. | |
|
||||||
| [organization](outputs.tf#L47) | Organization. | |
|
| [org_name](outputs.tf#L50) | Organization name. | |
|
||||||
| [service_attachments](outputs.tf#L52) | Service attachments. | |
|
| [organization](outputs.tf#L55) | Organization. | |
|
||||||
|
| [service_attachments](outputs.tf#L60) | Service attachments. | |
|
||||||
<!-- END TFDOC -->
|
<!-- END TFDOC -->
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2022 Google LLC
|
* Copyright 2023 Google LLC
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -15,12 +15,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
locals {
|
locals {
|
||||||
org_id = try(google_apigee_organization.organization[0].id, "organizations/${var.project_id}")
|
org_id = try(google_apigee_organization.organization[0].id, "organizations/${var.project_id}")
|
||||||
org_name = try(google_apigee_organization.organization[0].name, var.project_id)
|
org_name = try(google_apigee_organization.organization[0].name, var.project_id)
|
||||||
envgroups = coalesce(var.envgroups, {})
|
|
||||||
environments = coalesce(var.environments, {})
|
|
||||||
instances = coalesce(var.instances, {})
|
|
||||||
endpoint_attachments = coalesce(var.endpoint_attachments, {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_organization" "organization" {
|
resource "google_apigee_organization" "organization" {
|
||||||
|
@ -35,14 +31,14 @@ resource "google_apigee_organization" "organization" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_envgroup" "envgroups" {
|
resource "google_apigee_envgroup" "envgroups" {
|
||||||
for_each = local.envgroups
|
for_each = var.envgroups
|
||||||
name = each.key
|
name = each.key
|
||||||
hostnames = each.value
|
hostnames = each.value
|
||||||
org_id = local.org_id
|
org_id = local.org_id
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_environment" "environments" {
|
resource "google_apigee_environment" "environments" {
|
||||||
for_each = local.environments
|
for_each = var.environments
|
||||||
name = each.key
|
name = each.key
|
||||||
display_name = each.value.display_name
|
display_name = each.value.display_name
|
||||||
description = each.value.description
|
description = each.value.description
|
||||||
|
@ -64,7 +60,7 @@ resource "google_apigee_environment" "environments" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_envgroup_attachment" "envgroup_attachments" {
|
resource "google_apigee_envgroup_attachment" "envgroup_attachments" {
|
||||||
for_each = merge(concat([for k1, v1 in local.environments : {
|
for_each = merge(concat([for k1, v1 in var.environments : {
|
||||||
for v2 in coalesce(v1.envgroups, []) : "${k1}-${v2}" => {
|
for v2 in coalesce(v1.envgroups, []) : "${k1}-${v2}" => {
|
||||||
environment = k1
|
environment = k1
|
||||||
envgroup = v2
|
envgroup = v2
|
||||||
|
@ -75,7 +71,7 @@ resource "google_apigee_envgroup_attachment" "envgroup_attachments" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_environment_iam_binding" "binding" {
|
resource "google_apigee_environment_iam_binding" "binding" {
|
||||||
for_each = merge(concat([for k1, v1 in local.environments : {
|
for_each = merge(concat([for k1, v1 in var.environments : {
|
||||||
for k2, v2 in coalesce(v1.iam, {}) : "${k1}-${k2}" => {
|
for k2, v2 in coalesce(v1.iam, {}) : "${k1}-${k2}" => {
|
||||||
environment = "${k1}"
|
environment = "${k1}"
|
||||||
role = k2
|
role = k2
|
||||||
|
@ -89,7 +85,7 @@ resource "google_apigee_environment_iam_binding" "binding" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_instance" "instances" {
|
resource "google_apigee_instance" "instances" {
|
||||||
for_each = local.instances
|
for_each = var.instances
|
||||||
name = "instance-${each.key}"
|
name = "instance-${each.key}"
|
||||||
display_name = each.value.display_name
|
display_name = each.value.display_name
|
||||||
description = each.value.description
|
description = each.value.description
|
||||||
|
@ -100,8 +96,18 @@ resource "google_apigee_instance" "instances" {
|
||||||
consumer_accept_list = each.value.consumer_accept_list
|
consumer_accept_list = each.value.consumer_accept_list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resource "google_apigee_nat_address" "apigee_nat" {
|
||||||
|
for_each = {
|
||||||
|
for k, v in var.instances :
|
||||||
|
k => google_apigee_instance.instances[k].id
|
||||||
|
if v.enable_nat
|
||||||
|
}
|
||||||
|
name = each.key
|
||||||
|
instance_id = each.value
|
||||||
|
}
|
||||||
|
|
||||||
resource "google_apigee_instance_attachment" "instance_attachments" {
|
resource "google_apigee_instance_attachment" "instance_attachments" {
|
||||||
for_each = merge(concat([for k1, v1 in local.environments : {
|
for_each = merge(concat([for k1, v1 in var.environments : {
|
||||||
for v2 in coalesce(v1.regions, []) :
|
for v2 in coalesce(v1.regions, []) :
|
||||||
"${k1}-${v2}" => {
|
"${k1}-${v2}" => {
|
||||||
environment = k1
|
environment = k1
|
||||||
|
@ -114,7 +120,7 @@ resource "google_apigee_instance_attachment" "instance_attachments" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_endpoint_attachment" "endpoint_attachments" {
|
resource "google_apigee_endpoint_attachment" "endpoint_attachments" {
|
||||||
for_each = local.endpoint_attachments
|
for_each = var.endpoint_attachments
|
||||||
org_id = local.org_id
|
org_id = local.org_id
|
||||||
endpoint_attachment_id = each.key
|
endpoint_attachment_id = each.key
|
||||||
location = each.value.region
|
location = each.value.region
|
||||||
|
@ -122,39 +128,37 @@ resource "google_apigee_endpoint_attachment" "endpoint_attachments" {
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "google_apigee_addons_config" "test_organization" {
|
resource "google_apigee_addons_config" "test_organization" {
|
||||||
org = local.org_name
|
for_each = toset(var.addons_config == null ? [] : [""])
|
||||||
dynamic "addons_config" {
|
org = local.org_name
|
||||||
for_each = var.addons_config == null ? [] : [""]
|
addons_config {
|
||||||
content {
|
dynamic "advanced_api_ops_config" {
|
||||||
dynamic "advanced_api_ops_config" {
|
for_each = var.addons_config.advanced_api_ops ? [] : [""]
|
||||||
for_each = var.addons_config.advanced_api_ops ? [] : [""]
|
content {
|
||||||
content {
|
enabled = true
|
||||||
enabled = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
dynamic "api_security_config" {
|
}
|
||||||
for_each = var.addons_config.api_security ? [] : [""]
|
dynamic "api_security_config" {
|
||||||
content {
|
for_each = var.addons_config.api_security ? [] : [""]
|
||||||
enabled = true
|
content {
|
||||||
}
|
enabled = true
|
||||||
}
|
}
|
||||||
dynamic "connectors_platform_config" {
|
}
|
||||||
for_each = var.addons_config.connectors_platform ? [] : [""]
|
dynamic "connectors_platform_config" {
|
||||||
content {
|
for_each = var.addons_config.connectors_platform ? [] : [""]
|
||||||
enabled = true
|
content {
|
||||||
}
|
enabled = true
|
||||||
}
|
}
|
||||||
dynamic "integration_config" {
|
}
|
||||||
for_each = var.addons_config.integration ? [] : [""]
|
dynamic "integration_config" {
|
||||||
content {
|
for_each = var.addons_config.integration ? [] : [""]
|
||||||
enabled = true
|
content {
|
||||||
}
|
enabled = true
|
||||||
}
|
}
|
||||||
dynamic "monetization_config" {
|
}
|
||||||
for_each = var.addons_config.monetization ? [] : [""]
|
dynamic "monetization_config" {
|
||||||
content {
|
for_each = var.addons_config.monetization ? [] : [""]
|
||||||
enabled = true
|
content {
|
||||||
}
|
enabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2022 Google LLC
|
* Copyright 2023 Google LLC
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -34,6 +34,14 @@ output "instances" {
|
||||||
value = try(google_apigee_instance.instances, null)
|
value = try(google_apigee_instance.instances, null)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
output "nat_ips" {
|
||||||
|
description = "NAT IP addresses used in instances."
|
||||||
|
value = {
|
||||||
|
for k, v in google_apigee_nat_address.apigee_nat :
|
||||||
|
k => v.ip_address
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
output "org_id" {
|
output "org_id" {
|
||||||
description = "Organization ID."
|
description = "Organization ID."
|
||||||
value = local.org_id
|
value = local.org_id
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2022 Google LLC
|
* Copyright 2023 Google LLC
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -32,13 +32,15 @@ variable "endpoint_attachments" {
|
||||||
region = string
|
region = string
|
||||||
service_attachment = string
|
service_attachment = string
|
||||||
}))
|
}))
|
||||||
default = null
|
default = {}
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "envgroups" {
|
variable "envgroups" {
|
||||||
description = "Environment groups (NAME => [HOSTNAMES])."
|
description = "Environment groups (NAME => [HOSTNAMES])."
|
||||||
type = map(list(string))
|
type = map(list(string))
|
||||||
default = null
|
default = {}
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "environments" {
|
variable "environments" {
|
||||||
|
@ -56,7 +58,8 @@ variable "environments" {
|
||||||
envgroups = optional(list(string))
|
envgroups = optional(list(string))
|
||||||
regions = optional(list(string))
|
regions = optional(list(string))
|
||||||
}))
|
}))
|
||||||
default = null
|
default = {}
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "instances" {
|
variable "instances" {
|
||||||
|
@ -68,8 +71,10 @@ variable "instances" {
|
||||||
troubleshooting_ip_cidr_range = string
|
troubleshooting_ip_cidr_range = string
|
||||||
disk_encryption_key = optional(string)
|
disk_encryption_key = optional(string)
|
||||||
consumer_accept_list = optional(list(string))
|
consumer_accept_list = optional(list(string))
|
||||||
|
enable_nat = optional(bool, false)
|
||||||
}))
|
}))
|
||||||
default = null
|
default = {}
|
||||||
|
nullable = false
|
||||||
}
|
}
|
||||||
|
|
||||||
variable "organization" {
|
variable "organization" {
|
||||||
|
|
Loading…
Reference in New Issue