generated from aws-ia/terraform-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
88 lines (77 loc) · 3.75 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
/*
AWS Migration Hub Refactor Spaces: Environment
Create AWS Migration Hub Refactor Spaces environment if no environment_id provided.
*/
module "refactor_spaces_environment" {
count = local.create_environment ? 1 : 0
source = "./modules/tf-refactor-spaces-environment"
environment_name = var.environment_name
environment_description = var.environment_description
provision_network_bridge = var.provision_network_bridge
shared_to_principals = var.shared_to_principals
resource_tags = local.tags
}
# Search for existing AWS Migration Hub Refactor Spaces environment with var.environment_id if not creating
data "awscc_refactorspaces_environment" "environment" {
count = local.create_environment ? 0 : 1
id = var.environment_id
}
/*
AWS Migration Hub Refactor Spaces: Applications
Create AWS Migration Hub Refactor Spaces applications (Strangler-Fig-Proxy).
*/
module "refactor_spaces_application" {
for_each = { for application in var.applications : application.application_name => application }
source = "./modules/tf-refactor-spaces-application"
environment_id = local.environment.environment_identifier
application_name = each.value.application_name
proxy_type = each.value.proxy_type
apigateway_stage_name = each.value.apigateway_stage_name
application_proxy_vpc_id = each.value.application_proxy_vpc_id
#resource_tags = local.tags # Tagging is not currently supported, to be enabled in future
}
/*
AWS Migration Hub Refactor Spaces: Applications
Return data objects for one or more AWS Migration Hub Refactor Spaces applications for use in service configuration.
*/
data "awscc_refactorspaces_application" "application" {
count = length(local.application_id_collection) # Using length as for_each keys would derived from resource attributes determined after apply if creating applications
id = local.application_id_collection[count.index]
}
/*
AWS Migration Hub Refactor Spaces: Service
Create refactor spaces services and routing constructs.
Enforce explicit ordering of service hosting the default route (create first/destroy last)
*/
module "refactor_spaces_service_defaults" {
for_each = { for service in var.services : "${service.application_name}_${service.name}" => service if contains(service.routes[*].source_path, "/") }
source = "./modules/tf-refactor-spaces-service"
environment_id = local.environment.environment_identifier
application_id = local.application_objects[each.value.application_name].application_identifier
name = each.value.name
description = each.value.description
endpoint_type = each.value.endpoint_type
lambda_arn = each.value.lambda_arn
url_endpoint = each.value.url_endpoint
health_url = each.value.health_url
vpc_id = each.value.vpc_id
routes = each.value.routes
}
module "refactor_spaces_service_non_defaults" {
for_each = { for service in var.services : "${service.application_name}_${service.name}" => service if !contains(service.routes[*].source_path, "/") }
source = "./modules/tf-refactor-spaces-service"
environment_id = local.environment.environment_identifier
application_id = local.application_objects[each.value.application_name].application_identifier
name = each.value.name
description = each.value.description
endpoint_type = each.value.endpoint_type
lambda_arn = each.value.lambda_arn
url_endpoint = each.value.url_endpoint
health_url = each.value.health_url
vpc_id = each.value.vpc_id
routes = each.value.routes
# To enforce explicit resource create/delete ordering of services with default routes
depends_on = [
module.refactor_spaces_service_defaults
]
}