forked from terraform-ibm-modules/terraform-ibm-cos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
199 lines (182 loc) · 6.89 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
##############################################################################
# Resource Group
##############################################################################
module "resource_group" {
source = "terraform-ibm-modules/resource-group/ibm"
version = "1.1.4"
# if an existing resource group is not set (null) create a new one using prefix
resource_group_name = var.resource_group == null ? "${var.prefix}-resource-group" : null
existing_resource_group_name = var.resource_group
}
##############################################################################
# VPC
##############################################################################
resource "ibm_is_vpc" "example_vpc" {
name = "${var.prefix}-vpc"
resource_group = module.resource_group.resource_group_id
tags = var.resource_tags
}
resource "ibm_is_subnet" "testacc_subnet" {
name = "${var.prefix}-subnet"
vpc = ibm_is_vpc.example_vpc.id
zone = "${var.region}-1"
total_ipv4_address_count = 256
resource_group = module.resource_group.resource_group_id
}
##############################################################################
# Observability Instances (Sysdig + AT)
##############################################################################
locals {
existing_at = var.existing_at_instance_crn != null ? true : false
at_crn = var.existing_at_instance_crn == null ? module.observability_instances.activity_tracker_crn : var.existing_at_instance_crn
}
# Create Sysdig and Activity Tracker instance
module "observability_instances" {
source = "terraform-ibm-modules/observability-instances/ibm"
version = "2.11.0"
providers = {
logdna.at = logdna.at
logdna.ld = logdna.ld
}
region = var.region
resource_group_id = module.resource_group.resource_group_id
cloud_monitoring_instance_name = "${var.prefix}-sysdig"
cloud_monitoring_plan = "graduated-tier"
enable_platform_logs = false
enable_platform_metrics = false
log_analysis_provision = false
activity_tracker_instance_name = "${var.prefix}-at"
activity_tracker_tags = var.resource_tags
activity_tracker_plan = "7-day"
activity_tracker_provision = !local.existing_at
log_analysis_tags = var.resource_tags
cloud_monitoring_tags = var.resource_tags
}
##############################################################################
# Get Cloud Account ID
##############################################################################
data "ibm_iam_account_settings" "iam_account_settings" {
}
##############################################################################
# Create CBR Zone
##############################################################################
module "cbr_zone" {
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
version = "1.18.0"
name = "${var.prefix}-VPC-fscloud-nz"
zone_description = "CBR Network zone containing VPC"
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
addresses = [{
type = "vpc", # to bind a specific vpc to the zone
value = ibm_is_vpc.example_vpc.crn,
}]
}
# Allow schematics, from outside VPC, to manage resources
module "cbr_zone_schematics" {
source = "terraform-ibm-modules/cbr/ibm//modules/cbr-zone-module"
version = "1.18.0"
name = "${var.prefix}-schematics-fscloud-nz"
zone_description = "CBR Network zone containing Schematics"
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
addresses = [{
type = "serviceRef", # to bind a schematics to the zone
ref = {
# Allow all schematics instances from all geographies
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
service_name = "schematics"
}
}]
}
##############################################################################
# Create COS instance and bucket with:
# - Encryption
# - Monitoring
# - Activity Tracking
##############################################################################
module "cos_fscloud" {
source = "../../modules/fscloud"
resource_group_id = module.resource_group.resource_group_id
cos_instance_name = "${var.prefix}-cos"
cos_tags = var.resource_tags
access_tags = var.access_tags
# CBR rule only allowing the COS instance to be accessbile over the private endpoint from within the VPC
# or from schematics
instance_cbr_rules = [{
description = "sample rule for the instance"
enforcement_mode = "enabled"
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
rule_contexts = [{
attributes = [
{
"name" : "endpointType",
"value" : "private"
},
{
name = "networkZoneId"
value = module.cbr_zone.zone_id
}]
}, {
attributes = [
{
"name" : "endpointType",
"value" : "private"
},
{
name = "networkZoneId"
value = module.cbr_zone_schematics.zone_id
}]
}]
operations = [{
api_types = [{
api_type_id = "crn:v1:bluemix:public:context-based-restrictions::::api-type:"
}]
}]
}]
# Create one regional bucket, encrypted with the HPCS root key
bucket_configs = [{
access_tags = var.access_tags
bucket_name = "${var.prefix}-bucket"
kms_key_crn = var.bucket_hpcs_key_crn
kms_guid = var.bucket_existing_hpcs_instance_guid
management_endpoint_type = var.management_endpoint_type_for_bucket
region_location = var.region
activity_tracking = {
activity_tracker_crn = local.at_crn
}
metrics_monitoring = {
metrics_monitoring_crn = module.observability_instances.cloud_monitoring_crn
}
# CBR rule only allowing the COS bucket to be accessbile over the private endpoint from within the VPC
cbr_rules = [{
description = "sample rule for ${var.prefix}-bucket"
enforcement_mode = "enabled"
account_id = data.ibm_iam_account_settings.iam_account_settings.account_id
rule_contexts = [{
attributes = [
{
"name" : "endpointType",
"value" : "private"
},
{
name = "networkZoneId"
value = module.cbr_zone.zone_id
}
] }, {
attributes = [
{
"name" : "endpointType",
"value" : "private"
},
{
name = "networkZoneId"
value = module.cbr_zone_schematics.zone_id
}]
}]
operations = [{
api_types = [{
api_type_id = "crn:v1:bluemix:public:context-based-restrictions::::api-type:"
}]
}]
}]
}, ]
}