generated from aws-ia/terraform-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
119 lines (107 loc) · 2.9 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
locals {
declared_app_components = [
for app_component in var.app_components :
{
name = app_component["app_component_name"]
type = app_component["app_component_type"]
resourceNames = [
for resource in app_component["resources"] :
resource["resource_name"]
]
}
]
app_common_app_component = [
{
name = "appcommon"
type = "AWS::ResilienceHub::AppCommonAppComponent",
resourceNames : []
}
]
app_components = tolist(concat(local.declared_app_components, local.app_common_app_component))
resources_list = flatten([
for component in var.app_components : [
for resource in component["resources"] : {
resource_name = resource["resource_name"]
resource_type = resource["resource_type"]
resource_identifier_type = resource["resource_identifier_type"]
resource_identifier = resource["resource_identifier"]
resource_region = resource["resource_region"]
}
]
])
state_file_mapping = [
{
mapping_type = "Terraform"
physical_resource_id = {
identifier = var.s3_state_file_url
type = "Native"
}
terraform_source_name = "TerraformStateFile"
}
]
resources_mappings_only = [
for resource in local.resources_list :
{
mapping_type = "Resource"
physical_resource_id = {
identifier = resource["resource_identifier"]
type = resource["resource_identifier_type"]
aws_region = resource["resource_region"]
}
resource_name = resource["resource_name"]
}
]
resource_mappings = concat(local.resources_mappings_only, local.state_file_mapping)
resources_json = [
for resource in local.resources_list :
{
logicalResourceId = {
identifier = resource["resource_name"]
}
type = resource["resource_type"]
name = resource["resource_name"]
}
]
}
resource "random_id" "session" {
byte_length = 16
}
resource "awscc_resiliencehub_app" "app" {
name = var.app_name
app_template_body = jsonencode({
resources = local.resources_json
appComponents = local.app_components
excludedResources = {}
version = 2
})
resource_mappings = local.resource_mappings
resiliency_policy_arn = awscc_resiliencehub_resiliency_policy.policy.policy_arn
tags = {
"terraform" = "managed"
}
}
resource "awscc_resiliencehub_resiliency_policy" "policy" {
policy_name = "Policy-${random_id.session.id}"
tier = "MissionCritical"
policy = {
az = {
rto_in_secs = var.rto
rpo_in_secs = var.rpo
}
hardware = {
rto_in_secs = var.rto
rpo_in_secs = var.rpo
}
software = {
rto_in_secs = var.rto
rpo_in_secs = var.rpo
}
region = {
rto_in_secs = var.rto
rpo_in_secs = var.rpo
}
}
tags = {
"terraform" = "managed"
}
}