Skip to content

Commit

Permalink
Merge pull request #927 from kmucha555/kmucha555/f_apigee_env_deployment
Browse files Browse the repository at this point in the history
Add support for deployment type and api proxy type for Apigee org
  • Loading branch information
juliocc committed Oct 27, 2022
2 parents 3dc7b5d + 798fd6c commit f8e5255
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 32 deletions.
59 changes: 37 additions & 22 deletions modules/apigee-organization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand All @@ -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. | <code>string</code> || |
| [project_id](variables.tf#L61) | Project ID to host this Apigee organization (will also become the Apigee Org name). | <code>string</code> || |
| [runtime_type](variables.tf#L66) | Apigee runtime type. Must be `CLOUD` or `HYBRID`. | <code>string</code> || |
| [project_id](variables.tf#L72) | Project ID to host this Apigee organization (will also become the Apigee Org name). | <code>string</code> || |
| [runtime_type](variables.tf#L77) | Apigee runtime type. Must be `CLOUD` or `HYBRID`. | <code>string</code> || |
| [apigee_envgroups](variables.tf#L22) | Apigee Environment Groups. | <code title="map&#40;object&#40;&#123;&#10; environments &#61; list&#40;string&#41;&#10; hostnames &#61; list&#40;string&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [apigee_environments](variables.tf#L31) | Apigee Environment Names. | <code>list&#40;string&#41;</code> | | <code>&#91;&#93;</code> |
| [authorized_network](variables.tf#L37) | VPC network self link (requires service network peering enabled (Used in Apigee X only). | <code>string</code> | | <code>null</code> |
| [billing_type](variables.tf#L75) | Billing type of the Apigee organization. | <code>string</code> | | <code>null</code> |
| [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). | <code>string</code> | | <code>null</code> |
| [description](variables.tf#L49) | Description of the Apigee Organization. | <code>string</code> | | <code>&#34;Apigee Organization created by tf module&#34;</code> |
| [display_name](variables.tf#L55) | Display Name of the Apigee Organization. | <code>string</code> | | <code>null</code> |
| [apigee_environments](variables.tf#L31) | Apigee Environment Names. | <code title="map&#40;object&#40;&#123;&#10; api_proxy_type &#61; optional&#40;string, &#34;API_PROXY_TYPE_UNSPECIFIED&#34;&#41;&#10; deployment_type &#61; optional&#40;string, &#34;DEPLOYMENT_TYPE_UNSPECIFIED&#34;&#41;&#10;&#125;&#41;&#41;">map&#40;object&#40;&#123;&#8230;&#125;&#41;&#41;</code> | | <code>&#123;&#125;</code> |
| [authorized_network](variables.tf#L48) | VPC network self link (requires service network peering enabled (Used in Apigee X only). | <code>string</code> | | <code>null</code> |
| [billing_type](variables.tf#L86) | Billing type of the Apigee organization. | <code>string</code> | | <code>null</code> |
| [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). | <code>string</code> | | <code>null</code> |
| [description](variables.tf#L60) | Description of the Apigee Organization. | <code>string</code> | | <code>&#34;Apigee Organization created by tf module&#34;</code> |
| [display_name](variables.tf#L66) | Display Name of the Apigee Organization. | <code>string</code> | | <code>null</code> |

## Outputs

Expand Down
16 changes: 13 additions & 3 deletions modules/apigee-organization/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 : {
Expand All @@ -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" {
Expand Down
15 changes: 13 additions & 2 deletions modules/apigee-organization/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
15 changes: 11 additions & 4 deletions tests/modules/apigee_organization/fixture/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
18 changes: 17 additions & 1 deletion tests/modules/apigee_organization/test_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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'

0 comments on commit f8e5255

Please sign in to comment.