Skip to content

Commit 0c1e7db

Browse files
committed
Refactor to work with Terraform Enterprise
Use `public_key` (as contents) instead of reading from disk. Use AWS credentials from environment variables.
1 parent b4fb90f commit 0c1e7db

File tree

7 files changed

+19
-42
lines changed

7 files changed

+19
-42
lines changed

main.tf

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@ terraform {
33
}
44

55
provider "aws" {
6-
version = "~> 1.5"
7-
access_key = "${var.access_key}"
8-
secret_key = "${var.secret_key}"
9-
region = "${var.region}"
6+
version = "~> 1.5"
107
}
118

129
module "server" {
1310
source = "./server"
1411

15-
num_webs = "${var.num_webs}"
16-
identity = "${var.identity}"
17-
ami = "${var.ami}"
18-
ingress_cidr = "${var.ingress_cidr}"
19-
public_key_path = "${var.public_key_path}"
20-
private_key_path = "${var.private_key_path}"
12+
num_webs = "${var.num_webs}"
13+
identity = "${var.identity}"
14+
ami = "${var.ami}"
15+
ingress_cidr = "${var.ingress_cidr}"
16+
public_key = "${var.public_key}"
17+
private_key = "${var.private_key}"
2118
}

outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
output "public_ip" {
32
value = "${module.server.public_ip}"
43
}

server/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
resource "aws_key_pair" "default" {
22
key_name = "${var.identity}-key"
3-
public_key = "${file("${var.public_key_path}")}"
3+
public_key = "${var.public_key}"
44
}
55

66
resource "aws_security_group" "default" {
@@ -50,7 +50,7 @@ resource "aws_instance" "web" {
5050

5151
connection {
5252
user = "ubuntu"
53-
private_key = "${file("${var.private_key_path}")}"
53+
private_key = "${var.private_key}"
5454
}
5555

5656
provisioner "file" {

server/outputs.tf

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
output "public_ip" {
32
value = ["${aws_instance.web.*.public_ip}"]
43
}

server/variables.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
variable "ami" {
32
description = "Base machine image for running this server"
43
}
@@ -16,11 +15,10 @@ variable "ingress_cidr" {
1615
description = "IP address block from which connections to this instance will be made"
1716
}
1817

19-
variable "public_key_path" {
20-
description = "Path on disk to the public key used to connect to this instance"
18+
variable "public_key" {
19+
description = "Contents of the public key used to connect to this instance"
2120
}
2221

23-
variable "private_key_path" {
24-
description = "Path on disk to the private key used to connect to this instance"
22+
variable "private_key" {
23+
description = "Contents of the private key used to connect to this instance"
2524
}
26-

terraform.tfvars.example

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
access_key=""
2-
secret_key=""
31
identity="demo-wallaby"
4-
region="us-west-2"
52
ingress_cidr="0.0.0.0/0"
3+
public_key="AAAA"
4+
private_key="AAAA"

variables.tf

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,4 @@
11

2-
variable "access_key" {
3-
description = "The AWS access key used to provision resources"
4-
}
5-
6-
variable "secret_key" {
7-
description = "The AWS secret key used to provision resources"
8-
}
9-
10-
variable "region" {
11-
description = "The AWS region in which to provision resources"
12-
default = "us-west-2"
13-
}
14-
152
variable "identity" {
163
description = "A unique name for your resources"
174
}
@@ -26,14 +13,12 @@ variable "ingress_cidr" {
2613
description = "IP block from which connections to this instance will be made"
2714
}
2815

29-
variable "public_key_path" {
30-
description = "Path on disk to the public key used to connect to this instance"
31-
default = "~/.ssh/id_rsa.pub"
16+
variable "public_key" {
17+
description = "Contents of the public key used to connect to this instance"
3218
}
3319

34-
variable "private_key_path" {
35-
description = "Path on disk to the private key used to connect to this instance"
36-
default = "~/.ssh/id_rsa"
20+
variable "private_key" {
21+
description = "Contents of the private key used to connect to this instance"
3722
}
3823

3924
variable "num_webs" {

0 commit comments

Comments
 (0)