Skip to content

Commit 3f782fc

Browse files
committed
chore: adding the various upstream changes
1 parent b5ac6d6 commit 3f782fc

File tree

5 files changed

+160
-91
lines changed

5 files changed

+160
-91
lines changed

modules/destination/main.tf

+30-36
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,6 @@ module "collector" {
245245
providers = {
246246
aws.useast1 = aws.us_east_1
247247
}
248-
249-
depends_on = [
250-
aws_quicksight_user.admin
251-
]
252248
}
253249

254250
## Provision the cloud intelligence dashboards
@@ -272,13 +268,41 @@ module "dashboards" {
272268
}
273269

274270
depends_on = [
275-
aws_cloudformation_stack.core_data_export_destination,
271+
aws_cloudformation_stack.data_export_destination,
276272
aws_quicksight_account_subscription.subscription,
277273
aws_quicksight_user.admin,
278274
module.collector,
279275
]
280276
}
281277

278+
## Provision the stack contain the cora data exports in the management account
279+
## Deployment of same stack the management account
280+
resource "aws_cloudformation_stack" "data_export_destination" {
281+
capabilities = ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
282+
name = var.stack_name_cora_data_exports
283+
on_failure = "ROLLBACK"
284+
tags = var.tags
285+
template_url = format("%s/cudos/%s", local.bucket_url, "data-exports-aggregation.yaml")
286+
287+
parameters = {
288+
"DestinationAccountId" = local.account_id,
289+
"EnableSCAD" = var.enable_scad ? "yes" : "no",
290+
"ManageCOH" = "no",
291+
"ManageCUR2" = "yes",
292+
"SourceAccountIds" = join(",", local.payer_account_ids),
293+
}
294+
295+
lifecycle {
296+
ignore_changes = [
297+
capabilities,
298+
]
299+
}
300+
301+
depends_on = [
302+
aws_s3_object.cloudformation_templates,
303+
]
304+
}
305+
282306
## We need to provision the data collection stack in the colletor account
283307
resource "aws_cloudformation_stack" "cudos_data_collection" {
284308
name = var.stack_name_collectors
@@ -304,38 +328,8 @@ resource "aws_cloudformation_stack" "cudos_data_collection" {
304328
}
305329

306330
depends_on = [
331+
aws_cloudformation_stack.data_export_destination,
307332
aws_s3_object.cloudformation_templates,
308-
module.collector,
309-
module.dashboards,
310-
]
311-
}
312-
313-
## Provision the stack contain the cora data exports in the management account
314-
## Deployment of same stack the management account
315-
resource "aws_cloudformation_stack" "core_data_export_destination" {
316-
capabilities = ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
317-
name = var.stack_name_cora_data_exports
318-
on_failure = "ROLLBACK"
319-
tags = var.tags
320-
template_url = format("%s/cudos/%s", local.bucket_url, "data-exports-aggregation.yaml")
321-
322-
parameters = {
323-
"DestinationAccountId" = local.account_id,
324-
"EnableSCAD" = var.enable_scad ? "yes" : "no",
325-
"ManageCOH" = "no",
326-
"ManageCUR2" = "yes",
327-
"SourceAccountIds" = join(",", local.payer_account_ids),
328-
}
329-
330-
lifecycle {
331-
ignore_changes = [
332-
capabilities,
333-
]
334-
}
335-
336-
depends_on = [
337-
aws_s3_object.cloudformation_templates,
338-
module.collector,
339333
]
340334
}
341335

modules/source/locals.tf

-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ locals {
66
management_account_id = data.aws_caller_identity.current.account_id
77
## The s3 bucket name for the cloudformation scripts
88
stacks_base_url = format("https://%s.s3.%s.amazonaws.com", var.stacks_bucket_name, local.region)
9-
## The account id where the dashboard is being deployed
10-
destination_account_id = var.destination_account_id
119
## The organization units where the dashboard is being deployed
1210
organizational_unit_ids = join(",", var.organizational_unit_ids)
1311
## Indicate if the read permissions stack should be deployed

modules/source/main.tf

+8-3
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,15 @@ module "source" {
9797

9898
## Provision the stack contain the cora data exports in the management account
9999
## Deployment of same stack the management account
100-
resource "aws_cloudformation_stack" "core_data_export_management" {
100+
resource "aws_cloudformation_stack" "data_export_management" {
101101
capabilities = ["CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
102102
name = var.stack_name_data_exports_source
103103
on_failure = "ROLLBACK"
104104
tags = var.tags
105105
template_url = format("%s/cudos/%s", local.stacks_base_url, "data-exports-aggregation.yaml")
106106

107107
parameters = {
108-
"DestinationAccountId" = local.destination_account_id,
108+
"DestinationAccountId" = var.destination_account_id,
109109
"EnableSCAD" = var.enable_scad ? "yes" : "no",
110110
"ManageCOH" = var.enable_compute_optimizization_hub ? "yes" : "no",
111111
"ManageCUR2" = "yes",
@@ -116,6 +116,11 @@ resource "aws_cloudformation_stack" "core_data_export_management" {
116116
capabilities,
117117
]
118118
}
119+
120+
depends_on = [
121+
aws_s3_object.cloudformation_templates,
122+
module.source,
123+
]
119124
}
120125

121126
## We need to provision the read permissions stack within the management account, note
@@ -131,7 +136,7 @@ resource "aws_cloudformation_stack" "cudos_read_permissions" {
131136

132137
parameters = {
133138
"AllowModuleReadInMgmt" = "yes",
134-
"DataCollectionAccountID" = local.destination_account_id,
139+
"DataCollectionAccountID" = var.destination_account_id,
135140
"IncludeBackupModule" = var.enable_backup_module ? "yes" : "no",
136141
"IncludeBudgetsModule" = var.enable_budgets_module ? "yes" : "no",
137142
"IncludeComputeOptimizerModule" = var.enable_compute_optimizer_module ? "yes" : "no",

modules/source/variables.tf

+49-50
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
2-
variable "tags" {
3-
description = "Tags to apply to all resources"
4-
type = map(string)
5-
}
6-
71
variable "destination_account_id" {
82
description = "The AWS account ID for the destination account"
93
type = string
@@ -14,22 +8,28 @@ variable "destination_bucket_arn" {
148
type = string
159
}
1610

17-
variable "stacks_bucket_name" {
18-
description = "The name of the bucket to store the CloudFormation templates"
19-
type = string
20-
default = "cid-cloudformation-templates"
11+
variable "enable_backup_module" {
12+
description = "Indicates if the Backup module should be enabled"
13+
type = bool
14+
default = true
2115
}
2216

23-
variable "stack_name_read_permissions" {
24-
description = "The name of the CloudFormation stack to create the collectors"
25-
type = string
26-
default = "CidDataCollectionReadPermissionsStack"
17+
variable "enable_budgets_module" {
18+
description = "Indicates if the Budget module should be enabled"
19+
type = bool
20+
default = true
2721
}
2822

29-
variable "stack_name_data_exports_source" {
30-
description = "The name of the CloudFormation stack to create the Data Exports"
31-
type = string
32-
default = "CidDataExportsSourceStack"
23+
variable "enable_compute_optimizer_module" {
24+
description = "Indicates if the Compute Optimizer module should be enabled"
25+
type = bool
26+
default = true
27+
}
28+
29+
variable "enable_compute_optimizization_hub" {
30+
description = "Indicates if the Compute Optimizization Hub module should be enabled"
31+
type = bool
32+
default = false
3333
}
3434

3535
variable "enable_cost_anomaly_module" {
@@ -38,8 +38,8 @@ variable "enable_cost_anomaly_module" {
3838
default = true
3939
}
4040

41-
variable "enable_scad" {
42-
description = "Indicates if the SCAD module should be enabled, only available when Cora enabled"
41+
variable "enable_ecs_chargeback_module" {
42+
description = "Indicates if the ECS Chargeback module should be enabled"
4343
type = bool
4444
default = false
4545
}
@@ -50,28 +50,28 @@ variable "enable_health_events_module" {
5050
default = true
5151
}
5252

53-
variable "enable_backup_module" {
54-
description = "Indicates if the Backup module should be enabled"
53+
variable "enable_inventory_module" {
54+
description = "Indicates if the Inventory module should be enabled"
5555
type = bool
5656
default = true
5757
}
5858

59-
variable "enable_budgets_module" {
60-
description = "Indicates if the Budget module should be enabled"
59+
variable "enable_rds_utilization_module" {
60+
description = "Indicates if the RDS Utilization module should be enabled"
6161
type = bool
6262
default = true
6363
}
6464

65-
variable "enable_ecs_chargeback_module" {
66-
description = "Indicates if the ECS Chargeback module should be enabled"
65+
variable "enable_rightsizing_module" {
66+
description = "Indicates if the Rightsizing module should be enabled"
6767
type = bool
68-
default = false
68+
default = true
6969
}
7070

71-
variable "enable_compute_optimizer_module" {
72-
description = "Indicates if the Compute Optimizer module should be enabled"
71+
variable "enable_scad" {
72+
description = "Indicates if the SCAD module should be enabled, only available when Cora enabled"
7373
type = bool
74-
default = true
74+
default = false
7575
}
7676

7777
variable "enable_tao_module" {
@@ -86,32 +86,31 @@ variable "enable_transit_gateway_module" {
8686
default = true
8787
}
8888

89-
variable "enable_inventory_module" {
90-
description = "Indicates if the Inventory module should be enabled"
91-
type = bool
92-
default = true
89+
variable "organizational_unit_ids" {
90+
description = "List of organization units where the read permissions stack will be deployed"
91+
type = list(string)
92+
default = []
9393
}
9494

95-
variable "enable_rds_utilization_module" {
96-
description = "Indicates if the RDS Utilization module should be enabled"
97-
type = bool
98-
default = true
95+
variable "stack_name_data_exports_source" {
96+
description = "The name of the CloudFormation stack to create the Data Exports"
97+
type = string
98+
default = "CidDataExportsSourceStack"
9999
}
100100

101-
variable "enable_rightsizing_module" {
102-
description = "Indicates if the Rightsizing module should be enabled"
103-
type = bool
104-
default = true
101+
variable "stack_name_read_permissions" {
102+
description = "The name of the CloudFormation stack to create the collectors"
103+
type = string
104+
default = "CidDataCollectionReadPermissionsStack"
105105
}
106106

107-
variable "enable_compute_optimizization_hub" {
108-
description = "Indicates if the Compute Optimizization Hub module should be enabled"
109-
type = bool
110-
default = false
107+
variable "stacks_bucket_name" {
108+
description = "The name of the bucket to store the CloudFormation templates"
109+
type = string
110+
default = "cid-cloudformation-templates"
111111
}
112112

113-
variable "organizational_unit_ids" {
114-
description = "List of organization units where the read permissions stack will be deployed"
115-
type = list(string)
116-
default = []
113+
variable "tags" {
114+
description = "Tags to apply to all resources"
115+
type = map(string)
117116
}

variables.awk

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env -S awk -f
2+
# https://gist.github.com/yermulnik/7e0cf991962680d406692e1db1b551e6
3+
# Tested with GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)
4+
# Usage: /path/to/tf_vars_sort.awk < variables.tf | tee sorted_variables.tf
5+
# Note: "chmod +x /path/to/tf_vars_sort.awk" before use
6+
# No licensing; [email protected], 2021-2024
7+
{
8+
# skip blank lines at the beginning of file
9+
if (!resource_type && length($0) == 0) next
10+
11+
# pick only known Terraform resource definition block types of the 1st level
12+
# https://github.com/hashicorp/terraform/blob/main/internal/configs/parser_config.go#L92-L230
13+
switch ($0) {
14+
# ex: block_type {
15+
case /^[[:space:]]*(import|locals|moved|removed|terraform)[[:space:]]+{/:
16+
resource_type = $1
17+
resource_ident = resource_type "|" block_counter++
18+
break
19+
# ex: block_type type_label name_label {
20+
case /^[[:space:]]*(data|ephemeral|resource)[[:space:]]+("?[[:alnum:]_-]+"?[[:space:]]+){2}{/:
21+
resource_type = $1
22+
resource_subtype = $2
23+
resource_name = $3
24+
resource_ident = resource_type "|" resource_subtype "|" resource_name
25+
break
26+
# ex: block_type name_label {
27+
case /^[[:space:]]*(check|module|output|provider|variable)[[:space:]]+"?[[:alnum:]_-]+"?[[:space:]]+{/:
28+
resource_type = $1
29+
resource_name = $2
30+
resource_ident = resource_type "|" resource_name
31+
break
32+
}
33+
arr[resource_ident] = arr[resource_ident] ? arr[resource_ident] RS $0 : $0
34+
} END {
35+
# exit if there was solely empty input
36+
# (input consisting of multiple empty lines only, counts in as empty input too)
37+
if (length(arr) == 0) exit
38+
# declare empty array (the one to hold final result)
39+
split("", res)
40+
# case-insensitive string operations in this block
41+
# (primarily for the `asort()` call below)
42+
IGNORECASE = 1
43+
# sort by `resource_ident` which is a key in our case
44+
asort(arr)
45+
46+
# blank-lines-fix each block
47+
for (item in arr) {
48+
split(arr[item],new_arr,RS)
49+
50+
# remove multiple blank lines at the end of resource definition block
51+
while (length(new_arr[length(new_arr)]) == 0) delete new_arr[length(new_arr)]
52+
53+
# add one single blank line at the end of the resource definition block
54+
# so that blocks are delimited with a blank like to align with TF code style
55+
new_arr[length(new_arr)+1] = RS
56+
57+
# fill resulting array with data from each resource definition block
58+
for (line in new_arr) {
59+
# trim whitespaces at the end of each line in resource definition block
60+
gsub(/[[:space:]]+$/, "", new_arr[line])
61+
res[length(res)+1] = new_arr[line]
62+
}
63+
}
64+
65+
# ensure there are no extra blank lines at the beginning and end of data
66+
while (length(res[1]) == 0) delete res[1]
67+
while (length(res[length(res)]) == 0) delete res[length(res)]
68+
69+
# print resulting data to stdout
70+
for (line in res) {
71+
print res[line]
72+
}
73+
}

0 commit comments

Comments
 (0)