-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunchconfig.tf
104 lines (98 loc) · 3.02 KB
/
launchconfig.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
data "aws_iam_policy_document" "ec2" {
statement {
actions = ["sts:AssumeRole"]
principals {
type = "Service"
identifiers = ["ec2.amazonaws.com"]
}
}
}
resource "aws_iam_policy" "session-manager" {
description = "session-manager"
name = "session-manager"
policy = jsonencode({
"Version":"2012-10-17",
"Statement":[
{
"Action": "ec2:*",
"Effect": "Allow",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "elasticloadbalancing:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "cloudwatch:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "autoscaling:*",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "iam:CreateServiceLinkedRole",
"Resource": "*",
"Condition": {
"StringEquals": {
"iam:AWSServiceName": [
"autoscaling.amazonaws.com",
"ec2scheduled.amazonaws.com",
"elasticloadbalancing.amazonaws.com",
"spot.amazonaws.com",
"spotfleet.amazonaws.com",
"transitgateway.amazonaws.com"
]
}
}
}
]
})
}
resource "aws_iam_role" "session-manager" {
assume_role_policy = data.aws_iam_policy_document.ec2.json
name = "session-manager"
tags = {
Name = "session-manager"
}
}
resource "aws_iam_instance_profile" "session-manager" {
name = "session-manager"
role = aws_iam_role.session-manager.name
}
resource "aws_instance" "bastion" {
ami = lookup(var.amis, var.region)
instance_type = "${var.instance_type}"
key_name = "protocol-assignment"
iam_instance_profile = aws_iam_instance_profile.session-manager.id
associate_public_ip_address = true
security_groups = [aws_security_group.ec2.id]
subnet_id = aws_subnet.public-subnet-1.id
tags = {
Name = "Bastion"
}
}
resource "aws_launch_configuration" "ec2" {
# count = var.instance_count
name = "${var.ec2_instance_name}-instances-lc"
image_id = lookup(var.amis, var.region)
instance_type = "${var.instance_type}"
security_groups = [aws_security_group.ec2.id]
key_name = "protocol-assignment"
iam_instance_profile = aws_iam_instance_profile.session-manager.id
associate_public_ip_address = false
# user_data = <<-EOL
# #!/bin/bash -xe
# sudo yum update -y
# sudo yum -y install docker
# sudo service docker start
# sudo usermod -a -G docker ec2-user
# sudo chmod 666 /var/run/docker.sock
# docker pull ahnay2019/nodejs
# docker run -d -p 80:8080 --name assignment ahnay2019/nodejs
# EOL
}