Skip to content

Commit

Permalink
Add ability to have write custom files during TF tests for specialize…
Browse files Browse the repository at this point in the history
…d configurations (#4132)

Signed-off-by: rancher-max <[email protected]>
  • Loading branch information
rancher-max authored Apr 28, 2023
1 parent 0a1f395 commit c4ed8d8
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
/build
.vagrant/
.DS_Store
go.work*
1 change: 1 addition & 0 deletions tests/terraform/modules/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module "master" {
etcd_worker_nodes = var.etcd_worker_nodes
cp_only_nodes = var.cp_only_nodes
cp_worker_nodes = var.cp_worker_nodes
optional_files = var.optional_files

# AWS variables
access_key = var.access_key
Expand Down
20 changes: 20 additions & 0 deletions tests/terraform/modules/master/instances_server.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ resource "aws_instance" "master" {
Name = "${var.resource_name}-server"
"kubernetes.io/cluster/clusterid" = "owned"
}
provisioner "file" {
source = "optional_write_files.sh"
destination = "/tmp/optional_write_files.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/optional_write_files.sh",
"sudo /tmp/optional_write_files.sh \"${var.optional_files}\"",
]
}
provisioner "file" {
source = "define_node_role.sh"
destination = "/tmp/define_node_role.sh"
Expand Down Expand Up @@ -78,6 +88,16 @@ resource "aws_instance" "master2" {
"kubernetes.io/cluster/clusterid" = "owned"
}
depends_on = [aws_instance.master]
provisioner "file" {
source = "optional_write_files.sh"
destination = "/tmp/optional_write_files.sh"
}
provisioner "remote-exec" {
inline = [
"chmod +x /tmp/optional_write_files.sh",
"sudo /tmp/optional_write_files.sh \"${var.optional_files}\"",
]
}
provisioner "file" {
source = "define_node_role.sh"
destination = "/tmp/define_node_role.sh"
Expand Down
1 change: 1 addition & 0 deletions tests/terraform/modules/master/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ variable "etcd_cp_nodes" {}
variable "etcd_worker_nodes" {}
variable "cp_only_nodes" {}
variable "cp_worker_nodes" {}
variable "optional_files" {}
19 changes: 19 additions & 0 deletions tests/terraform/modules/optional_write_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# This script pulls raw files and writes to specified locations.
# For example, it can be used to write HelmChartConfig or custom PSA files.


files=$1

if [ -n "$files" ]
then
file_array=($(echo "$files" | tr ' ' '\n'))
for current_file in "${file_array[@]}"; do
file_location=$(echo "$current_file" | awk -F, '{print $1}')
mkdir -p "$(dirname "$file_location")"

raw_data=$(echo "$current_file" | awk -F, '{print $2}')
curl -s "$raw_data" -o "$file_location"
done

fi
3 changes: 3 additions & 0 deletions tests/terraform/modules/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ variable "cp_only_nodes" {
variable "cp_worker_nodes" {
default = 0
}
variable "optional_files" {
description = "File location and raw data url separate by commas, with a space for other pairs. E.g. file1,url1 file2,url2"
}
2 changes: 1 addition & 1 deletion tests/terraform/scripts/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:alpine

ARG TF_VERSION=1.4.0
ARG TF_VERSION=1.4.5
ENV TERRAFORM_VERSION $TF_VERSION

RUN apk update && \
Expand Down

0 comments on commit c4ed8d8

Please sign in to comment.