Skip to content

Commit

Permalink
Refactor Terraform scripts for different providers (nephio-project#179)
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Morales <v.morales@samsung.com>
  • Loading branch information
electrocucaracha authored and dkosteck committed Aug 15, 2024
1 parent 81eadca commit 889d99c
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 104 deletions.
68 changes: 59 additions & 9 deletions .prow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ presubmits:
args:
- "--plugin-config=prow/config/plugins.yaml"
- "--config-path=prow/config/config.yaml"
- name: e2e-ubuntu
- name: e2e-ubuntu-focal
annotations:
labels:
run_if_changed: '^e2e/'
Expand All @@ -29,8 +29,8 @@ presubmits:
args:
- "-c"
- |
set -eE; cd e2e/terraform/ubuntu; trap 'terraform destroy -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -auto-approve
set -eE; cd e2e/terraform; trap 'terraform destroy -target module.gcp-ubuntu-focal -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -target module.gcp-ubuntu-focal -auto-approve
volumeMounts:
- name: satoken
mountPath: "/etc/satoken"
Expand Down Expand Up @@ -64,7 +64,7 @@ presubmits:
items:
- key: nephio.yaml
path: nephio.yaml
- name: e2e-fedora
- name: e2e-fedora-34
annotations:
labels:
run_if_changed: '^e2e/'
Expand All @@ -79,8 +79,8 @@ presubmits:
args:
- "-c"
- |
set -eE; cd e2e/terraform/fedora; trap 'terraform destroy -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -auto-approve
set -eE; cd e2e/terraform; trap 'terraform destroy -target module.gcp-fedora-34 -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -target module.gcp-fedora-34 -auto-approve
volumeMounts:
- name: satoken
mountPath: "/etc/satoken"
Expand Down Expand Up @@ -298,7 +298,7 @@ postsubmits:
path: config.json

periodics:
- name: e2e-daily
- name: e2e-ubuntu-focal-daily
annotations:
labels:
cron: "0 15 * * 1-5"
Expand All @@ -313,8 +313,58 @@ periodics:
args:
- "-c"
- |
set -eE; cd e2e/terraform; trap 'terraform destroy -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -auto-approve
set -eE; cd e2e/terraform; trap 'terraform destroy -target module.gcp-ubuntu-focal -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -target module.gcp-ubuntu-focal -auto-approve
volumeMounts:
- name: satoken
mountPath: "/etc/satoken"
- name: ssh-key-vol
mountPath: "/etc/ssh-key"
- name: nephio-e2e-yaml
mountPath: "/etc/nephio"
resources:
requests:
cpu: 2
memory: 2Gi
volumes:
- name: satoken
secret:
secretName: satoken
items:
- key: satoken
path: satoken
- name: ssh-key-vol
secret:
secretName: ssh-key-e2e
defaultMode: 256
items:
- key: id_rsa
path: id_rsa
- key: id_rsa.pub
path: id_rsa.pub
- name: nephio-e2e-yaml
secret:
secretName: nephio-e2e-yaml
items:
- key: nephio.yaml
path: nephio.yaml
- name: e2e-fedora-34-daily
annotations:
labels:
cron: "0 15 * * 1-5"
skip_report: false
decorate: true
cluster: default
spec:
containers:
- image: "nephio/e2e:1"
command:
- "/bin/sh"
args:
- "-c"
- |
set -eE; cd e2e/terraform; trap 'terraform destroy -target module.gcp-fedora-34 -auto-approve' EXIT;
terraform init && timeout 75m terraform apply -target module.gcp-fedora-34 -auto-approve
volumeMounts:
- name: satoken
mountPath: "/etc/satoken"
Expand Down
13 changes: 0 additions & 13 deletions e2e/terraform/fedora/main.tf

This file was deleted.

9 changes: 9 additions & 0 deletions e2e/terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module "gcp-ubuntu-focal" {
source = ".//modules/gcp"
}

module "gcp-fedora-34" {
source = ".//modules/gcp"
vmimage = "fedora-cloud/fedora-cloud-34"
ansible_user = "fedora"
}
4 changes: 0 additions & 4 deletions e2e/terraform/modules/e2e/output.tf

This file was deleted.

51 changes: 0 additions & 51 deletions e2e/terraform/modules/e2e/variables.tf

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
terraform {
required_providers {
random = "~> 3.5"
google = "~> 4.80"
}
}

provider "google" {
credentials = file(var.credentials)
project = var.project
region = var.region
zone = var.zone
}

resource "random_string" "vm-name" {
length = 6
upper = false
Expand All @@ -7,8 +21,8 @@ resource "random_string" "vm-name" {
}

locals {
vm-name = "e2e-vm-${random_string.vm-name.result}"
nephioyaml = "/home/${var.home_user}/nephio.yaml"
vm-name = "e2e-vm-${random_string.vm-name.result}"
nephioyaml = "/home/${var.ansible_user}/nephio.yaml"
}

resource "google_compute_instance" "lab_instances" {
Expand Down Expand Up @@ -54,8 +68,8 @@ resource "google_compute_instance" "e2e_instances" {
}
}
provisioner "file" {
source = "../../../../test-infra"
destination = "/home/${var.home_user}/test-infra"
source = "../../../test-infra"
destination = "/home/${var.ansible_user}/test-infra"
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
Expand Down Expand Up @@ -88,17 +102,17 @@ resource "google_compute_instance" "e2e_instances" {
]
}
provisioner "remote-exec" {
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
private_key = file(var.ssh_prv_key)
user = var.ansible_user
agent = false
}
inline = [
"cd /home/${var.home_user}/test-infra/e2e/provision/",
"chmod +x init.sh",
"sudo -E NEPHIO_REPO_DIR=/home/${var.home_user}/test-infra NEPHIO_DEBUG=true NEPHIO_RUN_E2E=true NEPHIO_USER=${var.home_user} ./init.sh"
]
connection {
host = self.network_interface[0].access_config[0].nat_ip
type = "ssh"
private_key = file(var.ssh_prv_key)
user = var.ansible_user
agent = false
}
inline = [
"cd /home/${var.ansible_user}/test-infra/e2e/provision/",
"chmod +x init.sh",
"sudo -E NEPHIO_REPO_DIR=/home/${var.ansible_user}/test-infra NEPHIO_DEBUG=true NEPHIO_RUN_E2E=true NEPHIO_USER=${var.ansible_user} ./init.sh"
]
}
}
4 changes: 4 additions & 0 deletions e2e/terraform/modules/gcp/output.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "instance_ips" {
value = join(" ", google_compute_instance.lab_instances[*].network_interface[0].access_config[0].nat_ip)
description = "The public IP address of the newly created instance"
}
65 changes: 65 additions & 0 deletions e2e/terraform/modules/gcp/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
variable "project" {
description = "GCP project that will host CI instances"
default = "pure-faculty-367518"
type = string
}

variable "region" {
description = "GCP region to deploy CI instances"
default = "us-central1"
type = string
}

variable "zone" {
description = "GCP zone to deploy CI instances"
default = "us-central1-c"
type = string
}

variable "instance" {
description = "GCP flavor to be used by the CI instances"
default = "e2-standard-16"
type = string
}

variable "vmimage" {
description = "OS image to be used for the creation of CI instances"
default = "ubuntu-os-cloud/ubuntu-2004-lts"
type = string
}

variable "credentials" {
description = "Credentials file to connect to GCP"
default = "/etc/satoken/satoken"
type = string
}

variable "ssh_prv_key" {
description = "SSH private key for CI instance's connection"
default = "/etc/ssh-key/id_rsa"
type = string
}

variable "ssh_pub_key" {
description = "SSH public key for CI instance's connection"
default = "/etc/ssh-key/id_rsa.pub"
type = string
}

variable "ansible_user" {
description = "OS user used for Ansible connectivity"
default = "ubuntu"
type = string
}

variable "nephio_lab_nodes" {
description = "The number of Lab instances to be created."
default = 0
type = number
}

variable "nephio_e2e_nodes" {
description = "The number of End-to-End instances running per PR."
default = 1
type = number
}
11 changes: 0 additions & 11 deletions e2e/terraform/ubuntu/main.tf

This file was deleted.

0 comments on commit 889d99c

Please sign in to comment.