Skip to content

Commit 76fe1e6

Browse files
author
Brian Peterson
committed
upgraded to tf 0.12+ version
1 parent b39518d commit 76fe1e6

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

terraform.tf

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,15 @@ variable "az" {
1717
}
1818

1919
locals {
20-
azs = { "a" : 0, "b" : 1, "c" : 2, "d" : 3, "e" : 4, "f" : 5, "g" : 6 }
20+
azs = {
21+
a = 0
22+
b = 1
23+
c = 2
24+
d = 3
25+
e = 4
26+
f = 5
27+
g = 6
28+
}
2129
}
2230

2331
variable "os" {
@@ -42,7 +50,7 @@ variable "allowed_cidr" {
4250

4351
# Maps
4452
variable "ami_names" {
45-
type = "map"
53+
type = map(string)
4654

4755
default = {
4856
ubuntu = "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server*"
@@ -57,7 +65,7 @@ variable "custom_ami" {
5765
}
5866

5967
variable "os_users" {
60-
type = "map"
68+
type = map(string)
6169

6270
default = {
6371
ubuntu = "ubuntu"
@@ -73,19 +81,28 @@ variable "custom_user" {
7381

7482
# Providers
7583
provider "aws" {
76-
profile = "${var.profile}"
77-
region = "${var.region}"
84+
profile = var.profile
85+
region = var.region
7886
}
7987

8088
# Data lookups
8189
data "aws_ami" "ami" {
8290
most_recent = true
91+
8392
# self for own account, conical for ubuntu, or amazon for aws linux
8493
owners = ["self", "099720109477", "amazon"]
8594

8695
filter {
87-
name = "name"
88-
values = ["${lookup(var.ami_names, var.os, var.custom_ami)}"]
96+
name = "name"
97+
# TF-UPGRADE-TODO: In Terraform v0.10 and earlier, it was sometimes necessary to
98+
# force an interpolation expression to be interpreted as a list by wrapping it
99+
# in an extra set of list brackets. That form was supported for compatibilty in
100+
# v0.11, but is no longer supported in Terraform v0.12.
101+
#
102+
# If the expression in the following list itself returns a list, remove the
103+
# brackets to avoid interpretation as a list of lists. If the expression
104+
# returns a single list item then leave it as-is and remove this TODO comment.
105+
values = [lookup(var.ami_names, var.os, var.custom_ami)]
89106
}
90107
}
91108

@@ -94,42 +111,45 @@ data "aws_vpc" "default" {
94111
}
95112

96113
# All AZs Available in the current region
97-
data "aws_availability_zones" "available" {}
114+
data "aws_availability_zones" "available" {
115+
}
98116

99117
# Resources
100118
resource "aws_instance" "instance" {
101-
ami = "${data.aws_ami.ami.id}"
102-
instance_type = "${var.size}"
103-
availability_zone = "${data.aws_availability_zones.available.names[local.azs[var.az]]}"
104-
security_groups = ["${aws_security_group.sec_grp.name}"]
105-
key_name = "${aws_key_pair.key.key_name}"
119+
ami = data.aws_ami.ami.id
120+
instance_type = var.size
121+
availability_zone = data.aws_availability_zones.available.names[local.azs[var.az]]
122+
security_groups = [aws_security_group.sec_grp.name]
123+
key_name = aws_key_pair.key.key_name
106124
tags = {
107125
Name = "temp_tf_instance"
108126
}
109127
}
110128

111129
resource "aws_key_pair" "key" {
112130
key_name = "ssh-key"
113-
public_key = "${file("${var.keyfile}")}"
131+
public_key = file(var.keyfile)
114132
}
115133

116134
resource "aws_security_group" "sec_grp" {
117135
name_prefix = "ssh-only-sg_"
118136
description = "ssh_only"
119-
vpc_id = "${data.aws_vpc.default.id}"
137+
vpc_id = data.aws_vpc.default.id
120138

121139
ingress {
122140
from_port = 22
123141
to_port = 22
124142
protocol = "tcp"
125-
cidr_blocks = ["${var.allowed_cidr}"]
143+
cidr_blocks = [var.allowed_cidr]
126144
}
127145
}
128146

129147
# outputs
130148
output "instance_id" {
131-
value = "${aws_instance.instance.id}"
149+
value = aws_instance.instance.id
132150
}
151+
133152
output "ssh_command" {
134153
value = "ssh -i ${var.keyfile} ${lookup(var.os_users, var.os, var.custom_user)}@${aws_instance.instance.public_ip}"
135154
}
155+

versions.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
terraform {
3+
required_version = ">= 0.12"
4+
}

0 commit comments

Comments
 (0)