Skip to content

Commit

Permalink
ci: update e2e mini default region and always return resource group n…
Browse files Browse the repository at this point in the history
…ame (#3373)

* Choose resource group name outside of Terraform to catch issues during apply
* Run test in West Europe

---------

Signed-off-by: Daniel Weiße <[email protected]>
  • Loading branch information
daniel-weisse authored Sep 25, 2024
1 parent 068e68d commit c0a59a1
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 59 deletions.
5 changes: 2 additions & 3 deletions .github/actions/e2e_mini/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,5 @@ runs:
# clean up if e2e test failed or if the run was cancelled
if: (failure() && steps.e2e-test.conclusion == 'failure') || cancelled()
run: |
rg_name=${{ steps.e2e-test.outputs.rgname }}
echo "[*] Deleting resource group $rg_name"
az group delete -y --resource-group "$rg_name"
echo "[*] Deleting resource group ${{ steps.e2e-test.outputs.rgname }}"
az group delete -y --resource-group "${{ steps.e2e-test.outputs.rgname }}"
30 changes: 0 additions & 30 deletions e2e/miniconstellation/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/miniconstellation/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ filegroup(
"main.tf",
"output.tf",
"test-remote.sh",
"variables.tf",
],
)

Expand Down
8 changes: 5 additions & 3 deletions e2e/miniconstellation/main.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ cd e2e/miniconstellation

echo "::group::Terraform"

random_string=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 6)
rg_name="e2e-mini-${random_string}"
echo "rgname=${rg_name}" >> "${GITHUB_OUTPUT:-/dev/null}"
echo "resource_name = \"${rg_name}\"" > terraform.tfvars

terraform init
terraform apply -auto-approve
terraform output -raw ssh_private_key > id_rsa
chmod 600 id_rsa

rg_name=$(terraform output -raw rg_name)
echo "rgname=$rg_name" >> "${GITHUB_OUTPUT:-/dev/null}"

azure_vm_ip=$(terraform output -raw public_ip)

echo "::endgroup::"
Expand Down
25 changes: 8 additions & 17 deletions e2e/miniconstellation/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ terraform {
source = "hashicorp/azurerm"
version = "4.1.0"
}
random = {
source = "hashicorp/random"
version = "3.6.2"
}
tls = {
source = "hashicorp/tls"
version = "4.0.5"
Expand All @@ -29,11 +25,6 @@ provider "azurerm" {

provider "tls" {}

resource "random_string" "suffix" {
length = 6
special = false
}

resource "tls_private_key" "ssh_key" {
algorithm = "RSA"
rsa_bits = 2048
Expand All @@ -50,34 +41,34 @@ data "cloudinit_config" "cloud_init" {
}

resource "azurerm_resource_group" "main" {
name = "e2e-mini-${random_string.suffix.result}"
location = "North Europe"
name = var.resource_name
location = "West Europe"
}

resource "azurerm_virtual_network" "main" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
}

resource "azurerm_subnet" "main" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
resource_group_name = azurerm_resource_group.main.name
virtual_network_name = azurerm_virtual_network.main.name
address_prefixes = ["10.0.2.0/24"]
}

resource "azurerm_public_ip" "main" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
location = azurerm_resource_group.main.location
resource_group_name = azurerm_resource_group.main.name
allocation_method = "Static"
sku = "Standard"
}

resource "azurerm_network_interface" "main" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location

Expand All @@ -90,7 +81,7 @@ resource "azurerm_network_interface" "main" {
}

resource "azurerm_network_security_group" "ssh" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location

Expand All @@ -113,7 +104,7 @@ resource "azurerm_subnet_network_security_group_association" "ssh" {
}

resource "azurerm_linux_virtual_machine" "main" {
name = "e2e-mini-${random_string.suffix.result}"
name = var.resource_name
resource_group_name = azurerm_resource_group.main.name
location = azurerm_resource_group.main.location

Expand Down
6 changes: 0 additions & 6 deletions e2e/miniconstellation/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,3 @@ output "ssh_private_key" {
sensitive = true
depends_on = [tls_private_key.ssh_key]
}

output "rg_name" {
value = "e2e-mini-${random_string.suffix.result}"
sensitive = false
depends_on = [random_string.suffix]
}
4 changes: 4 additions & 0 deletions e2e/miniconstellation/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "resource_name" {
type = string
description = "name for resources to create"
}

0 comments on commit c0a59a1

Please sign in to comment.