Merge pull request #1447 from apichick/apigee-refactoring
Refactored apigee module and adjusted the blueprints accordingly
This commit is contained in:
commit
604ca5afd8
|
@ -59,15 +59,15 @@ Do the following to verify that everything works as expected.
|
|||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [envgroups](variables.tf#L24) | Environment groups (NAME => [HOSTNAMES]). | <code>map(list(string))</code> | ✓ | |
|
||||
| [environments](variables.tf#L30) | Environments. | <code title="map(object({ display_name = optional(string) description = optional(string) node_config = optional(object({ min_node_count = optional(number) max_node_count = optional(number) })) iam = optional(map(list(string))) envgroups = list(string) }))">map(object({…}))</code> | ✓ | |
|
||||
| [instances](variables.tf#L45) | Instance. | <code title="map(object({ display_name = optional(string) description = optional(string) region = string environments = list(string) runtime_ip_cidr_range = string troubleshooting_ip_cidr_range = string disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) }))">map(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L92) | Project ID. | <code>string</code> | ✓ | |
|
||||
| [psc_config](variables.tf#L98) | PSC configuration. | <code>map(string)</code> | ✓ | |
|
||||
| [environments](variables.tf#L30) | Environments. | <code title="map(object({ display_name = optional(string) description = 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> | ✓ | |
|
||||
| [instances](variables.tf#L46) | Instance. | <code title="map(object({ display_name = optional(string) description = optional(string) runtime_ip_cidr_range = string troubleshooting_ip_cidr_range = string disk_encryption_key = optional(string) consumer_accept_list = optional(list(string)) }))">map(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L91) | Project ID. | <code>string</code> | ✓ | |
|
||||
| [psc_config](variables.tf#L97) | PSC configuration. | <code>map(string)</code> | ✓ | |
|
||||
| [datastore_name](variables.tf#L17) | Datastore. | <code>string</code> | | <code>"gcs"</code> |
|
||||
| [organization](variables.tf#L60) | Apigee organization. | <code title="object({ display_name = optional(string, "Apigee organization created by tf module") description = optional(string, "Apigee organization created by tf module") authorized_network = optional(string, "vpc") runtime_type = optional(string, "CLOUD") billing_type = optional(string) database_encryption_key = optional(string) analytics_region = optional(string, "europe-west1") })">object({…})</code> | | <code title="{ }">{…}</code> |
|
||||
| [path](variables.tf#L76) | Bucket path. | <code>string</code> | | <code>"/analytics"</code> |
|
||||
| [project_create](variables.tf#L83) | Parameters for the creation of the new project. | <code title="object({ billing_account_id = string parent = string })">object({…})</code> | | <code>null</code> |
|
||||
| [vpc_create](variables.tf#L104) | Boolean flag indicating whether the VPC should be created or not. | <code>bool</code> | | <code>true</code> |
|
||||
| [organization](variables.tf#L59) | Apigee organization. | <code title="object({ display_name = optional(string, "Apigee organization created by tf module") description = optional(string, "Apigee organization created by tf module") authorized_network = optional(string, "vpc") runtime_type = optional(string, "CLOUD") billing_type = optional(string) database_encryption_key = optional(string) analytics_region = optional(string, "europe-west1") })">object({…})</code> | | <code title="{ }">{…}</code> |
|
||||
| [path](variables.tf#L75) | Bucket path. | <code>string</code> | | <code>"/analytics"</code> |
|
||||
| [project_create](variables.tf#L82) | Parameters for the creation of the new project. | <code title="object({ billing_account_id = string parent = string })">object({…})</code> | | <code>null</code> |
|
||||
| [vpc_create](variables.tf#L103) | Boolean flag indicating whether the VPC should be created or not. | <code>bool</code> | | <code>true</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
@ -92,12 +92,11 @@ module "test" {
|
|||
environments = {
|
||||
apis-test = {
|
||||
envgroups = ["test"]
|
||||
regions = ["europe-west1"]
|
||||
}
|
||||
}
|
||||
instances = {
|
||||
instance-ew1 = {
|
||||
region = "europe-west1"
|
||||
environments = ["apis-test"]
|
||||
europe-west1 = {
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.0.0/28"
|
||||
}
|
||||
|
|
|
@ -108,11 +108,11 @@ module "glb" {
|
|||
neg_configs = {
|
||||
for k, v in var.instances : k => {
|
||||
psc = {
|
||||
region = v.region
|
||||
region = k
|
||||
target_service = module.apigee.instances[k].service_attachment
|
||||
network = module.vpc.network.self_link
|
||||
subnetwork = (
|
||||
module.vpc.subnets_psc["${v.region}/subnet-psc-${v.region}"].self_link
|
||||
module.vpc.subnets_psc["${k}/subnet-psc-${k}"].self_link
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,7 @@ environments = {
|
|||
}
|
||||
}
|
||||
instances = {
|
||||
instance-ew1 = {
|
||||
region = "europe-west1"
|
||||
europe-west1 = {
|
||||
environments = ["apis-test"]
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.1.0/28"
|
||||
|
|
|
@ -37,7 +37,8 @@ variable "environments" {
|
|||
max_node_count = optional(number)
|
||||
}))
|
||||
iam = optional(map(list(string)))
|
||||
envgroups = list(string)
|
||||
envgroups = optional(list(string))
|
||||
regions = optional(list(string))
|
||||
}))
|
||||
nullable = false
|
||||
}
|
||||
|
@ -47,8 +48,6 @@ variable "instances" {
|
|||
type = map(object({
|
||||
display_name = optional(string)
|
||||
description = optional(string)
|
||||
region = string
|
||||
environments = list(string)
|
||||
runtime_ip_cidr_range = string
|
||||
troubleshooting_ip_cidr_range = string
|
||||
disk_encryption_key = optional(string)
|
||||
|
|
|
@ -76,12 +76,11 @@ module "apigee" {
|
|||
environments = {
|
||||
(local.environment) = {
|
||||
envgroups = [local.envgroup]
|
||||
regions = [var.region]
|
||||
}
|
||||
}
|
||||
instances = {
|
||||
instance-1 = {
|
||||
region = var.region
|
||||
environments = [local.environment]
|
||||
(var.region) = {
|
||||
runtime_ip_cidr_range = var.apigee_runtime_ip_cidr_range
|
||||
troubleshooting_ip_cidr_range = var.apigee_troubleshooting_ip_cidr_range
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
billing_account_id = "12345-12345-123456"
|
||||
parent = "folders/123456789"
|
||||
apigee_project_id = "my-apigee-project"
|
||||
onprem_project_id = "my-onprem-project"
|
||||
onprem_proje◊ct_id = "my-onprem-project"
|
||||
hostname = "test.myorg.org"
|
|
@ -27,31 +27,25 @@ module "apigee" {
|
|||
apis-test = {
|
||||
display_name = "APIs test"
|
||||
description = "APIs Test"
|
||||
deployment_type = "ARCHIVE"
|
||||
api_proxy_type = "PROGRAMMABLE"
|
||||
envgroups = ["test"]
|
||||
regions = ["europe-west1"]
|
||||
}
|
||||
apis-prod = {
|
||||
display_name = "APIs prod"
|
||||
description = "APIs prod"
|
||||
deployment_type = "PROXY"
|
||||
api_proxy_type = "CONFIGURABLE"
|
||||
envgroups = ["prod"]
|
||||
regions = ["europe-west3"]
|
||||
iam = {
|
||||
"roles/viewer" = ["group:devops@myorg.com"]
|
||||
}
|
||||
}
|
||||
}
|
||||
instances = {
|
||||
instance-test-ew1 = {
|
||||
region = "europe-west1"
|
||||
environments = ["apis-test"]
|
||||
europe-west1 = {
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.1.0.0/28"
|
||||
}
|
||||
instance-prod-ew3 = {
|
||||
region = "europe-west3"
|
||||
environments = ["apis-prod"]
|
||||
europe-west3 = {
|
||||
runtime_ip_cidr_range = "10.0.8.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.16.0/28"
|
||||
}
|
||||
|
@ -105,7 +99,7 @@ module "apigee" {
|
|||
# tftest modules=1 resources=8
|
||||
```
|
||||
|
||||
### New environment group in an existing organization
|
||||
### New environment group
|
||||
|
||||
```hcl
|
||||
module "apigee" {
|
||||
|
@ -118,7 +112,7 @@ module "apigee" {
|
|||
# tftest modules=1 resources=1
|
||||
```
|
||||
|
||||
### New environment in an existing environment group
|
||||
### New environment
|
||||
|
||||
```hcl
|
||||
module "apigee" {
|
||||
|
@ -128,29 +122,26 @@ module "apigee" {
|
|||
apis-test = {
|
||||
display_name = "APIs test"
|
||||
description = "APIs Test"
|
||||
envgroups = ["test"]
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=1
|
||||
```
|
||||
|
||||
### New instance attached to an existing environment
|
||||
### New instance
|
||||
|
||||
```hcl
|
||||
module "apigee" {
|
||||
source = "./fabric/modules/apigee"
|
||||
project_id = "my-project"
|
||||
instances = {
|
||||
instance-test-ew1 = {
|
||||
region = "europe-west1"
|
||||
environments = ["apis-test"]
|
||||
europe-west1 = {
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.1.0/28"
|
||||
}
|
||||
}
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
# tftest modules=1 resources=1
|
||||
```
|
||||
|
||||
### New endpoint attachment
|
||||
|
@ -176,12 +167,12 @@ module "apigee" {
|
|||
|
||||
| name | description | type | required | default |
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [project_id](variables.tf#L78) | Project ID. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L77) | Project ID. | <code>string</code> | ✓ | |
|
||||
| [endpoint_attachments](variables.tf#L17) | Endpoint attachments. | <code title="map(object({ region = string service_attachment = string }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [envgroups](variables.tf#L26) | Environment groups (NAME => [HOSTNAMES]). | <code>map(list(string))</code> | | <code>null</code> |
|
||||
| [environments](variables.tf#L32) | 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 = list(string) }))">map(object({…}))</code> | | <code>null</code> |
|
||||
| [instances](variables.tf#L49) | Instances. | <code title="map(object({ display_name = optional(string) description = optional(string, "Terraform-managed") region = string environments = list(string) 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> |
|
||||
| [organization](variables.tf#L64) | 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") })">object({…})</code> | | <code>null</code> |
|
||||
| [environments](variables.tf#L32) | 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> |
|
||||
| [instances](variables.tf#L50) | 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> |
|
||||
| [organization](variables.tf#L63) | 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") })">object({…})</code> | | <code>null</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
|
|
@ -63,7 +63,7 @@ resource "google_apigee_environment" "environments" {
|
|||
|
||||
resource "google_apigee_envgroup_attachment" "envgroup_attachments" {
|
||||
for_each = merge(concat([for k1, v1 in local.environments : {
|
||||
for v2 in v1.envgroups : "${k1}-${v2}" => {
|
||||
for v2 in coalesce(v1.envgroups, []) : "${k1}-${v2}" => {
|
||||
environment = k1
|
||||
envgroup = v2
|
||||
}
|
||||
|
@ -88,10 +88,10 @@ resource "google_apigee_environment_iam_binding" "binding" {
|
|||
|
||||
resource "google_apigee_instance" "instances" {
|
||||
for_each = local.instances
|
||||
name = each.key
|
||||
name = "instance-${each.key}"
|
||||
display_name = each.value.display_name
|
||||
description = each.value.description
|
||||
location = each.value.region
|
||||
location = each.key
|
||||
org_id = local.org_id
|
||||
ip_range = "${each.value.runtime_ip_cidr_range},${each.value.troubleshooting_ip_cidr_range}"
|
||||
disk_encryption_key_name = each.value.disk_encryption_key
|
||||
|
@ -99,14 +99,14 @@ resource "google_apigee_instance" "instances" {
|
|||
}
|
||||
|
||||
resource "google_apigee_instance_attachment" "instance_attachments" {
|
||||
for_each = merge(concat([for k1, v1 in local.instances : {
|
||||
for v2 in v1.environments :
|
||||
for_each = merge(concat([for k1, v1 in local.environments : {
|
||||
for v2 in coalesce(v1.regions, []) :
|
||||
"${k1}-${v2}" => {
|
||||
instance = k1
|
||||
environment = v2
|
||||
environment = k1
|
||||
region = v2
|
||||
}
|
||||
}])...)
|
||||
instance_id = google_apigee_instance.instances[each.value.instance].id
|
||||
instance_id = google_apigee_instance.instances[each.value.region].id
|
||||
environment = try(google_apigee_environment.environments[each.value.environment].name,
|
||||
"${local.org_id}/environments/${each.value.environment}")
|
||||
}
|
||||
|
|
|
@ -41,18 +41,17 @@ variable "environments" {
|
|||
max_node_count = optional(number)
|
||||
}))
|
||||
iam = optional(map(list(string)))
|
||||
envgroups = list(string)
|
||||
envgroups = optional(list(string))
|
||||
regions = optional(list(string))
|
||||
}))
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "instances" {
|
||||
description = "Instances."
|
||||
description = "Instances ([REGION] => [INSTANCE])."
|
||||
type = map(object({
|
||||
display_name = optional(string)
|
||||
description = optional(string, "Terraform-managed")
|
||||
region = string
|
||||
environments = list(string)
|
||||
runtime_ip_cidr_range = string
|
||||
troubleshooting_ip_cidr_range = string
|
||||
disk_encryption_key = optional(string)
|
||||
|
|
|
@ -17,26 +17,24 @@ 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 = {
|
||||
instance-test-ew1 = {
|
||||
region = "europe-west1"
|
||||
environments = ["apis-test"]
|
||||
europe-west1 = {
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.0.0/28"
|
||||
}
|
||||
instance-prod-ew3 = {
|
||||
region = "europe-west3"
|
||||
environments = ["apis-prod"]
|
||||
europe-west3 = {
|
||||
runtime_ip_cidr_range = "10.0.6.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.0.16/28"
|
||||
}
|
||||
|
|
|
@ -47,20 +47,20 @@ values:
|
|||
members:
|
||||
- group:devops@myorg.com
|
||||
role: roles/viewer
|
||||
google_apigee_instance.instances["instance-prod-ew3"]:
|
||||
google_apigee_instance.instances["europe-west3"]:
|
||||
description: Terraform-managed
|
||||
disk_encryption_key_name: null
|
||||
display_name: null
|
||||
ip_range: 10.0.6.0/22,10.1.0.16/28
|
||||
location: europe-west3
|
||||
name: instance-prod-ew3
|
||||
google_apigee_instance.instances["instance-test-ew1"]:
|
||||
name: instance-europe-west3
|
||||
google_apigee_instance.instances["europe-west1"]:
|
||||
description: Terraform-managed
|
||||
disk_encryption_key_name: null
|
||||
display_name: null
|
||||
ip_range: 10.0.4.0/22,10.1.0.0/28
|
||||
location: europe-west1
|
||||
name: instance-test-ew1
|
||||
name: instance-europe-west1
|
||||
google_apigee_organization.organization[0]:
|
||||
analytics_region: europe-west1
|
||||
authorized_network: my-vpc
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
project_id = "my-project"
|
||||
instances = {
|
||||
instance-test-ew1 = {
|
||||
region = "europe-west1"
|
||||
environments = ["apis-test"]
|
||||
europe-west1 = {
|
||||
runtime_ip_cidr_range = "10.0.4.0/22"
|
||||
troubleshooting_ip_cidr_range = "10.1.1.0.0/28"
|
||||
}
|
||||
|
|
|
@ -13,14 +13,11 @@
|
|||
# limitations under the License.
|
||||
|
||||
values:
|
||||
google_apigee_instance.instances["instance-test-ew1"]:
|
||||
google_apigee_instance.instances["europe-west1"]:
|
||||
ip_range: 10.0.4.0/22,10.1.1.0.0/28
|
||||
location: europe-west1
|
||||
name: instance-test-ew1
|
||||
name: "instance-europe-west1"
|
||||
org_id: organizations/my-project
|
||||
google_apigee_instance_attachment.instance_attachments["instance-test-ew1-apis-test"]:
|
||||
environment: organizations/my-project/environments/apis-test
|
||||
|
||||
counts:
|
||||
google_apigee_instance: 1
|
||||
google_apigee_instance_attachment: 1
|
||||
|
|
Loading…
Reference in New Issue