Skip to content
This repository was archived by the owner on Jul 11, 2023. It is now read-only.

Commit daac984

Browse files
committed
Add example for the packer-vpc module.
1 parent 6468b82 commit daac984

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

examples/terraform-vpc/Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Hardcoding value of 3 minutes when we check if the plan file is stale
2+
STALE_PLAN_FILE := `find "tf.out" -mmin -3 | grep -q tf.out`
3+
4+
## Check if tf.out is stale (Older than 2 minutes)
5+
check-plan-file:
6+
@if ! ${STALE_PLAN_FILE} ; then \
7+
echo "ERROR: Stale tf.out plan file (older than 3 minutes)!"; \
8+
exit 1; \
9+
fi
10+
11+
## Runs terraform get and terraform init for env
12+
init:
13+
@terraform get
14+
@terraform init
15+
16+
## terraform plan (makes everything)
17+
plan:
18+
@terraform plan -out=tf.out
19+
20+
## terraform apply
21+
apply: check-plan-file
22+
@terraform apply tf.out
23+
24+
# clean up terrform and any other files
25+
clean:
26+
@terraform destroy
27+
@rm -f tf.out
28+
@rm -f terraform.tfvars
29+
@rm -f terraform.*.backup
30+
@rm -f terraform.tfstate

examples/terraform-vpc/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Example to test the packer-vpc module.
2+
3+
An example to demonstrate the [packer-vpc](https://github.com/fpco/terraform-aws-foundation/tree/master/modules/packer-vpc) module.
4+
This will use the `packer-vpc` module to create a simple, isolated VPC on AWS which can be dedicated to building AMI's with `packer`.
5+
6+
7+
## Using the Example
8+
9+
### Environment creation and deployment
10+
11+
To use this example set up AWS credentials and then run the commands in the
12+
following order:
13+
14+
```
15+
make init
16+
make plan
17+
make apply
18+
```
19+
20+
Or simply run the following:
21+
22+
```
23+
make init && make plan && make apply
24+
```
25+
26+
### Destruction
27+
28+
To destroy the test environment and other resources created by the example run the following command:
29+
30+
```
31+
make clean
32+
```
33+

examples/terraform-vpc/main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
variable "region" {
2+
default = "us-west-1"
3+
description = "The AWS region to deploy to"
4+
}
5+
6+
provider "aws" {
7+
region = "${var.region}"
8+
}
9+
10+
module "vpc" {
11+
source = "../../modules/packer-vpc"
12+
region = "${var.region}"
13+
}
14+
15+
output "region" {
16+
value = "${var.region}"
17+
description = "region"
18+
}
19+
20+
output "vpc_id" {
21+
value = "${module.vpc.vpc_id}"
22+
description = "VPC ID"
23+
}
24+
25+
output "subnet_id" {
26+
value = "${module.vpc.subnet_id}"
27+
description = "Subnet ID"
28+
}
29+
30+
output "trusty_ami_id" {
31+
value = "${module.vpc.trusty_ami_id}"
32+
description = "ID of latest trusty AMI"
33+
}
34+
35+
output "xenial_ami_id" {
36+
value = "${module.vpc.xenial_ami_id}"
37+
description = "ID of latest xenial AMI"
38+
}

0 commit comments

Comments
 (0)