Skip to content

Commit 0f149d5

Browse files
committedFeb 18, 2019
migrate to s3 backend with locking with dynamodb
1 parent 0216273 commit 0f149d5

11 files changed

+102
-313
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.terraform
22
*.swp
33
*.backup
4+
*.out
5+
*.log

‎backend.tf

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
terraform {
3+
backend "s3" {
4+
encrypt = false
5+
# bucket = "homework.gcloud.training"
6+
bucket = "homework-zf-dot-com"
7+
region = "us-west-2"
8+
profile = "default"
9+
key = "app/terraform.tfstate"
10+
# dynamodb_table = "homework.gcloud.training"
11+
dynamodb_table = "terraform-lock"
12+
13+
}
14+
# depends_on = ["homework-terraform-state-storage-s3j"]
15+
}
16+
17+

‎main.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!flask/bin/python
2-
#import boto.ec2
32
from dateutil.parser import *
43
import subprocess
54
import datetime
@@ -35,5 +34,4 @@ def get_loader_io():
3534
return "loaderio-14cd55e65597953829f714fdd2ba66b1", 200
3635

3736
if __name__ == '__main__':
38-
# app.run(debug=True,host='0.0.0.0', port=8000)
3937
app.run(debug=True,host='0.0.0.0', port=80)

‎lc.tf ‎main.tf

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
provider "aws" {
2-
region = "us-west-2"
3-
}
4-
51
data "aws_ami" "amzn2_lc" {
62
most_recent = true
73

84
filter {
95
name = "name"
106
# values = ["amzn2-ami-hvm-2.0.*-x86_64-gp2"]
11-
values = ["packer-linux-aws-demo-*"]
7+
# values = ["packer-linux-aws-demo-*"]
8+
values = ["packer-linux-homework-demo-*"]
129
}
1310

1411
filter {
@@ -36,9 +33,9 @@ resource "aws_launch_configuration" "as_conf" {
3633
resource "aws_autoscaling_group" "homework_asg" {
3734
name = "homework_asg"
3835
launch_configuration = "${aws_launch_configuration.as_conf.name}"
39-
desired_capacity = 6
36+
desired_capacity = 1
4037
min_size = 1
41-
max_size = 6
38+
max_size = 1
4239
vpc_zone_identifier = ["subnet-e9afac9d","subnet-9632d1f3","subnet-dc3b169a"]
4340
# load_balancers = ["homework-alb"]
4441
# target_group_arns = [""]

‎plan.out

-10.8 KB
Binary file not shown.

‎providers.tf

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
profile = "default"
4+
version = "~> 1.59"
5+
}

‎s3/plan.out

5.05 KB
Binary file not shown.

‎s3/providers.tf

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "aws" {
2+
region = "us-west-2"
3+
}

‎s3/s3.tf

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# terraform state file setup
2+
# create an S3 bucket to store the state file in
3+
resource "aws_s3_bucket" "homework-terraform-state-storage-s3" {
4+
# bucket = "homework.gcloud.training"
5+
bucket = "homework-zf-dot-com"
6+
7+
versioning {
8+
enabled = true
9+
}
10+
11+
lifecycle {
12+
prevent_destroy = false
13+
}
14+
15+
tags {
16+
Name = "S3 Remote Terraform State Store"
17+
}
18+
}

‎s3/terraform.tfstate

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"version": 3,
3+
"terraform_version": "0.11.11",
4+
"serial": 6,
5+
"lineage": "68b9a351-72c2-7cf1-178e-a62e49e386a2",
6+
"modules": [
7+
{
8+
"path": [
9+
"root"
10+
],
11+
"outputs": {},
12+
"resources": {
13+
"aws_s3_bucket.homework-terraform-state-storage-s3": {
14+
"type": "aws_s3_bucket",
15+
"depends_on": [],
16+
"primary": {
17+
"id": "homework-zf-dot-com",
18+
"attributes": {
19+
"acceleration_status": "",
20+
"acl": "private",
21+
"arn": "arn:aws:s3:::homework-zf-dot-com",
22+
"bucket": "homework-zf-dot-com",
23+
"bucket_domain_name": "homework-zf-dot-com.s3.amazonaws.com",
24+
"bucket_regional_domain_name": "homework-zf-dot-com.s3.us-west-2.amazonaws.com",
25+
"cors_rule.#": "0",
26+
"force_destroy": "false",
27+
"hosted_zone_id": "Z3BJ6K6RIION7M",
28+
"id": "homework-zf-dot-com",
29+
"lifecycle_rule.#": "0",
30+
"logging.#": "0",
31+
"object_lock_configuration.#": "0",
32+
"region": "us-west-2",
33+
"replication_configuration.#": "0",
34+
"request_payer": "BucketOwner",
35+
"server_side_encryption_configuration.#": "0",
36+
"tags.%": "1",
37+
"tags.Name": "S3 Remote Terraform State Store",
38+
"versioning.#": "1",
39+
"versioning.0.enabled": "true",
40+
"versioning.0.mfa_delete": "false",
41+
"website.#": "0"
42+
},
43+
"meta": {},
44+
"tainted": false
45+
},
46+
"deposed": [],
47+
"provider": "provider.aws"
48+
}
49+
},
50+
"depends_on": []
51+
}
52+
]
53+
}

‎terraform.tfstate

-304
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.