forked from GoogleCloudPlatform/cloud-foundation-fabric
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
170 lines (159 loc) · 5.65 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
locals {
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)
}
resource "google_apigee_organization" "organization" {
count = var.organization == null ? 0 : 1
analytics_region = var.organization.analytics_region
project_id = var.project_id
authorized_network = var.organization.authorized_network
billing_type = var.organization.billing_type
runtime_type = var.organization.runtime_type
runtime_database_encryption_key_name = var.organization.database_encryption_key
retention = var.organization.retention
disable_vpc_peering = var.organization.disable_vpc_peering
}
resource "google_apigee_envgroup" "envgroups" {
for_each = var.envgroups
name = each.key
hostnames = each.value
org_id = local.org_id
}
resource "google_apigee_environment" "environments" {
for_each = var.environments
name = each.key
display_name = each.value.display_name
description = each.value.description
deployment_type = each.value.deployment_type
api_proxy_type = each.value.api_proxy_type
dynamic "node_config" {
for_each = try(each.value.node_config, null) != null ? [""] : []
content {
min_node_count = each.value.node_config.min_node_count
max_node_count = each.value.node_config.max_node_count
}
}
org_id = local.org_id
lifecycle {
ignore_changes = [
node_config["current_aggregate_node_count"]
]
}
}
resource "google_apigee_envgroup_attachment" "envgroup_attachments" {
for_each = merge(concat([for k1, v1 in var.environments : {
for v2 in coalesce(v1.envgroups, []) : "${k1}-${v2}" => {
environment = k1
envgroup = v2
}
}])...)
envgroup_id = try(google_apigee_envgroup.envgroups[each.value.envgroup].id, each.value.envgroup)
environment = google_apigee_environment.environments[each.value.environment].name
}
resource "google_apigee_environment_iam_binding" "binding" {
for_each = merge(concat([for k1, v1 in var.environments : {
for k2, v2 in coalesce(v1.iam, {}) : "${k1}-${k2}" => {
environment = "${k1}"
role = k2
members = v2
}
}])...)
org_id = local.org_id
env_id = google_apigee_environment.environments[each.value.environment].name
role = each.value.role
members = each.value.members
}
resource "google_apigee_instance" "instances" {
for_each = var.instances
name = coalesce(each.value.name, "instance-${each.key}")
display_name = each.value.display_name
description = each.value.description
location = each.key
org_id = local.org_id
ip_range = (
compact([each.value.runtime_ip_cidr_range, each.value.troubleshooting_ip_cidr_range]) == []
? null
: join(",", compact([each.value.runtime_ip_cidr_range, each.value.troubleshooting_ip_cidr_range]))
)
disk_encryption_key_name = each.value.disk_encryption_key
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" {
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.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" {
for_each = var.endpoint_attachments
org_id = local.org_id
endpoint_attachment_id = each.key
location = each.value.region
service_attachment = each.value.service_attachment
}
resource "google_apigee_addons_config" "addons_config" {
for_each = toset(var.addons_config == null ? [] : [""])
org = local.org_name
addons_config {
dynamic "advanced_api_ops_config" {
for_each = var.addons_config.advanced_api_ops ? [] : [""]
content {
enabled = true
}
}
dynamic "api_security_config" {
for_each = var.addons_config.api_security ? [] : [""]
content {
enabled = true
}
}
dynamic "connectors_platform_config" {
for_each = var.addons_config.connectors_platform ? [] : [""]
content {
enabled = true
}
}
dynamic "integration_config" {
for_each = var.addons_config.integration ? [] : [""]
content {
enabled = true
}
}
dynamic "monetization_config" {
for_each = var.addons_config.monetization ? [] : [""]
content {
enabled = true
}
}
}
}