forked from techservicesillinois/terraform-aws-ecs-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.tf
59 lines (44 loc) · 1.59 KB
/
data.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
locals {
all_subnets = distinct(concat(local.module_subnet_ids, try(var.network_configuration.subnet_ids, [])))
}
data "aws_caller_identity" "current" {}
data "aws_ecs_cluster" "selected" {
cluster_name = var.cluster
}
# Set boolean specifying whether to invoke get-subnets module to look up subnets.
locals {
do_subnet_lookup = try(var.network_configuration.subnet_type != null && var.network_configuration.vpc != null, false)
}
# Look up matching subnets.
module "get-subnets" {
source = "github.com/techservicesillinois/terraform-aws-util//modules/get-subnets?ref=v3.0.4"
count = local.do_subnet_lookup ? 1 : 0
subnet_type = var.network_configuration.subnet_type
vpc = var.network_configuration.vpc
}
locals {
module_subnet_ids = local.do_subnet_lookup ? try(module.get-subnets[0].subnets.ids, []) : []
}
## LB data sources
data "aws_lb" "selected" {
count = var.load_balancer != null ? 1 : 0
name = var.load_balancer.name
}
data "aws_lb_listener" "selected" {
count = var.load_balancer != null ? 1 : 0
load_balancer_arn = data.aws_lb.selected[0].arn
port = var.load_balancer.port
}
data "aws_security_group" "lb" {
count = var.load_balancer != null ? 1 : 0
name = data.aws_lb.selected[0].name
}
data "aws_security_group" "selected" {
count = try(length(var.network_configuration.security_group_names), 0)
name = var.network_configuration.security_group_names[count.index]
}
## Network data sources
data "aws_subnet" "selected" {
count = try(length(var.network_configuration) > 0, false) ? 1 : 0
id = local.all_subnets[0]
}