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

Update e2e infra provision to expect providers #24694

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Thumbs.db
.idea
.fleet


# Folders
_obj
_test
Expand Down
177 changes: 0 additions & 177 deletions e2e/terraform/.terraform.lock.hcl

This file was deleted.

2 changes: 1 addition & 1 deletion e2e/terraform/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CONSUL_LICENSE_PATH ?=
custom.tfvars:
echo 'nomad_local_binary = "$(PKG_PATH)"' > custom.tfvars
echo 'volumes = false' >> custom.tfvars
echo 'client_count_ubuntu_jammy_amd64 = 3' >> custom.tfvars
echo 'client_count_linux = 3' >> custom.tfvars
echo 'client_count_windows_2016_amd64 = 0' >> custom.tfvars
echo 'consul_license = "$(shell cat $(CONSUL_LICENSE_PATH))"' >> custom.tfvars
echo 'nomad_license = "$(shell cat $(NOMAD_LICENSE_PATH))"' >> custom.tfvars
Expand Down
2 changes: 1 addition & 1 deletion e2e/terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Linux clients or Windows clients.
region = "us-east-1"
instance_type = "t2.medium"
server_count = "3"
client_count_ubuntu_jammy_amd64 = "4"
client_count_linux = "4"
Copy link
Member

Choose a reason for hiding this comment

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

This variable originally included the specific distro and architecture so that we could spin up different hosts in the same test run (although we never got around to doing so). It's not obvious to me how we're planning on feeding in the architecture/platform if not by this variable.

(Or, if we're planning on adding architecture/platform variables later, shouldn't we make the same change to the windows_2026_amd64` var?)

client_count_windows_2016_amd64 = "1"
```

Expand Down
36 changes: 10 additions & 26 deletions e2e/terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@ provider "aws" {
region = var.region
}

data "aws_caller_identity" "current" {
}

resource "random_pet" "e2e" {
}

resource "random_password" "windows_admin_password" {
length = 20
special = true
override_special = "_%@"
}
module "provision-infra" {
source = "./provision-infra"

locals {
random_name = "${var.name}-${random_pet.e2e.id}"
}

# Generates keys to use for provisioning and access
module "keys" {
name = local.random_name
path = "${path.root}/keys"
source = "mitchellh/dynamic-keys/aws"
version = "v2.0.0"
}

data "aws_kms_alias" "e2e" {
name = "alias/${var.aws_kms_alias}"
}
server_count = var.client_count_linux
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
server_count = var.client_count_linux
server_count = var.server_count

client_count_linux = var.client_count_linux
client_count_windows_2016_amd64 = var.client_count_windows_2016_amd64
nomad_local_binary = var.nomad_local_binary
nomad_license = var.nomad_license
consul_license = var.consul_license
nomad_region = var.nomad_region
}
Copy link
Member

Choose a reason for hiding this comment

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

Missing trailing EOL. There's a few of these in this PR.

44 changes: 5 additions & 39 deletions e2e/terraform/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,19 @@
# SPDX-License-Identifier: BUSL-1.1

output "servers" {
value = aws_instance.server.*.public_ip
value = module.provision-infra.servers
}

output "linux_clients" {
value = aws_instance.client_ubuntu_jammy_amd64.*.public_ip
value = module.provision-infra.linux_clients
}

output "windows_clients" {
value = aws_instance.client_windows_2016_amd64.*.public_ip
value = module.provision-infra.windows_clients
}

output "message" {
value = <<EOM
Your cluster has been provisioned! To prepare your environment, run:

$(terraform output --raw environment)

Then you can run tests from the e2e directory with:

go test -v .

ssh into servers with:

%{for ip in aws_instance.server.*.public_ip~}
ssh -i keys/${local.random_name}.pem ubuntu@${ip}
%{endfor~}

ssh into clients with:

%{for ip in aws_instance.client_ubuntu_jammy_amd64.*.public_ip~}
ssh -i keys/${local.random_name}.pem ubuntu@${ip}
%{endfor~}
%{for ip in aws_instance.client_windows_2016_amd64.*.public_ip~}
ssh -i keys/${local.random_name}.pem Administrator@${ip}
%{endfor~}

EOM
value = module.provision-infra.message
}

# Note: Consul and Vault environment needs to be set in test
Expand All @@ -47,15 +23,5 @@ EOM
output "environment" {
description = "get connection config by running: $(terraform output environment)"
sensitive = true
value = <<EOM
export NOMAD_ADDR=https://${aws_instance.server[0].public_ip}:4646
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.module)}/keys/tls_ca.crt
EOM
value = module.provision-infra.environment
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# SPDX-License-Identifier: BUSL-1.1

locals {
ami_prefix = "nomad-e2e-v3"
ami_prefix = "nomad-e2e-v3"
ubuntu_instance_name = "ubuntu-jammy-${var.instance_architecture}"
Copy link
Member

Choose a reason for hiding this comment

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

This is the image (AMI), not the instance, right?

Suggested change
ubuntu_instance_name = "ubuntu-jammy-${var.instance_architecture}"
ubuntu_image_name = "ubuntu-jammy-${var.instance_architecture}"

}

resource "aws_instance" "server" {
Expand All @@ -22,18 +23,18 @@ resource "aws_instance" "server" {
}
}

resource "aws_instance" "client_ubuntu_jammy_amd64" {
ami = data.aws_ami.ubuntu_jammy_amd64.image_id
resource "aws_instance" "client_ubuntu_jammy" {
ami = data.aws_ami.ubuntu_jammy.image_id
instance_type = var.instance_type
key_name = module.keys.key_name
vpc_security_group_ids = [aws_security_group.clients.id] # see also the secondary ENI
count = var.client_count_ubuntu_jammy_amd64
count = var.client_count_linux
iam_instance_profile = data.aws_iam_instance_profile.nomad_e2e_cluster.name
availability_zone = var.availability_zone

# Instance tags
tags = {
Name = "${local.random_name}-client-ubuntu-jammy-amd64-${count.index}"
Name = "${local.random_name}-client-ubuntu-jammy-${count.index}"
ConsulAutoJoin = "auto-join-${local.random_name}"
User = data.aws_caller_identity.current.arn
}
Expand Down Expand Up @@ -106,6 +107,26 @@ data "aws_ami" "ubuntu_jammy_amd64" {
}
}

data "aws_ami" "ubuntu_jammy" {
most_recent = true
owners = ["self"]

filter {
name = "name"
values = ["${local.ami_prefix}-${local.ubuntu_instance_name}-*"]
}

filter {
name = "tag:OS"
values = ["Ubuntu"]
}

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

data "aws_ami" "windows_2016_amd64" {
count = var.client_count_windows_2016_amd64 > 0 ? 1 : 0

Expand Down
Loading
Loading