diff --git a/modules/apigee-organization/README.md b/modules/apigee-organization/README.md
index eceb4d1338..150553a144 100644
--- a/modules/apigee-organization/README.md
+++ b/modules/apigee-organization/README.md
@@ -13,10 +13,16 @@ module "apigee-organization" {
analytics_region = "us-central1"
runtime_type = "CLOUD"
authorized_network = "my-vpc"
- apigee_environments = [
- "eval1",
- "eval2"
- ]
+ apigee_environments = {
+ eval1 = {
+ api_proxy_type = "PROGRAMMABLE"
+ deployment_type = "PROXY"
+ }
+ eval2 = {
+ api_proxy_type = "CONFIGURABLE"
+ deployment_type = "ARCHIVE"
+ }
+ }
apigee_envgroups = {
eval = {
environments = [
@@ -42,12 +48,18 @@ module "apigee-organization" {
runtime_type = "CLOUD"
authorized_network = "my-vpc"
database_encryption_key = "my-data-key"
- apigee_environments = [
- "dev1",
- "dev2",
- "test1",
- "test2"
- ]
+ apigee_environments = {
+ dev1 = {
+ api_proxy_type = "PROGRAMMABLE"
+ deployment_type = "PROXY"
+ }
+ dev2 = {
+ api_proxy_type = "CONFIGURABLE"
+ deployment_type = "ARCHIVE"
+ }
+ test1 = {}
+ test2 = {}
+ }
apigee_envgroups = {
dev = {
environments = [
@@ -80,10 +92,13 @@ module "apigee-organization" {
project_id = "my-project"
analytics_region = "us-central1"
runtime_type = "HYBRID"
- apigee_environments = [
- "eval1",
- "eval2"
- ]
+ apigee_environments = {
+ eval1 = {
+ api_proxy_type = "PROGRAMMABLE"
+ deployment_type = "PROXY"
+ }
+ eval2 = {}
+ }
apigee_envgroups = {
eval = {
environments = [
@@ -105,15 +120,15 @@ module "apigee-organization" {
| name | description | type | required | default |
|---|---|:---:|:---:|:---:|
| [analytics_region](variables.tf#L17) | Analytics Region for the Apigee Organization (immutable). See https://cloud.google.com/apigee/docs/api-platform/get-started/install-cli. | string
| ✓ | |
-| [project_id](variables.tf#L61) | Project ID to host this Apigee organization (will also become the Apigee Org name). | string
| ✓ | |
-| [runtime_type](variables.tf#L66) | Apigee runtime type. Must be `CLOUD` or `HYBRID`. | string
| ✓ | |
+| [project_id](variables.tf#L72) | Project ID to host this Apigee organization (will also become the Apigee Org name). | string
| ✓ | |
+| [runtime_type](variables.tf#L77) | Apigee runtime type. Must be `CLOUD` or `HYBRID`. | string
| ✓ | |
| [apigee_envgroups](variables.tf#L22) | Apigee Environment Groups. | map(object({…}))
| | {}
|
-| [apigee_environments](variables.tf#L31) | Apigee Environment Names. | list(string)
| | []
|
-| [authorized_network](variables.tf#L37) | VPC network self link (requires service network peering enabled (Used in Apigee X only). | string
| | null
|
-| [billing_type](variables.tf#L75) | Billing type of the Apigee organization. | string
| | null
|
-| [database_encryption_key](variables.tf#L43) | Cloud KMS key self link (e.g. `projects/foo/locations/us/keyRings/bar/cryptoKeys/baz`) used for encrypting the data that is stored and replicated across runtime instances (immutable, used in Apigee X only). | string
| | null
|
-| [description](variables.tf#L49) | Description of the Apigee Organization. | string
| | "Apigee Organization created by tf module"
|
-| [display_name](variables.tf#L55) | Display Name of the Apigee Organization. | string
| | null
|
+| [apigee_environments](variables.tf#L31) | Apigee Environment Names. | map(object({…}))
| | {}
|
+| [authorized_network](variables.tf#L48) | VPC network self link (requires service network peering enabled (Used in Apigee X only). | string
| | null
|
+| [billing_type](variables.tf#L86) | Billing type of the Apigee organization. | string
| | null
|
+| [database_encryption_key](variables.tf#L54) | Cloud KMS key self link (e.g. `projects/foo/locations/us/keyRings/bar/cryptoKeys/baz`) used for encrypting the data that is stored and replicated across runtime instances (immutable, used in Apigee X only). | string
| | null
|
+| [description](variables.tf#L60) | Description of the Apigee Organization. | string
| | "Apigee Organization created by tf module"
|
+| [display_name](variables.tf#L66) | Display Name of the Apigee Organization. | string
| | null
|
## Outputs
diff --git a/modules/apigee-organization/main.tf b/modules/apigee-organization/main.tf
index 148711a99d..a498135bb8 100644
--- a/modules/apigee-organization/main.tf
+++ b/modules/apigee-organization/main.tf
@@ -15,6 +15,14 @@
*/
locals {
+ env_pairs = flatten([
+ for env_name, env in var.apigee_environments : {
+ api_proxy_type = env.api_proxy_type
+ deployment_type = env.deployment_type
+ env_name = env_name
+ }
+ ])
+
env_envgroup_pairs = flatten([
for eg_name, eg in var.apigee_envgroups : [
for e in eg.environments : {
@@ -37,9 +45,11 @@ resource "google_apigee_organization" "apigee_org" {
}
resource "google_apigee_environment" "apigee_env" {
- for_each = toset(var.apigee_environments)
- org_id = google_apigee_organization.apigee_org.id
- name = each.key
+ for_each = { for env in local.env_pairs : env.env_name => env }
+ api_proxy_type = each.value.api_proxy_type
+ deployment_type = each.value.deployment_type
+ name = each.key
+ org_id = google_apigee_organization.apigee_org.id
}
resource "google_apigee_envgroup" "apigee_envgroup" {
diff --git a/modules/apigee-organization/variables.tf b/modules/apigee-organization/variables.tf
index b2b3eac9f4..b3d13e151c 100644
--- a/modules/apigee-organization/variables.tf
+++ b/modules/apigee-organization/variables.tf
@@ -30,8 +30,19 @@ variable "apigee_envgroups" {
variable "apigee_environments" {
description = "Apigee Environment Names."
- type = list(string)
- default = []
+ type = map(object({
+ api_proxy_type = optional(string, "API_PROXY_TYPE_UNSPECIFIED")
+ deployment_type = optional(string, "DEPLOYMENT_TYPE_UNSPECIFIED")
+ }))
+ default = {}
+ validation {
+ condition = alltrue([for k, v in var.apigee_environments : contains(["API_PROXY_TYPE_UNSPECIFIED", "PROGRAMMABLE", "CONFIGURABLE"], v.api_proxy_type)])
+ error_message = "Allowed values for api_proxy_type \"API_PROXY_TYPE_UNSPECIFIED\", \"PROGRAMMABLE\" or \"CONFIGURABLE\"."
+ }
+ validation {
+ condition = alltrue([for k, v in var.apigee_environments : contains(["DEPLOYMENT_TYPE_UNSPECIFIED", "PROXY", "ARCHIVE"], v.deployment_type)])
+ error_message = "Allowed values for deployment_type \"DEPLOYMENT_TYPE_UNSPECIFIED\", \"PROXY\" or \"ARCHIVE\"."
+ }
}
variable "authorized_network" {
diff --git a/tests/modules/apigee_organization/fixture/main.tf b/tests/modules/apigee_organization/fixture/main.tf
index 9dfb49bccf..37fa536bd2 100644
--- a/tests/modules/apigee_organization/fixture/main.tf
+++ b/tests/modules/apigee_organization/fixture/main.tf
@@ -21,10 +21,17 @@ module "test" {
runtime_type = "CLOUD"
billing_type = "EVALUATION"
authorized_network = var.network
- apigee_environments = [
- "eval1",
- "eval2"
- ]
+ apigee_environments = {
+ eval1 = {
+ api_proxy_type = "PROGRAMMABLE"
+ deployment_type = "PROXY"
+ }
+ eval2 = {
+ api_proxy_type = "CONFIGURABLE"
+ deployment_type = "ARCHIVE"
+ }
+ eval3 = {}
+ }
apigee_envgroups = {
eval = {
environments = [
diff --git a/tests/modules/apigee_organization/test_plan.py b/tests/modules/apigee_organization/test_plan.py
index ec2312c963..6e873bc0dc 100644
--- a/tests/modules/apigee_organization/test_plan.py
+++ b/tests/modules/apigee_organization/test_plan.py
@@ -23,7 +23,7 @@ def resources(plan_runner):
def test_resource_count(resources):
"Test number of resources created."
- assert len(resources) == 6
+ assert len(resources) == 7
def test_envgroup_attachment(resources):
@@ -42,3 +42,19 @@ def test_envgroup(resources):
assert envgroups[0]['name'] == 'eval'
assert len(envgroups[0]['hostnames']) == 1
assert envgroups[0]['hostnames'][0] == 'eval.api.example.com'
+
+
+def test_env(resources):
+ "Test environments."
+ envs = [r['values'] for r in resources if r['type']
+ == 'google_apigee_environment']
+ assert len(envs) == 3
+ assert envs[0]['name'] == 'eval1'
+ assert envs[0]['api_proxy_type'] == 'PROGRAMMABLE'
+ assert envs[0]['deployment_type'] == 'PROXY'
+ assert envs[1]['name'] == 'eval2'
+ assert envs[1]['api_proxy_type'] == 'CONFIGURABLE'
+ assert envs[1]['deployment_type'] == 'ARCHIVE'
+ assert envs[2]['name'] == 'eval3'
+ assert envs[2]['api_proxy_type'] == 'API_PROXY_TYPE_UNSPECIFIED'
+ assert envs[2]['deployment_type'] == 'DEPLOYMENT_TYPE_UNSPECIFIED'