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

Commit

Permalink
Add example for the packer-vpc module.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcgirr committed May 25, 2018
1 parent 6468b82 commit daac984
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
30 changes: 30 additions & 0 deletions examples/terraform-vpc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Hardcoding value of 3 minutes when we check if the plan file is stale
STALE_PLAN_FILE := `find "tf.out" -mmin -3 | grep -q tf.out`

## Check if tf.out is stale (Older than 2 minutes)
check-plan-file:
@if ! ${STALE_PLAN_FILE} ; then \
echo "ERROR: Stale tf.out plan file (older than 3 minutes)!"; \
exit 1; \
fi

## Runs terraform get and terraform init for env
init:
@terraform get
@terraform init

## terraform plan (makes everything)
plan:
@terraform plan -out=tf.out

## terraform apply
apply: check-plan-file
@terraform apply tf.out

# clean up terrform and any other files
clean:
@terraform destroy
@rm -f tf.out
@rm -f terraform.tfvars
@rm -f terraform.*.backup
@rm -f terraform.tfstate
33 changes: 33 additions & 0 deletions examples/terraform-vpc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Example to test the packer-vpc module.

An example to demonstrate the [packer-vpc](https://github.com/fpco/terraform-aws-foundation/tree/master/modules/packer-vpc) module.
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`.


## Using the Example

### Environment creation and deployment

To use this example set up AWS credentials and then run the commands in the
following order:

```
make init
make plan
make apply
```

Or simply run the following:

```
make init && make plan && make apply
```

### Destruction

To destroy the test environment and other resources created by the example run the following command:

```
make clean
```

38 changes: 38 additions & 0 deletions examples/terraform-vpc/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
variable "region" {
default = "us-west-1"
description = "The AWS region to deploy to"
}

provider "aws" {
region = "${var.region}"
}

module "vpc" {
source = "../../modules/packer-vpc"
region = "${var.region}"
}

output "region" {
value = "${var.region}"
description = "region"
}

output "vpc_id" {
value = "${module.vpc.vpc_id}"
description = "VPC ID"
}

output "subnet_id" {
value = "${module.vpc.subnet_id}"
description = "Subnet ID"
}

output "trusty_ami_id" {
value = "${module.vpc.trusty_ami_id}"
description = "ID of latest trusty AMI"
}

output "xenial_ami_id" {
value = "${module.vpc.xenial_ami_id}"
description = "ID of latest xenial AMI"
}

1 comment on commit daac984

@mcgirr
Copy link
Contributor Author

@mcgirr mcgirr commented on daac984 May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit is intended to address issue #95

Please sign in to comment.