Skip to content

Commit 8f309aa

Browse files
author
Joshua Timmons
authored
[CC-3032] EC2 client start up patches (#83)
* EC2 client connection debugging * Run make * Add ssh_key param * Bump to 0.10.0 * Make ssh_keyname required, move intentions to module/ec2-demo-app * Nit: fix output spacing
1 parent c6f23f8 commit 8f309aa

File tree

34 files changed

+284
-252
lines changed

34 files changed

+284
-252
lines changed

examples/hcp-ec2-demo/main.tf

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ resource "hcp_hvn" "main" {
2626

2727
module "aws_hcp_consul" {
2828
source = "hashicorp/hcp-consul/aws"
29-
version = "~> 0.9.4"
29+
version = "~> 0.10.0"
3030

3131
hvn = hcp_hvn.main
3232
vpc_id = module.vpc.vpc_id
@@ -51,23 +51,19 @@ resource "tls_private_key" "ssh" {
5151
}
5252

5353
resource "aws_key_pair" "hcp_ec2" {
54-
count = var.ssh ? 1 : 0
55-
5654
public_key = tls_private_key.ssh.public_key_openssh
5755
key_name = "hcp-ec2-key-${var.cluster_id}"
5856
}
5957

6058
resource "local_file" "ssh_key" {
61-
count = var.ssh ? 1 : 0
62-
6359
content = tls_private_key.ssh.private_key_pem
6460
file_permission = "400"
65-
filename = "${path.module}/${aws_key_pair.hcp_ec2[0].key_name}.pem"
61+
filename = "${path.module}/${aws_key_pair.hcp_ec2.key_name}.pem"
6662
}
6763

6864
module "aws_ec2_consul_client" {
6965
source = "hashicorp/hcp-consul/aws//modules/hcp-ec2-client"
70-
version = "~> 0.9.4"
66+
version = "~> 0.10.0"
7167

7268
allowed_http_cidr_blocks = ["0.0.0.0/0"]
7369
allowed_ssh_cidr_blocks = ["0.0.0.0/0"]
@@ -78,8 +74,20 @@ module "aws_ec2_consul_client" {
7874
install_demo_app = var.install_demo_app
7975
root_token = hcp_consul_cluster_root_token.token.secret_id
8076
security_group_id = module.aws_hcp_consul.security_group_id
81-
ssh_keyname = var.ssh ? aws_key_pair.hcp_ec2[0].key_name : ""
77+
ssh_key = tls_private_key.ssh.private_key_pem
78+
ssh_keyname = aws_key_pair.hcp_ec2.key_name
8279
ssm = var.ssm
8380
subnet_id = module.vpc.public_subnets[0]
8481
vpc_id = module.vpc.vpc_id
8582
}
83+
84+
module "hashicups" {
85+
count = var.install_demo_app ? 1 : 0
86+
87+
source = "hashicorp/hcp-consul/aws/modules/ec2-demo-app"
88+
version = "~> 0.10.0"
89+
90+
depends_on = [
91+
module.aws_ec2_consul_client
92+
]
93+
}

examples/hcp-ec2-demo/output.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ output "hashicups_url" {
2020
}
2121

2222
output "next_steps" {
23-
value = var.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output consul_root_token' to retrieve the root token." : null
23+
value = var.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output -raw consul_root_token' to retrieve the root token." : null
2424
}
2525

2626
output "howto_connect" {
2727
value = <<EOF
2828
${var.install_demo_app ? "The demo app, HashiCups, is installed on a Nomad server we have deployed for you." : ""}
2929
${var.install_demo_app ? "To access Nomad using your local client run the following command:" : ""}
30-
${var.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output consul_root_token)" : ""}
30+
${var.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output -raw consul_root_token)" : ""}
3131
${var.install_demo_app ? "export NOMAD_ADDR=http://${module.aws_ec2_consul_client.public_ip}:8081" : ""}
3232
3333
To access Consul from your local client run:
3434
export CONSUL_HTTP_ADDR="${hcp_consul_cluster.main.consul_public_endpoint_url}"
3535
export CONSUL_HTTP_TOKEN=$(terraform output -raw consul_root_token)
3636
37-
To connect to the ec2 instance deployed:
38-
${var.ssh ? " - To access via SSH run: ssh -i ${abspath(local_file.ssh_key[0].filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}" : ""}
39-
${var.ssm ? " - To access via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${var.vpc_region}" : ""}
37+
To connect to the deployed EC2 instance:
38+
- via SSH run: ssh -i ${abspath(local_file.ssh_key.filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}
39+
${var.ssm ? " - via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${var.vpc_region}" : ""}
4040
EOF
4141
}

examples/hcp-ec2-demo/providers.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,8 @@ provider "consul" {
2525
token = hcp_consul_cluster_root_token.token.secret_id
2626
}
2727

28+
provider "nomad" {
29+
address = "http://${module.aws_ec2_consul_client.public_ip}:8081"
30+
http_auth = "nomad:${hcp_consul_cluster_root_token.token.secret_id}"
31+
}
32+

examples/hcp-ec2-demo/variables.tf

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ variable "tier" {
3434
default = "development"
3535
}
3636

37-
variable "ssh" {
38-
type = bool
39-
description = "Enable or disable SSH access via locally created certificate"
40-
default = true
41-
}
42-
4337
variable "ssm" {
4438
type = bool
4539
description = "Whether to enable SSM on the EC2 host"

examples/hcp-ecs-demo/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ resource "hcp_hvn" "main" {
2828

2929
module "aws_hcp_consul" {
3030
source = "hashicorp/hcp-consul/aws"
31-
version = "~> 0.9.4"
31+
version = "~> 0.10.0"
3232

3333
hvn = hcp_hvn.main
3434
vpc_id = module.vpc.vpc_id
@@ -49,7 +49,7 @@ resource "hcp_consul_cluster_root_token" "token" {
4949

5050
module "aws_ecs_cluster" {
5151
source = "hashicorp/hcp-consul/aws//modules/hcp-ecs-client"
52-
version = "~> 0.9.4"
52+
version = "~> 0.10.0"
5353

5454
allowed_http_cidr_blocks = ["0.0.0.0/0"]
5555
allowed_ssh_cidr_blocks = ["0.0.0.0/0"]

examples/hcp-ecs-demo/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ output "hashicups_url" {
1616
}
1717

1818
output "next_steps" {
19-
value = "HashiCups Application will be ready in ~2 minutes. Use 'terraform output consul_root_token' to retrieve the root token."
19+
value = "HashiCups Application will be ready in ~2 minutes. Use 'terraform output -raw consul_root_token' to retrieve the root token."
2020
}

examples/hcp-eks-demo/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resource "hcp_hvn" "main" {
6565
# Note: Uncomment the below module to setup peering for connecting to a private HCP Consul cluster
6666
# module "aws_hcp_consul" {
6767
# source = "hashicorp/hcp-consul/aws"
68-
# version = "~> 0.9.4"
68+
# version = "~> 0.10.0"
6969
#
7070
# hvn = hcp_hvn.main
7171
# vpc_id = module.vpc.vpc_id
@@ -88,7 +88,7 @@ resource "hcp_consul_cluster_root_token" "token" {
8888

8989
module "eks_consul_client" {
9090
source = "hashicorp/hcp-consul/aws//modules/hcp-eks-client"
91-
version = "~> 0.9.4"
91+
version = "~> 0.10.0"
9292

9393
boostrap_acl_token = hcp_consul_cluster_root_token.token.secret_id
9494
cluster_id = hcp_consul_cluster.main.cluster_id
@@ -107,7 +107,7 @@ module "eks_consul_client" {
107107
module "demo_app" {
108108
count = var.install_demo_app ? 1 : 0
109109
source = "hashicorp/hcp-consul/aws//modules/k8s-demo-app"
110-
version = "~> 0.9.4"
110+
version = "~> 0.10.0"
111111

112112
depends_on = [module.eks_consul_client]
113113
}

examples/hcp-eks-demo/output.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ output "hashicups_url" {
2424
}
2525

2626
output "next_steps" {
27-
value = "HashiCups Application will be ready in ~2 minutes. Use 'terraform output consul_root_token' to retrieve the root token."
27+
value = "HashiCups Application will be ready in ~2 minutes. Use 'terraform output -raw consul_root_token' to retrieve the root token."
2828
}
2929

3030
output "howto_connect" {

hcp-ui-templates/ec2-existing-vpc/main.tf

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ locals {
77
vpc_id = "{{ .VPCID }}"
88
public_route_table_id = "{{ .PublicRouteTableID }}"
99
public_subnet1 = "{{ .PublicSubnet1 }}"
10-
ssh = true
1110
ssm = true
1211
}
1312

@@ -35,6 +34,11 @@ provider "consul" {
3534
token = hcp_consul_cluster_root_token.token.secret_id
3635
}
3736

37+
provider "nomad" {
38+
address = "http://${module.aws_ec2_consul_client.public_ip}:8081"
39+
http_auth = "nomad:${hcp_consul_cluster_root_token.token.secret_id}"
40+
}
41+
3842

3943
resource "hcp_hvn" "main" {
4044
hvn_id = local.hvn_id
@@ -45,7 +49,7 @@ resource "hcp_hvn" "main" {
4549

4650
module "aws_hcp_consul" {
4751
source = "hashicorp/hcp-consul/aws"
48-
version = "~> 0.9.4"
52+
version = "~> 0.10.0"
4953

5054
hvn = hcp_hvn.main
5155
vpc_id = local.vpc_id
@@ -70,23 +74,19 @@ resource "tls_private_key" "ssh" {
7074
}
7175

7276
resource "aws_key_pair" "hcp_ec2" {
73-
count = local.ssh ? 1 : 0
74-
7577
public_key = tls_private_key.ssh.public_key_openssh
7678
key_name = "hcp-ec2-key-${local.cluster_id}"
7779
}
7880

7981
resource "local_file" "ssh_key" {
80-
count = local.ssh ? 1 : 0
81-
8282
content = tls_private_key.ssh.private_key_pem
8383
file_permission = "400"
84-
filename = "${path.module}/${aws_key_pair.hcp_ec2[0].key_name}.pem"
84+
filename = "${path.module}/${aws_key_pair.hcp_ec2.key_name}.pem"
8585
}
8686

8787
module "aws_ec2_consul_client" {
8888
source = "hashicorp/hcp-consul/aws//modules/hcp-ec2-client"
89-
version = "~> 0.9.4"
89+
version = "~> 0.10.0"
9090

9191
allowed_http_cidr_blocks = ["0.0.0.0/0"]
9292
allowed_ssh_cidr_blocks = ["0.0.0.0/0"]
@@ -97,11 +97,23 @@ module "aws_ec2_consul_client" {
9797
install_demo_app = local.install_demo_app
9898
root_token = hcp_consul_cluster_root_token.token.secret_id
9999
security_group_id = module.aws_hcp_consul.security_group_id
100-
ssh_keyname = local.ssh ? aws_key_pair.hcp_ec2[0].key_name : ""
100+
ssh_key = tls_private_key.ssh.private_key_pem
101+
ssh_keyname = aws_key_pair.hcp_ec2.key_name
101102
ssm = local.ssm
102103
subnet_id = local.public_subnet1
103104
vpc_id = local.vpc_id
104105
}
106+
107+
module "hashicups" {
108+
count = local.install_demo_app ? 1 : 0
109+
110+
source = "hashicorp/hcp-consul/aws/modules/ec2-demo-app"
111+
version = "~> 0.10.0"
112+
113+
depends_on = [
114+
module.aws_ec2_consul_client
115+
]
116+
}
105117
output "consul_root_token" {
106118
value = hcp_consul_cluster_root_token.token.secret_id
107119
sensitive = true
@@ -124,22 +136,22 @@ output "hashicups_url" {
124136
}
125137

126138
output "next_steps" {
127-
value = local.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output consul_root_token' to retrieve the root token." : null
139+
value = local.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output -raw consul_root_token' to retrieve the root token." : null
128140
}
129141

130142
output "howto_connect" {
131143
value = <<EOF
132144
${local.install_demo_app ? "The demo app, HashiCups, is installed on a Nomad server we have deployed for you." : ""}
133145
${local.install_demo_app ? "To access Nomad using your local client run the following command:" : ""}
134-
${local.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output consul_root_token)" : ""}
146+
${local.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output -raw consul_root_token)" : ""}
135147
${local.install_demo_app ? "export NOMAD_ADDR=http://${module.aws_ec2_consul_client.public_ip}:8081" : ""}
136148
137149
To access Consul from your local client run:
138150
export CONSUL_HTTP_ADDR="${hcp_consul_cluster.main.consul_public_endpoint_url}"
139151
export CONSUL_HTTP_TOKEN=$(terraform output -raw consul_root_token)
140152
141-
To connect to the ec2 instance deployed:
142-
${local.ssh ? " - To access via SSH run: ssh -i ${abspath(local_file.ssh_key[0].filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}" : ""}
143-
${local.ssm ? " - To access via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${local.vpc_region}" : ""}
153+
To connect to the deployed EC2 instance:
154+
- via SSH run: ssh -i ${abspath(local_file.ssh_key.filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}
155+
${local.ssm ? " - via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${local.vpc_region}" : ""}
144156
EOF
145157
}

hcp-ui-templates/ec2/main.tf

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ locals {
44
cluster_id = "{{ .ClusterID }}"
55
hvn_id = "{{ .ClusterID }}-hvn"
66
install_demo_app = true
7-
ssh = true
87
ssm = true
98
}
109

@@ -32,6 +31,11 @@ provider "consul" {
3231
token = hcp_consul_cluster_root_token.token.secret_id
3332
}
3433

34+
provider "nomad" {
35+
address = "http://${module.aws_ec2_consul_client.public_ip}:8081"
36+
http_auth = "nomad:${hcp_consul_cluster_root_token.token.secret_id}"
37+
}
38+
3539
data "aws_availability_zones" "available" {
3640
filter {
3741
name = "zone-type"
@@ -60,7 +64,7 @@ resource "hcp_hvn" "main" {
6064

6165
module "aws_hcp_consul" {
6266
source = "hashicorp/hcp-consul/aws"
63-
version = "~> 0.9.4"
67+
version = "~> 0.10.0"
6468

6569
hvn = hcp_hvn.main
6670
vpc_id = module.vpc.vpc_id
@@ -85,23 +89,19 @@ resource "tls_private_key" "ssh" {
8589
}
8690

8791
resource "aws_key_pair" "hcp_ec2" {
88-
count = local.ssh ? 1 : 0
89-
9092
public_key = tls_private_key.ssh.public_key_openssh
9193
key_name = "hcp-ec2-key-${local.cluster_id}"
9294
}
9395

9496
resource "local_file" "ssh_key" {
95-
count = local.ssh ? 1 : 0
96-
9797
content = tls_private_key.ssh.private_key_pem
9898
file_permission = "400"
99-
filename = "${path.module}/${aws_key_pair.hcp_ec2[0].key_name}.pem"
99+
filename = "${path.module}/${aws_key_pair.hcp_ec2.key_name}.pem"
100100
}
101101

102102
module "aws_ec2_consul_client" {
103103
source = "hashicorp/hcp-consul/aws//modules/hcp-ec2-client"
104-
version = "~> 0.9.4"
104+
version = "~> 0.10.0"
105105

106106
allowed_http_cidr_blocks = ["0.0.0.0/0"]
107107
allowed_ssh_cidr_blocks = ["0.0.0.0/0"]
@@ -112,11 +112,23 @@ module "aws_ec2_consul_client" {
112112
install_demo_app = local.install_demo_app
113113
root_token = hcp_consul_cluster_root_token.token.secret_id
114114
security_group_id = module.aws_hcp_consul.security_group_id
115-
ssh_keyname = local.ssh ? aws_key_pair.hcp_ec2[0].key_name : ""
115+
ssh_key = tls_private_key.ssh.private_key_pem
116+
ssh_keyname = aws_key_pair.hcp_ec2.key_name
116117
ssm = local.ssm
117118
subnet_id = module.vpc.public_subnets[0]
118119
vpc_id = module.vpc.vpc_id
119120
}
121+
122+
module "hashicups" {
123+
count = local.install_demo_app ? 1 : 0
124+
125+
source = "hashicorp/hcp-consul/aws/modules/ec2-demo-app"
126+
version = "~> 0.10.0"
127+
128+
depends_on = [
129+
module.aws_ec2_consul_client
130+
]
131+
}
120132
output "consul_root_token" {
121133
value = hcp_consul_cluster_root_token.token.secret_id
122134
sensitive = true
@@ -139,22 +151,22 @@ output "hashicups_url" {
139151
}
140152

141153
output "next_steps" {
142-
value = local.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output consul_root_token' to retrieve the root token." : null
154+
value = local.install_demo_app ? "HashiCups Application will be ready in ~2 minutes. Use 'terraform output -raw consul_root_token' to retrieve the root token." : null
143155
}
144156

145157
output "howto_connect" {
146158
value = <<EOF
147159
${local.install_demo_app ? "The demo app, HashiCups, is installed on a Nomad server we have deployed for you." : ""}
148160
${local.install_demo_app ? "To access Nomad using your local client run the following command:" : ""}
149-
${local.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output consul_root_token)" : ""}
161+
${local.install_demo_app ? "export NOMAD_HTTP_AUTH=nomad:$(terraform output -raw consul_root_token)" : ""}
150162
${local.install_demo_app ? "export NOMAD_ADDR=http://${module.aws_ec2_consul_client.public_ip}:8081" : ""}
151163
152164
To access Consul from your local client run:
153165
export CONSUL_HTTP_ADDR="${hcp_consul_cluster.main.consul_public_endpoint_url}"
154166
export CONSUL_HTTP_TOKEN=$(terraform output -raw consul_root_token)
155167
156-
To connect to the ec2 instance deployed:
157-
${local.ssh ? " - To access via SSH run: ssh -i ${abspath(local_file.ssh_key[0].filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}" : ""}
158-
${local.ssm ? " - To access via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${local.vpc_region}" : ""}
168+
To connect to the deployed EC2 instance:
169+
- via SSH run: ssh -i ${abspath(local_file.ssh_key.filename)} ubuntu@${module.aws_ec2_consul_client.public_ip}
170+
${local.ssm ? " - via SSM run: aws ssm start-session --target ${module.aws_ec2_consul_client.host_id} --region ${local.vpc_region}" : ""}
159171
EOF
160172
}

0 commit comments

Comments
 (0)