Skip to content

Commit 17b68f7

Browse files
backup_solution_terraform
1 parent b6b8c4d commit 17b68f7

6 files changed

Lines changed: 128 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
resource "aws_instance" "my-test-instance" {
2+
ami = "${var.test_ami}"
3+
instance_type = "${var.instance_type}"
4+
iam_instance_profile = "${aws_iam_instance_profile.my-test-profile.name}"
5+
key_name = "vpcflowlogs"
6+
disable_api_termination = false
7+
8+
tags {
9+
Name = "my-test-instance"
10+
}
11+
}
12+
13+
resource "aws_iam_role" "my-test-instance-role" {
14+
name = "my-testnew-instance-role"
15+
16+
assume_role_policy = <<EOF
17+
{
18+
"Version": "2012-10-17",
19+
"Statement": [
20+
{
21+
"Action": "sts:AssumeRole",
22+
"Principal": {
23+
"Service": "ec2.amazonaws.com"
24+
},
25+
"Effect": "Allow"
26+
}
27+
]
28+
}
29+
EOF
30+
31+
tags = {
32+
tag-key = "my-test-instance-role"
33+
}
34+
}
35+
36+
resource "aws_iam_instance_profile" "my-test-profile" {
37+
name = "my-testnew-profile"
38+
role = "${aws_iam_role.my-test-instance-role.name}"
39+
}
40+
41+
resource "aws_iam_role_policy" "my-test-policy" {
42+
name = "my-testnew-policy"
43+
role = "${aws_iam_role.my-test-instance-role.id}"
44+
45+
policy = <<EOF
46+
{
47+
"Version": "2012-10-17",
48+
"Statement": [
49+
{
50+
"Sid": "VisualEditor0",
51+
"Effect": "Allow",
52+
"Action": [
53+
"s3:PutAccountPublicAccessBlock",
54+
"s3:GetAccountPublicAccessBlock",
55+
"s3:ListAllMyBuckets",
56+
"cloudwatch:*",
57+
"s3:HeadBucket"
58+
],
59+
"Resource": "*"
60+
},
61+
{
62+
"Sid": "VisualEditor1",
63+
"Effect": "Allow",
64+
"Action": "s3:*",
65+
"Resource": "*"
66+
}
67+
]
68+
}
69+
EOF
70+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
variable "test_ami" {}
2+
variable "instance_type" {}

backup_solution/main.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}
4+
5+
module "ec2_instance" {
6+
source = "./ec2_instance_s3_role"
7+
test_ami = "ami-01ed306a12b7d1c96"
8+
instance_type = "t2.micro"
9+
}
10+
11+
module "vpc_endpoint" {
12+
source = "./vpc_endpoint"
13+
vpc_id = "vpc-03e162e6b83d51d68"
14+
route_table = "rtb-0af53c788e56135ea"
15+
}
16+
17+
module "s3_bucket_policy" {
18+
source = "./s3_bucket_policy"
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "aws_s3_bucket" "bucket" {
2+
bucket = "terraform-20190327040316452900000001"
3+
acl = "private"
4+
5+
lifecycle_rule {
6+
enabled = true
7+
8+
transition {
9+
days = 30
10+
storage_class = "STANDARD_IA"
11+
}
12+
13+
transition {
14+
days = 60
15+
storage_class = "GLACIER"
16+
}
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
resource "aws_vpc_endpoint" "s3" {
2+
vpc_id = "${var.vpc_id}"
3+
service_name = "com.amazonaws.us-west-2.s3"
4+
5+
policy = <<POLICY
6+
{
7+
"Statement": [
8+
{
9+
"Action": "*",
10+
"Effect": "Allow",
11+
"Resource": "*",
12+
"Principal": "*"
13+
}
14+
]
15+
}
16+
POLICY
17+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
variable "vpc_id" {}
2+
variable "route_table" {}

0 commit comments

Comments
 (0)