-
Notifications
You must be signed in to change notification settings - Fork 2
/
terraform_config.tf
100 lines (86 loc) · 2.82 KB
/
terraform_config.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
# File: terraform_config.tf
# Author: Tim Siwula <[email protected]>
# Date: Wed Jul 13th 2016
# This is a terraform script that will bootstrap an autoscaling group on AWS preinstalled with nginx. Access rights restricted to ELB only.
# Update: terraform get
# Complie: terraform plan
# Run: terraform apply
# Stop: terraform destroy
#
# docs:
# https://aws.amazon.com/blogs/apn/terraform-beyond-the-basics-with-aws/
# https://github.com/terraform-community-modules/tf_aws_asg_elb
# https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html
# https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html
# https://github.com/hashicorp/terraform/tree/master/examples
# ------------------------------------------------------------------
# 1. Define aws as provider
# ------------------------------------------------------------------
provider "aws" {
}
# ------------------------------------------------------------------
# 2. Define iam access
# ------------------------------------------------------------------
resource "aws_iam_role" "ecs" {
name = "ecs"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "sts:AssumeRole",
"Principal": {
"Service": "ec2.amazonaws.com"
},
"Effect": "Allow",
"Sid": ""
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "ecs_for_ec2" {
name = "ecs-for-ec2"
roles = ["${aws_iam_role.ecs.id}"]
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceforEC2Role"
}
resource "aws_iam_role" "ecs_elb" {
name = "ecs-elb"
assume_role_policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "ecs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
}
resource "aws_iam_policy_attachment" "ecs_elb" {
name = "ecs_elb"
roles = ["${aws_iam_role.ecs_elb.id}"]
policy_arn = "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceRole"
}
# ------------------------------------------------------------------
# 2. define a vpc
# ------------------------------------------------------------------
module "vpc" {
source = "github.com/terraform-community-modules/tf_aws_vpc"
name = "my-vpc"
cidr = "10.0.0.0/16"
private_subnets = "10.0.1.0/24,10.0.2.0/24,10.0.3.0/24"
public_subnets = "10.0.101.0/24,10.0.102.0/24,10.0.103.0/24"
azs = "us-east-1d, us-east-1a, us-east-1e, us-east-1c"
}
# ------------------------------------------------------------------
# 3. define a provisioner for bootstrap configs
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# 3. elb
# ------------------------------------------------------------------