-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
92 lines (79 loc) · 1.96 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
89
90
91
92
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "ec2_instance" {
ami = "ami-026b57f3c383c2eec"
instance_type = "t3a.medium"
key_name = var.ssh_key_name
vpc_security_group_ids = [aws_security_group.sg.id]
iam_instance_profile = aws_iam_instance_profile.instance_profile.name
user_data = data.template_file.userdata.rendered
tags = {
Name = var.prefix
}
}
locals {
ingress_ports = [22, 8080]
}
resource "aws_security_group" "sg" {
name = "${var.prefix}-sg"
dynamic "ingress" {
for_each = local.ingress_ports
iterator = port
content {
from_port = port.value
protocol = "tcp"
to_port = port.value
cidr_blocks = ["0.0.0.0/0"]
}
}
egress {
from_port = 0
protocol = -1
to_port = 0
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_iam_role" "aws_access" {
name = "${var.prefix}-role"
assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Action = "sts:AssumeRole"
Effect = "Allow"
Sid = ""
Principal = {
Service = "ec2.amazonaws.com"
}
}
]
})
inline_policy {
name = "eks-policy"
policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect : "Allow",
Action : ["eks:*"],
Resource : "*"
}]
})
}
managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess", "arn:aws:iam::aws:policy/AmazonEC2FullAccess", "arn:aws:iam::aws:policy/IAMFullAccess", "arn:aws:iam::aws:policy/AmazonS3FullAccess"]
}
resource "aws_iam_instance_profile" "instance_profile" {
name = "${var.prefix}-profile"
role = aws_iam_role.aws_access.name
}
data "template_file" "userdata" {
template = file("${abspath(path.module)}/userdata.sh")
}