Skip to content

Commit

Permalink
adds barebones terraform example (#857)
Browse files Browse the repository at this point in the history
  • Loading branch information
UncleGedd authored Oct 6, 2022
1 parent 8784efe commit 47c8994
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
17 changes: 17 additions & 0 deletions examples/terraform/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Terraform
This example demonstrates how to use Zarf to execute Terraform code to create an S3 bucket.

### Assumptions/Prereqs
- The binaries in the Zarf package are for an M1 Mac only and will need to be changed for other architectures
- The S3 bucket name will likely need to be changed as S3 bucket names must be globally unique
- Your machine has a connection to an AWS instance and is authenticated with an AWS account

### Steps

No K8s cluster is necessary, just build with the package with:

`zarf package create`

And execute with:

`zarf package deploy <package_name>`
17 changes: 17 additions & 0 deletions examples/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.33.0"
}
}
}

provider "aws" {
region = "us-east-1"
}

resource "aws_s3_bucket" "example-bucket" {
# note this bucket name will need to be changed because s3 buckets must be globally unique
bucket = "unclegedds-example-bucket"
}
32 changes: 32 additions & 0 deletions examples/terraform/zarf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
kind: ZarfPackageConfig
metadata:
name: "terraform"
description: "Run terraform/terragrunt code"

components:
- name: download-terraform
required: true
scripts:
after:
- "rm -f terraform"
- "./zarf tools archiver decompress tmp/terraform_1.3.1_darwin_arm64.zip ."
- "./zarf tools archiver decompress tmp/terraform-provider-aws_4.33.0_darwin_arm64.zip ./tf-plugins/registry.terraform.io/hashicorp/aws/4.33.0/darwin_arm64"
- "rm -rf tmp"
files:
# terraform code
- source: main.tf
target: main.tf
# mac m1 terraform aws provider binary
- source: https://releases.hashicorp.com/terraform-provider-aws/4.33.0/terraform-provider-aws_4.33.0_darwin_arm64.zip
target: tmp/terraform-provider-aws_4.33.0_darwin_arm64.zip
# mac m1 terraform binary
- source: https://releases.hashicorp.com/terraform/1.3.1/terraform_1.3.1_darwin_arm64.zip
target: tmp/terraform_1.3.1_darwin_arm64.zip

- name: execute-terraform
scripts:
timeoutSeconds: 60
showOutput: true
before:
- "./terraform init -plugin-dir=tf-plugins"
- "./terraform apply -auto-approve"

0 comments on commit 47c8994

Please sign in to comment.