Skip to content

Commit

Permalink
Terraform 0.12 (#20)
Browse files Browse the repository at this point in the history
* Terraform 0.12
  • Loading branch information
wardviaene committed Oct 6, 2019
1 parent 9e31795 commit 5d9eeb6
Show file tree
Hide file tree
Showing 201 changed files with 2,567 additions and 2,045 deletions.
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,10 @@
* These files are part of my Udemy course about Terraform
* Course URL: https://www.udemy.com/learn-devops-infrastructure-automation-with-terraform/?couponCode=TERRAFORM_GIT

# Compatibility

* This is the >=terraform-0.12 branch. For compatibility with older versions, use the terraform-0.11 branch.

# Demo overview
Demo Directory | Description
------------ | -------------
Expand Down
3 changes: 2 additions & 1 deletion demo-1/instance.tf
@@ -1,4 +1,5 @@
resource "aws_instance" "example" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
ami = var.AMIS[var.AWS_REGION]
instance_type = "t2.micro"
}

6 changes: 3 additions & 3 deletions demo-1/provider.tf
@@ -1,6 +1,6 @@
provider "aws" {
access_key = "${var.AWS_ACCESS_KEY}"
secret_key = "${var.AWS_SECRET_KEY}"
region = "${var.AWS_REGION}"
access_key = var.AWS_ACCESS_KEY
secret_key = var.AWS_SECRET_KEY
region = var.AWS_REGION
}

12 changes: 9 additions & 3 deletions demo-1/vars.tf
@@ -1,13 +1,19 @@
variable "AWS_ACCESS_KEY" {}
variable "AWS_SECRET_KEY" {}
variable "AWS_ACCESS_KEY" {
}

variable "AWS_SECRET_KEY" {
}

variable "AWS_REGION" {
default = "eu-west-1"
}

variable "AMIS" {
type = "map"
type = map(string)
default = {
us-east-1 = "ami-13be557e"
us-west-2 = "ami-06b94666"
eu-west-1 = "ami-0d729a60"
}
}

4 changes: 4 additions & 0 deletions demo-1/versions.tf
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}
23 changes: 12 additions & 11 deletions demo-10/cloudinit.tf
@@ -1,29 +1,30 @@
data "template_file" "init-script" {
template = "${file("scripts/init.cfg")}"
vars {
REGION = "${var.AWS_REGION}"
template = file("scripts/init.cfg")
vars = {
REGION = var.AWS_REGION
}
}

data "template_file" "shell-script" {
template = "${file("scripts/volumes.sh")}"
vars {
DEVICE = "${var.INSTANCE_DEVICE_NAME}"
template = file("scripts/volumes.sh")
vars = {
DEVICE = var.INSTANCE_DEVICE_NAME
}
}
data "template_cloudinit_config" "cloudinit-example" {

gzip = false
data "template_cloudinit_config" "cloudinit-example" {
gzip = false
base64_encode = false

part {
filename = "init.cfg"
content_type = "text/cloud-config"
content = "${data.template_file.init-script.rendered}"
content = data.template_file.init-script.rendered
}

part {
content_type = "text/x-shellscript"
content = "${data.template_file.shell-script.rendered}"
content = data.template_file.shell-script.rendered
}

}

29 changes: 14 additions & 15 deletions demo-10/instance.tf
@@ -1,33 +1,32 @@
resource "aws_instance" "example" {
ami = "${lookup(var.AMIS, var.AWS_REGION)}"
ami = var.AMIS[var.AWS_REGION]
instance_type = "t2.micro"

# the VPC subnet
subnet_id = "${aws_subnet.main-public-1.id}"
subnet_id = aws_subnet.main-public-1.id

# the security group
vpc_security_group_ids = ["${aws_security_group.allow-ssh.id}"]
vpc_security_group_ids = [aws_security_group.allow-ssh.id]

# the public SSH key
key_name = "${aws_key_pair.mykeypair.key_name}"
key_name = aws_key_pair.mykeypair.key_name

# user data
user_data = "${data.template_cloudinit_config.cloudinit-example.rendered}"

user_data = data.template_cloudinit_config.cloudinit-example.rendered
}

resource "aws_ebs_volume" "ebs-volume-1" {
availability_zone = "eu-west-1a"
size = 20
type = "gp2"
tags {
Name = "extra volume data"
}
availability_zone = "eu-west-1a"
size = 20
type = "gp2"
tags = {
Name = "extra volume data"
}
}

resource "aws_volume_attachment" "ebs-volume-1-attachment" {
device_name = "${var.INSTANCE_DEVICE_NAME}"
volume_id = "${aws_ebs_volume.ebs-volume-1.id}"
instance_id = "${aws_instance.example.id}"
device_name = var.INSTANCE_DEVICE_NAME
volume_id = aws_ebs_volume.ebs-volume-1.id
instance_id = aws_instance.example.id
}

5 changes: 3 additions & 2 deletions demo-10/key.tf
@@ -1,4 +1,5 @@
resource "aws_key_pair" "mykeypair" {
key_name = "mykeypair"
public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
key_name = "mykeypair"
public_key = file(var.PATH_TO_PUBLIC_KEY)
}

5 changes: 3 additions & 2 deletions demo-10/provider.tf
@@ -1,3 +1,4 @@
provider "aws" {
region = "${var.AWS_REGION}"
provider "aws" {
region = var.AWS_REGION
}

25 changes: 13 additions & 12 deletions demo-10/securitygroup.tf
@@ -1,21 +1,22 @@
resource "aws_security_group" "allow-ssh" {
vpc_id = "${aws_vpc.main.id}"
name = "allow-ssh"
vpc_id = aws_vpc.main.id
name = "allow-ssh"
description = "security group that allows ssh and all egress traffic"
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}

ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "allow-ssh"
}
}

7 changes: 6 additions & 1 deletion demo-10/vars.tf
@@ -1,20 +1,25 @@
variable "AWS_REGION" {
default = "eu-west-1"
}

variable "PATH_TO_PRIVATE_KEY" {
default = "mykey"
}

variable "PATH_TO_PUBLIC_KEY" {
default = "mykey.pub"
}

variable "AMIS" {
type = "map"
type = map(string)
default = {
us-east-1 = "ami-13be557e"
us-west-2 = "ami-06b94666"
eu-west-1 = "ami-844e0bf7"
}
}

variable "INSTANCE_DEVICE_NAME" {
default = "/dev/xvdh"
}

4 changes: 4 additions & 0 deletions demo-10/versions.tf
@@ -0,0 +1,4 @@

terraform {
required_version = ">= 0.12"
}

0 comments on commit 5d9eeb6

Please sign in to comment.