Skip to content

Commit 526c637

Browse files
Make paths in e2e/terraform/ directory relative to the module (#24664)
* func: make paths relative * func: make paths relative to the module inside the e2e terraform folder * fix: add license files to gitignore * func: move /etc and update all paths * Uncomment forgotten code * fix: update the path to the tls certificates to be local to the instance
1 parent a9a0f71 commit 526c637

35 files changed

+34
-27
lines changed

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,10 @@ tools/missing/missing
137137

138138
# allow security scanner file
139139
!scan.hcl
140+
141+
# generated variables for upgrade tests
142+
enos.vars.hcl
143+
enos/modules/*/*.tfvars
144+
145+
# local license files
146+
*.hclic

e2e/terraform/compute.tf

+3-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ resource "aws_instance" "client_ubuntu_jammy_amd64" {
3939
}
4040
}
4141

42+
43+
4244
resource "aws_instance" "client_windows_2016_amd64" {
4345
ami = data.aws_ami.windows_2016_amd64[0].image_id
4446
instance_type = var.instance_type
@@ -48,7 +50,7 @@ resource "aws_instance" "client_windows_2016_amd64" {
4850
iam_instance_profile = data.aws_iam_instance_profile.nomad_e2e_cluster.name
4951
availability_zone = var.availability_zone
5052

51-
user_data = file("${path.root}/userdata/windows-2016.ps1")
53+
user_data = file("${path.module}/userdata/windows-2016.ps1")
5254

5355
# Instance tags
5456
tags = {

e2e/terraform/consul-clients.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ resource "local_sensitive_file" "consul_agents_cert" {
4848
resource "random_uuid" "consul_agent_token" {}
4949

5050
resource "local_sensitive_file" "consul_agent_config_file" {
51-
content = templatefile("etc/consul.d/clients.hcl", {
51+
content = templatefile("${path.module}/provision-nomad/etc/consul.d/clients.hcl", {
5252
token = "${random_uuid.consul_agent_token.result}"
5353
autojoin_value = "auto-join-${local.random_name}"
5454
})
@@ -61,7 +61,7 @@ resource "local_sensitive_file" "consul_agent_config_file" {
6161
resource "random_uuid" "consul_token_for_nomad" {}
6262

6363
resource "local_sensitive_file" "nomad_client_config_for_consul" {
64-
content = templatefile("etc/nomad.d/client-consul.hcl", {
64+
content = templatefile("${path.module}/provision-nomad/etc/nomad.d/client-consul.hcl", {
6565
token = "${random_uuid.consul_token_for_nomad.result}"
6666
client_service_name = "client-${local.random_name}"
6767
server_service_name = "server-${local.random_name}"
@@ -71,7 +71,7 @@ resource "local_sensitive_file" "nomad_client_config_for_consul" {
7171
}
7272

7373
resource "local_sensitive_file" "nomad_server_config_for_consul" {
74-
content = templatefile("etc/nomad.d/server-consul.hcl", {
74+
content = templatefile("${path.module}/provision-nomad/etc/nomad.d/server-consul.hcl", {
7575
token = "${random_uuid.consul_token_for_nomad.result}"
7676
client_service_name = "client-${local.random_name}"
7777
server_service_name = "server-${local.random_name}"

e2e/terraform/consul-servers.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ resource "local_sensitive_file" "consul_initial_management_token" {
1515
}
1616

1717
resource "local_sensitive_file" "consul_server_config_file" {
18-
content = templatefile("etc/consul.d/servers.hcl", {
18+
content = templatefile("${path.module}/provision-nomad/etc/consul.d/servers.hcl", {
1919
management_token = "${random_uuid.consul_initial_management_token.result}"
2020
token = "${random_uuid.consul_agent_token.result}"
2121
nomad_token = "${random_uuid.consul_token_for_nomad.result}"
@@ -69,7 +69,7 @@ resource "local_sensitive_file" "consul_server_cert" {
6969

7070
# if consul_license is unset, it'll be a harmless empty license file
7171
resource "local_sensitive_file" "consul_environment" {
72-
content = templatefile("etc/consul.d/.environment", {
72+
content = templatefile("${path.module}/provision-nomad/etc/consul.d/.environment", {
7373
license = var.consul_license
7474
})
7575
filename = "uploads/shared/consul.d/.environment"
@@ -117,7 +117,7 @@ resource "null_resource" "upload_consul_server_configs" {
117117
destination = "/tmp/consul_server.hcl"
118118
}
119119
provisioner "file" {
120-
source = "etc/consul.d/consul-server.service"
120+
source = "${path.module}/provision-nomad/etc/consul.d/consul-server.service"
121121
destination = "/tmp/consul.service"
122122
}
123123
}

e2e/terraform/ecs.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ resource "aws_ecs_cluster" "nomad_rtd_e2e" {
88

99
resource "aws_ecs_task_definition" "nomad_rtd_e2e" {
1010
family = "nomad-rtd-e2e"
11-
container_definitions = file("ecs-task.json")
11+
container_definitions = file("${path.module}/ecs-task.json")
1212

1313
# Don't need a network for e2e tests
1414
network_mode = "awsvpc"

e2e/terraform/hcp_vault.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data "hcp_vault_cluster" "e2e_shared_vault" {
1616
# between concurrent E2E clusters
1717
resource "vault_policy" "nomad" {
1818
name = "${local.random_name}-nomad-server"
19-
policy = templatefile("${path.root}/etc/acls/vault/nomad-policy.hcl", {
19+
policy = templatefile("${path.module}/provision-nomad/etc/acls/vault/nomad-policy.hcl", {
2020
role = "nomad-tasks-${local.random_name}"
2121
})
2222
}
@@ -42,7 +42,7 @@ resource "vault_token_auth_backend_role" "nomad_cluster" {
4242

4343
# Nomad agent configuration for Vault
4444
resource "local_sensitive_file" "nomad_config_for_vault" {
45-
content = templatefile("etc/nomad.d/vault.hcl", {
45+
content = templatefile("${path.module}/provision-nomad/etc/nomad.d/vault.hcl", {
4646
token = vault_token.nomad.client_token
4747
url = data.hcp_vault_cluster.e2e_shared_vault.vault_private_endpoint_url
4848
namespace = var.hcp_vault_namespace

e2e/terraform/nomad-acls.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ resource "null_resource" "bootstrap_nomad_acls" {
2323

2424
data "local_sensitive_file" "nomad_token" {
2525
depends_on = [null_resource.bootstrap_nomad_acls]
26-
filename = "${path.root}/keys/nomad_root_token"
26+
filename = "${path.module}/keys/nomad_root_token"
2727
}
2828

2929
# push the token out to the servers for humans to use.
@@ -36,8 +36,8 @@ locals {
3636
cat <<ENV | sudo tee -a /root/.bashrc
3737
export NOMAD_ADDR=https://localhost:4646
3838
export NOMAD_SKIP_VERIFY=true
39-
export NOMAD_CLIENT_CERT=/etc/nomad.d/tls/agent.crt
40-
export NOMAD_CLIENT_KEY=/etc/nomad.d/tls/agent.key
39+
export NOMAD_CLIENT_CERT="/etc/nomad.d/tls/agent.crt"
40+
export NOMAD_CLIENT_KEY="/etc/nomad.d/tls/agent.key"
4141
export NOMAD_TOKEN=${data.local_sensitive_file.nomad_token.content}
4242
export CONSUL_HTTP_ADDR=https://localhost:8501
4343
export CONSUL_HTTP_TOKEN="${random_uuid.consul_initial_management_token.result}"

e2e/terraform/outputs.tf

+5-6
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,13 @@ output "environment" {
4949
sensitive = true
5050
value = <<EOM
5151
export NOMAD_ADDR=https://${aws_instance.server[0].public_ip}:4646
52-
export NOMAD_CACERT=${abspath(path.root)}/keys/tls_ca.crt
53-
export NOMAD_CLIENT_CERT=${abspath(path.root)}/keys/tls_api_client.crt
54-
export NOMAD_CLIENT_KEY=${abspath(path.root)}/keys/tls_api_client.key
52+
export NOMAD_CACERT=${abspath(path.module)}/keys/tls_ca.crt
53+
export NOMAD_CLIENT_CERT=${abspath(path.module)}/keys/tls_api_client.crt
54+
export NOMAD_CLIENT_KEY=${abspath(path.module)}/keys/tls_api_client.key
5555
export NOMAD_TOKEN=${data.local_sensitive_file.nomad_token.content}
5656
export NOMAD_E2E=1
5757
export CONSUL_HTTP_ADDR=https://${aws_instance.consul_server.public_ip}:8501
5858
export CONSUL_HTTP_TOKEN=${local_sensitive_file.consul_initial_management_token.content}
59-
export CONSUL_CACERT=${abspath(path.root)}/keys/tls_ca.crt
60-
59+
export CONSUL_CACERT=${abspath(path.module)}/keys/tls_ca.crt
6160
EOM
62-
}
61+
}

e2e/terraform/provision-nomad/install-linux.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: BUSL-1.1
33

44
resource "local_sensitive_file" "nomad_systemd_unit_file" {
5-
content = templatefile("etc/nomad.d/nomad-${var.role}.service", {})
5+
content = templatefile("${path.module}/etc/nomad.d/nomad-${var.role}.service", {})
66
filename = "${local.upload_dir}/nomad.d/nomad.service"
77
file_permission = "0600"
88
}

e2e/terraform/provision-nomad/main.tf

+6-7
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
locals {
55
upload_dir = "uploads/${var.instance.public_ip}"
66

7-
indexed_config_path = fileexists("etc/nomad.d/${var.role}-${var.platform}-${var.index}.hcl") ? "etc/nomad.d/${var.role}-${var.platform}-${var.index}.hcl" : "etc/nomad.d/index.hcl"
8-
7+
indexed_config_path = fileexists("${path.module}/etc/nomad.d/${var.role}-${var.platform}-${var.index}.hcl") ? "${path.module}/etc/nomad.d/${var.role}-${var.platform}-${var.index}.hcl" : "${path.module}/etc/nomad.d/index.hcl"
98
}
109

1110
# if nomad_license is unset, it'll be a harmless empty license file
1211
resource "local_sensitive_file" "nomad_environment" {
13-
content = templatefile("etc/nomad.d/.environment", {
12+
content = templatefile("${path.module}/etc/nomad.d/.environment", {
1413
license = var.nomad_license
1514
})
1615
filename = "${local.upload_dir}/nomad.d/.environment"
1716
file_permission = "0600"
1817
}
1918

2019
resource "local_sensitive_file" "nomad_base_config" {
21-
content = templatefile("etc/nomad.d/base.hcl", {
20+
content = templatefile("${path.module}/etc/nomad.d/base.hcl", {
2221
data_dir = var.platform != "windows" ? "/opt/nomad/data" : "C://opt/nomad/data"
2322
})
2423
filename = "${local.upload_dir}/nomad.d/base.hcl"
2524
file_permission = "0600"
2625
}
2726

2827
resource "local_sensitive_file" "nomad_role_config" {
29-
content = templatefile("etc/nomad.d/${var.role}-${var.platform}.hcl", {
28+
content = templatefile("${path.module}/etc/nomad.d/${var.role}-${var.platform}.hcl", {
3029
aws_region = var.aws_region
3130
aws_kms_key_id = var.aws_kms_key_id
3231
})
@@ -41,7 +40,7 @@ resource "local_sensitive_file" "nomad_indexed_config" {
4140
}
4241

4342
resource "local_sensitive_file" "nomad_tls_config" {
44-
content = templatefile("etc/nomad.d/tls.hcl", {})
43+
content = templatefile("${path.module}/etc/nomad.d/tls.hcl", {})
4544
filename = "${local.upload_dir}/nomad.d/tls.hcl"
4645
file_permission = "0600"
4746
}
@@ -75,7 +74,7 @@ resource "null_resource" "upload_consul_configs" {
7574
destination = "/tmp/consul_client.hcl"
7675
}
7776
provisioner "file" {
78-
source = "etc/consul.d/consul.service"
77+
source = "${path.module}/etc/consul.d/consul.service"
7978
destination = "/tmp/consul.service"
8079
}
8180
}

0 commit comments

Comments
 (0)