generated from oracle-devrel/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.tf
172 lines (163 loc) · 5.04 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
171
172
// Copyright (c) 2020 Oracle and/or its affiliates.
// Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
// --- provider settings --- //
terraform {
required_providers {
oci = {
source = "oracle/oci"
}
}
}
// --- provider settings --- //
// --- tenancy configuration --- //
provider "oci" {
alias = "service"
region = var.location
}
variable "tenancy_ocid" {}
variable "region" {}
variable "compartment_ocid" {}
variable "current_user_ocid" {}
locals {
topologies = flatten(compact([
var.management == true ? "management" : "",
var.host == true ? "host" : "",
var.nodes == true ? "nodes" : "",
var.container == true ? "container" : ""
]))
domains = jsondecode(file("${path.module}/default/resident/domains.json"))
segments = jsondecode(file("${path.module}/default/network/segments.json"))
wallets = jsondecode(file("${path.module}/default/encryption/wallets.json"))
}
module "configuration" {
source = "./default/"
providers = {oci = oci.service}
account = {
tenancy_id = var.tenancy_ocid
compartment_id = var.compartment_ocid
home = var.region
user_id = var.current_user_ocid
}
resident = {
topologies = local.topologies
domains = local.domains
segments = local.segments
}
solution = {
adb = "${var.adb_type}_${var.adb_size}"
budget = var.budget
class = var.class
encrypt = var.create_wallet
name = var.name
region = var.location
organization = var.organization
osn = var.osn
owner = var.owner
repository = var.repository
stage = var.stage
tenancy = var.tenancy_ocid
wallet = var.wallet
}
}
// --- tenancy configuration --- //
// --- operation controls --- //
provider "oci" {
alias = "home"
region = module.configuration.tenancy.region.key
}
module "resident" {
source = "./assets/resident"
depends_on = [module.configuration]
providers = {oci = oci.home}
schema = {
# Enable compartment delete on destroy. If true, compartment will be deleted when `terraform destroy` is executed; If false, compartment will not be deleted on `terraform destroy` execution
enable_delete = var.stage != "PRODUCTION" ? true : false
# Reference to the deployment root. The service is setup in an encapsulating child compartment
parent_id = var.tenancy_ocid
user_id = var.current_user_ocid
}
config = {
tenancy = module.configuration.tenancy
service = module.configuration.service
}
}
output "resident" {
value = {for resource, parameter in module.resident : resource => parameter}
}
// --- operation controls --- //
// --- wallet configuration --- //
module "encryption" {
source = "./assets/encryption"
depends_on = [module.configuration, module.resident]
providers = {oci = oci.service}
for_each = {for wallet in local.wallets : wallet.name => wallet}
schema = {
create = var.create_wallet
type = var.wallet == "SOFTWARE" ? "DEFAULT" : "VIRTUAL_PRIVATE"
}
config = {
tenancy = module.configuration.tenancy
service = module.configuration.service
encryption = module.configuration.encryption[each.key]
}
assets = {
resident = module.resident
}
}
output "encryption" {
value = {for resource, parameter in module.encryption : resource => parameter}
sensitive = true
}
// --- wallet configuration --- //
// --- network configuration --- //
module "network" {
source = "./assets/network"
depends_on = [module.configuration, module.encryption, module.resident]
providers = {oci = oci.service}
for_each = {for segment in local.segments : segment.name => segment}
schema = {
internet = var.internet == "PUBLIC" ? "ENABLE" : "DISABLE"
nat = var.nat == true ? "ENABLE" : "DISABLE"
ipv6 = var.ipv6
osn = var.osn
}
config = {
tenancy = module.configuration.tenancy
service = module.configuration.service
network = module.configuration.network[each.key]
}
assets = {
encryption = module.encryption["main"]
resident = module.resident
}
}
output "network" {
value = {for resource, parameter in module.network : resource => parameter}
}
// --- network configuration --- //
// --- database creation --- //
module "database" {
source = "./assets/database"
depends_on = [module.configuration, module.resident, module.network, module.encryption]
providers = {oci = oci.service}
schema = {
class = var.class
create = var.create_adb
password = var.create_wallet == false ? "RANDOM" : "VAULT"
}
config = {
tenancy = module.configuration.tenancy
service = module.configuration.service
database = module.configuration.database
}
assets = {
encryption = module.encryption["main"]
network = module.network["core"]
resident = module.resident
}
}
output "database" {
value = {for resource, parameter in module.database : resource => parameter}
sensitive = true
}
// --- database creation --- //