Skip to content

Commit eb0f5b8

Browse files
committed
Initial commit
0 parents  commit eb0f5b8

File tree

4 files changed

+94
-0
lines changed

4 files changed

+94
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Terraform Intro
2+
3+
This repo has many branches. Each branch represent an incremental
4+
terraform state. You can go through each branch an apply your changes
5+
(`terraform apply`) to see how that works
6+
7+
## Usage
8+
9+
We are going to use AWS for this. So you need to provide your access
10+
keys as environment variables. Check `env.sample` to see what variables
11+
are required.
12+
13+
If you don't have an AWS account, you can create one (A credit card is
14+
required) at [aws.amazon.com](https://aws.amazon.com). This examples works
15+
under their free-tier plan. So it shouldn't cost you anything.
16+
17+
Once you have your access keys for AWS, run this:
18+
19+
```bash
20+
cp env.sample .env
21+
# replace your AWS access keys in the .env file you just created
22+
source .env
23+
```
24+
25+
### Installing terraform
26+
27+
If you are on OSX, you should have homebrew installed (if not installed
28+
it, you have been missing one of the best tools for devs in OSX)
29+
30+
`brew install terraform`
31+
32+
### Branches
33+
34+
Once you reach this point, you should be able to run terraform commands
35+
without problems.
36+
37+
In each branch you should run first `terraform plan` to see the changes,
38+
and then `terraform apply` to apply the changes.
39+
40+
Once you are done running the examples, you can run `terraform destroy`
41+
to teardown the resources you created
42+
43+
#### master
44+
* Creating a basic EC2 instance
45+
46+
#### step2
47+
* Adding an ELB to that instance
48+
49+
#### step3
50+
* Exposing instance type as a variable
51+
52+
#### step4
53+
* Moving everything to a module
54+
55+
#### step5
56+
* Adding documentation with [terraform-docs](https://github.com/segmentio/terraform-docs)

env.sample

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export AWS_ACCESS_KEY_ID=
2+
export AWS_SECRET_ACCESS_KEY=
3+
export AWS_DEFAULT_REGION=us-east-1

main.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Resources
3+
*/
4+
data "aws_ami" "ubuntu" {
5+
most_recent = true
6+
7+
filter {
8+
name = "name"
9+
values = ["ubuntu/images/hvm-ssd/ubuntu-trusty-14.04-amd64-server-*"]
10+
}
11+
12+
filter {
13+
name = "virtualization-type"
14+
values = ["hvm"]
15+
}
16+
17+
owners = ["099720109477"] # Canonical
18+
}
19+
20+
resource "aws_instance" "example" {
21+
ami = "${data.aws_ami.ubuntu.id}"
22+
instance_type = "t2.nano"
23+
24+
tags {
25+
Name = "Terraform Intro"
26+
}
27+
}
28+
29+
/*
30+
* Outputs
31+
*/
32+
output "dns" {
33+
value = "${aws_instance.example.public_dns}"
34+
}

0 commit comments

Comments
 (0)