@@ -53,18 +53,6 @@ resource "aws_autoscaling_group" "app" {
53
53
launch_configuration = aws_launch_configuration. app . name
54
54
}
55
55
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
-
68
56
data "aws_ami" "stable_coreos" {
69
57
most_recent = true
70
58
@@ -91,11 +79,17 @@ resource "aws_launch_configuration" "app" {
91
79
aws_security_group . instance_sg . id ,
92
80
]
93
81
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
+ })
99
93
associate_public_ip_address = true
100
94
101
95
lifecycle {
@@ -168,20 +162,14 @@ resource "aws_ecs_cluster" "main" {
168
162
name = " terraform_example_ecs_cluster"
169
163
}
170
164
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" , {
175
168
image_url = " ghost:latest"
176
169
container_name = " ghost"
177
170
log_group_region = var.aws_region
178
171
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
+ })
185
173
}
186
174
187
175
resource "aws_ecs_service" "test" {
@@ -275,19 +263,13 @@ resource "aws_iam_role" "app_instance" {
275
263
EOF
276
264
}
277
265
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 " , {
282
270
app_log_group_arn = aws_cloudwatch_log_group.app.arn
283
271
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
+ })
291
273
}
292
274
293
275
# # ALB
0 commit comments