Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make paths in e2e/terraform/ directory relative to the module #24664

Merged
merged 6 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ tools/missing/missing

# allow security scanner file
!scan.hcl

# generated variables for upgrade tests
enos.vars.hcl
enos/modules/*/*.tfvars

# local license files
*.hclic
8 changes: 5 additions & 3 deletions e2e/terraform/compute.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ resource "aws_instance" "client_ubuntu_jammy_amd64" {
}
}



resource "aws_instance" "client_windows_2016_amd64" {
ami = data.aws_ami.windows_2016_amd64[0].image_id
instance_type = var.instance_type
Expand All @@ -48,7 +50,7 @@ resource "aws_instance" "client_windows_2016_amd64" {
iam_instance_profile = data.aws_iam_instance_profile.nomad_e2e_cluster.name
availability_zone = var.availability_zone

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

# Instance tags
tags = {
Expand Down Expand Up @@ -98,10 +100,10 @@ data "aws_ami" "ubuntu_jammy_amd64" {
values = ["Ubuntu"]
}

filter {
/* filter {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This filter was removed for testing, but should we restore it for the merge to main?

Copy link
Member Author

@Juanadelacuesta Juanadelacuesta Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right, my bad, they are commented for local testing

name = "tag:BuilderSha"
values = [data.external.packer_sha.result["sha"]]
}
} */
}

data "aws_ami" "windows_2016_amd64" {
Expand Down
6 changes: 3 additions & 3 deletions e2e/terraform/consul-clients.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ resource "local_sensitive_file" "consul_agents_cert" {
resource "random_uuid" "consul_agent_token" {}

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

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

resource "local_sensitive_file" "nomad_server_config_for_consul" {
content = templatefile("etc/nomad.d/server-consul.hcl", {
content = templatefile("${path.module}/provision-nomad/etc/nomad.d/server-consul.hcl", {
token = "${random_uuid.consul_token_for_nomad.result}"
client_service_name = "client-${local.random_name}"
server_service_name = "server-${local.random_name}"
Expand Down
6 changes: 3 additions & 3 deletions e2e/terraform/consul-servers.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resource "local_sensitive_file" "consul_initial_management_token" {
}

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

# if consul_license is unset, it'll be a harmless empty license file
resource "local_sensitive_file" "consul_environment" {
content = templatefile("etc/consul.d/.environment", {
content = templatefile("${path.module}/provision-nomad/etc/consul.d/.environment", {
license = var.consul_license
})
filename = "uploads/shared/consul.d/.environment"
Expand Down Expand Up @@ -117,7 +117,7 @@ resource "null_resource" "upload_consul_server_configs" {
destination = "/tmp/consul_server.hcl"
}
provisioner "file" {
source = "etc/consul.d/consul-server.service"
source = "${path.module}/provision-nomad/etc/consul.d/consul-server.service"
destination = "/tmp/consul.service"
}
}
Expand Down
2 changes: 1 addition & 1 deletion e2e/terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ resource "aws_ecs_cluster" "nomad_rtd_e2e" {

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

# Don't need a network for e2e tests
network_mode = "awsvpc"
Expand Down
4 changes: 2 additions & 2 deletions e2e/terraform/hcp_vault.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data "hcp_vault_cluster" "e2e_shared_vault" {
# between concurrent E2E clusters
resource "vault_policy" "nomad" {
name = "${local.random_name}-nomad-server"
policy = templatefile("${path.root}/etc/acls/vault/nomad-policy.hcl", {
policy = templatefile("${path.module}/provision-nomad/etc/acls/vault/nomad-policy.hcl", {
role = "nomad-tasks-${local.random_name}"
})
}
Expand All @@ -42,7 +42,7 @@ resource "vault_token_auth_backend_role" "nomad_cluster" {

# Nomad agent configuration for Vault
resource "local_sensitive_file" "nomad_config_for_vault" {
content = templatefile("etc/nomad.d/vault.hcl", {
content = templatefile("${path.module}/provision-nomad/etc/nomad.d/vault.hcl", {
token = vault_token.nomad.client_token
url = data.hcp_vault_cluster.e2e_shared_vault.vault_private_endpoint_url
namespace = var.hcp_vault_namespace
Expand Down
6 changes: 3 additions & 3 deletions e2e/terraform/nomad-acls.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ resource "null_resource" "bootstrap_nomad_acls" {

data "local_sensitive_file" "nomad_token" {
depends_on = [null_resource.bootstrap_nomad_acls]
filename = "${path.root}/keys/nomad_root_token"
filename = "${path.module}/keys/nomad_root_token"
}

# push the token out to the servers for humans to use.
Expand All @@ -36,8 +36,8 @@ locals {
cat <<ENV | sudo tee -a /root/.bashrc
export NOMAD_ADDR=https://localhost:4646
export NOMAD_SKIP_VERIFY=true
export NOMAD_CLIENT_CERT=/etc/nomad.d/tls/agent.crt
export NOMAD_CLIENT_KEY=/etc/nomad.d/tls/agent.key
export NOMAD_CLIENT_CERT="${path.module}/etc/nomad.d/tls/agent.crt"
export NOMAD_CLIENT_KEY="${path.module}/etc/nomad.d/tls/agent.key"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this path the path on the server, not the terraform environment? I don't think we want to change this.

export NOMAD_TOKEN=${data.local_sensitive_file.nomad_token.content}
export CONSUL_HTTP_ADDR=https://localhost:8501
export CONSUL_HTTP_TOKEN="${random_uuid.consul_initial_management_token.result}"
Expand Down
11 changes: 5 additions & 6 deletions e2e/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,13 @@ output "environment" {
sensitive = true
value = <<EOM
export NOMAD_ADDR=https://${aws_instance.server[0].public_ip}:4646
export NOMAD_CACERT=${abspath(path.root)}/keys/tls_ca.crt
export NOMAD_CLIENT_CERT=${abspath(path.root)}/keys/tls_api_client.crt
export NOMAD_CLIENT_KEY=${abspath(path.root)}/keys/tls_api_client.key
export NOMAD_CACERT=${abspath(path.module)}/keys/tls_ca.crt
export NOMAD_CLIENT_CERT=${abspath(path.module)}/keys/tls_api_client.crt
export NOMAD_CLIENT_KEY=${abspath(path.module)}/keys/tls_api_client.key
export NOMAD_TOKEN=${data.local_sensitive_file.nomad_token.content}
export NOMAD_E2E=1
export CONSUL_HTTP_ADDR=https://${aws_instance.consul_server.public_ip}:8501
export CONSUL_HTTP_TOKEN=${local_sensitive_file.consul_initial_management_token.content}
export CONSUL_CACERT=${abspath(path.root)}/keys/tls_ca.crt

export CONSUL_CACERT=${abspath(path.module)}/keys/tls_ca.crt
EOM
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing EOF

2 changes: 1 addition & 1 deletion e2e/terraform/provision-nomad/install-linux.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# SPDX-License-Identifier: BUSL-1.1

resource "local_sensitive_file" "nomad_systemd_unit_file" {
content = templatefile("etc/nomad.d/nomad-${var.role}.service", {})
content = templatefile("${path.module}/etc/nomad.d/nomad-${var.role}.service", {})
filename = "${local.upload_dir}/nomad.d/nomad.service"
file_permission = "0600"
}
Expand Down
13 changes: 6 additions & 7 deletions e2e/terraform/provision-nomad/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,28 @@
locals {
upload_dir = "uploads/${var.instance.public_ip}"

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"

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"
}

# if nomad_license is unset, it'll be a harmless empty license file
resource "local_sensitive_file" "nomad_environment" {
content = templatefile("etc/nomad.d/.environment", {
content = templatefile("${path.module}/etc/nomad.d/.environment", {
license = var.nomad_license
})
filename = "${local.upload_dir}/nomad.d/.environment"
file_permission = "0600"
}

resource "local_sensitive_file" "nomad_base_config" {
content = templatefile("etc/nomad.d/base.hcl", {
content = templatefile("${path.module}/etc/nomad.d/base.hcl", {
data_dir = var.platform != "windows" ? "/opt/nomad/data" : "C://opt/nomad/data"
})
filename = "${local.upload_dir}/nomad.d/base.hcl"
file_permission = "0600"
}

resource "local_sensitive_file" "nomad_role_config" {
content = templatefile("etc/nomad.d/${var.role}-${var.platform}.hcl", {
content = templatefile("${path.module}/etc/nomad.d/${var.role}-${var.platform}.hcl", {
aws_region = var.aws_region
aws_kms_key_id = var.aws_kms_key_id
})
Expand All @@ -41,7 +40,7 @@ resource "local_sensitive_file" "nomad_indexed_config" {
}

resource "local_sensitive_file" "nomad_tls_config" {
content = templatefile("etc/nomad.d/tls.hcl", {})
content = templatefile("${path.module}/etc/nomad.d/tls.hcl", {})
filename = "${local.upload_dir}/nomad.d/tls.hcl"
file_permission = "0600"
}
Expand Down Expand Up @@ -75,7 +74,7 @@ resource "null_resource" "upload_consul_configs" {
destination = "/tmp/consul_client.hcl"
}
provisioner "file" {
source = "etc/consul.d/consul.service"
source = "${path.module}/etc/consul.d/consul.service"
destination = "/tmp/consul.service"
}
}
Expand Down
6 changes: 4 additions & 2 deletions e2e/terraform/terraform.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
# before running `terraform apply` and created the /pkg/goos_goarch/binary
# folder

nomad_local_binary = "../../pkg/linux_amd64/nomad"
nomad_local_binary_client_windows_2016_amd64 = ["../../pkg/windows_amd64/nomad.exe"]
nomad_local_binary = "/Users/juanita.delacuestamorales/nomad/linux-amd64-ce/nomad"
#nomad_local_binary_client_windows_2016_amd64 = ["../../pkg/windows_amd64/nomad.exe"]
nomad_license = ""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trailing EOF

consul_license = ""
Loading