diff --git a/.gitignore b/.gitignore index 9a46aa7eaa..bb010d36a4 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ /build .vagrant/ .DS_Store +go.work* diff --git a/tests/terraform/modules/main.tf b/tests/terraform/modules/main.tf index f0e4d11fd3..d4defe860c 100644 --- a/tests/terraform/modules/main.tf +++ b/tests/terraform/modules/main.tf @@ -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 diff --git a/tests/terraform/modules/master/instances_server.tf b/tests/terraform/modules/master/instances_server.tf index 70a483b186..2ba6d7f4e8 100644 --- a/tests/terraform/modules/master/instances_server.tf +++ b/tests/terraform/modules/master/instances_server.tf @@ -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" @@ -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" diff --git a/tests/terraform/modules/master/variables.tf b/tests/terraform/modules/master/variables.tf index ef195a86e8..9405da1765 100644 --- a/tests/terraform/modules/master/variables.tf +++ b/tests/terraform/modules/master/variables.tf @@ -43,3 +43,4 @@ variable "etcd_cp_nodes" {} variable "etcd_worker_nodes" {} variable "cp_only_nodes" {} variable "cp_worker_nodes" {} +variable "optional_files" {} diff --git a/tests/terraform/modules/optional_write_files.sh b/tests/terraform/modules/optional_write_files.sh new file mode 100644 index 0000000000..809b4542d2 --- /dev/null +++ b/tests/terraform/modules/optional_write_files.sh @@ -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 diff --git a/tests/terraform/modules/variables.tf b/tests/terraform/modules/variables.tf index 08789fe8da..8aecf32adf 100644 --- a/tests/terraform/modules/variables.tf +++ b/tests/terraform/modules/variables.tf @@ -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" +} diff --git a/tests/terraform/scripts/Dockerfile.build b/tests/terraform/scripts/Dockerfile.build index f67b2cbc4c..0d58de9875 100644 --- a/tests/terraform/scripts/Dockerfile.build +++ b/tests/terraform/scripts/Dockerfile.build @@ -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 && \