Skip to content

Commit dd1018e

Browse files
examples/ecs-alb: Replace template_file data sources (#23395)
1 parent ce9280b commit dd1018e

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

examples/ecs-alb/main.tf

+20-38
Original file line numberDiff line numberDiff line change
@@ -53,18 +53,6 @@ resource "aws_autoscaling_group" "app" {
5353
launch_configuration = aws_launch_configuration.app.name
5454
}
5555

56-
data "template_file" "cloud_config" {
57-
template = file("${path.module}/cloud-config.yml")
58-
59-
vars = {
60-
aws_region = var.aws_region
61-
ecs_cluster_name = aws_ecs_cluster.main.name
62-
ecs_log_level = "info"
63-
ecs_agent_version = "latest"
64-
ecs_log_group_name = aws_cloudwatch_log_group.ecs.name
65-
}
66-
}
67-
6856
data "aws_ami" "stable_coreos" {
6957
most_recent = true
7058

@@ -91,11 +79,17 @@ resource "aws_launch_configuration" "app" {
9179
aws_security_group.instance_sg.id,
9280
]
9381

94-
key_name = var.key_name
95-
image_id = data.aws_ami.stable_coreos.id
96-
instance_type = var.instance_type
97-
iam_instance_profile = aws_iam_instance_profile.app.name
98-
user_data = data.template_file.cloud_config.rendered
82+
key_name = var.key_name
83+
image_id = data.aws_ami.stable_coreos.id
84+
instance_type = var.instance_type
85+
iam_instance_profile = aws_iam_instance_profile.app.name
86+
user_data = templatefile("${path.module}/cloud-config.yml", {
87+
aws_region = var.aws_region
88+
ecs_cluster_name = aws_ecs_cluster.main.name
89+
ecs_log_level = "info"
90+
ecs_agent_version = "latest"
91+
ecs_log_group_name = aws_cloudwatch_log_group.ecs.name
92+
})
9993
associate_public_ip_address = true
10094

10195
lifecycle {
@@ -168,20 +162,14 @@ resource "aws_ecs_cluster" "main" {
168162
name = "terraform_example_ecs_cluster"
169163
}
170164

171-
data "template_file" "task_definition" {
172-
template = file("${path.module}/task-definition.json")
173-
174-
vars = {
165+
resource "aws_ecs_task_definition" "ghost" {
166+
family = "tf_example_ghost_td"
167+
container_definitions = templatefile("${path.module}/task-definition.json", {
175168
image_url = "ghost:latest"
176169
container_name = "ghost"
177170
log_group_region = var.aws_region
178171
log_group_name = aws_cloudwatch_log_group.app.name
179-
}
180-
}
181-
182-
resource "aws_ecs_task_definition" "ghost" {
183-
family = "tf_example_ghost_td"
184-
container_definitions = data.template_file.task_definition.rendered
172+
})
185173
}
186174

187175
resource "aws_ecs_service" "test" {
@@ -275,19 +263,13 @@ resource "aws_iam_role" "app_instance" {
275263
EOF
276264
}
277265

278-
data "template_file" "instance_profile" {
279-
template = file("${path.module}/instance-profile-policy.json")
280-
281-
vars = {
266+
resource "aws_iam_role_policy" "instance" {
267+
name = "TfEcsExampleInstanceRole"
268+
role = aws_iam_role.app_instance.name
269+
policy = templatefile("${path.module}/instance-profile-policy.json", {
282270
app_log_group_arn = aws_cloudwatch_log_group.app.arn
283271
ecs_log_group_arn = aws_cloudwatch_log_group.ecs.arn
284-
}
285-
}
286-
287-
resource "aws_iam_role_policy" "instance" {
288-
name = "TfEcsExampleInstanceRole"
289-
role = aws_iam_role.app_instance.name
290-
policy = data.template_file.instance_profile.rendered
272+
})
291273
}
292274

293275
## ALB

0 commit comments

Comments
 (0)