Skip to content

Commit 94c4bbb

Browse files
Prep for tag (#124)
* added sandbox_version to terraform variables to help with tagging and explicit versioning of the installed environment * tested using existing VPC and existing public subnet * automatically scp deployed info to head node * not using, removed requirements.txt
1 parent 7026ce9 commit 94c4bbb

9 files changed

Lines changed: 40 additions & 167 deletions

File tree

DEPLOYMENT.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Newer versions are NOT open source for commercial use.
1818
Download and install the package that matches your desktop computer's architecture.
1919
https://releases.hashicorp.com/terraform/1.5.7/
2020

21+
Terraform Language Documentation
22+
https://developer.hashicorp.com/terraform/language/v1.5.x
23+
2124
On a Mac you can also install it using brew:
2225
```brew install terraform```
2326

scripts/reqs.p11

Lines changed: 0 additions & 74 deletions
This file was deleted.

scripts/requirements.txt

Lines changed: 0 additions & 72 deletions
This file was deleted.

terraform/init_template.tpl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ set -x
33

44
echo `date` > ~/setup.log
55

6-
BRANCH=main
6+
BRANCH=${sandbox_version}
77

88
# RHEL8+
99
RUNUSER="ec2-user"
@@ -15,7 +15,6 @@ mkdir -p /mnt/efs/fs1
1515
sudo yum -y -q install git
1616

1717

18-
1918
## Install EFS utilities
2019
########################
2120
# https://github.com/aws/efs-utils/blob/v2.3.3/README.md

terraform/main.tf

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,10 @@ resource "aws_instance" "head_node" {
313313
key_name = var.key_name
314314
iam_instance_profile = aws_iam_instance_profile.cloud_sandbox_iam_instance_profile.name
315315

316-
user_data = templatefile("init_template.tpl", { efs_name = aws_efs_file_system.main_efs.dns_name, ami_name = "${var.name_tag}-${random_pet.ami_id.id}", aws_region = var.preferred_region, project = var.project_tag })
316+
# The user_data section is executed in the last step of initialization/creation of the instance
317+
# the variables in { } will be exported and available to the shell script in init_template.tpl
318+
319+
user_data = templatefile("init_template.tpl", { efs_name = aws_efs_file_system.main_efs.dns_name, ami_name = "${var.name_tag}-${random_pet.ami_id.id}", aws_region = var.preferred_region, project = var.project_tag, sandbox_version = var.sandbox_version})
317320

318321
# associate_public_ip_address = true
319322
network_interface {
@@ -358,21 +361,18 @@ resource "aws_network_interface" "head_node" {
358361
}
359362
}
360363

364+
# https://developer.hashicorp.com/terraform/language/v1.5.x/resources/terraform-data
365+
366+
# scp deployment info to head node automatically
367+
resource "terraform_data" "send_outputs" {
361368

362-
# TODO scp deployment info to head node automatically
363-
# quick search reply from google AI - fix/check/test for correctness, e.g. fix trigger
364-
#resource "null_resource" "run_post_apply_script" {
365-
# # This 'triggers' block ensures the null_resource is re-evaluated
366-
# # if any of the specified values change, effectively re-running the script.
367-
# # You can add dependencies on other resources if you want the script
368-
# # to run only after those resources are fully provisioned.
369-
# triggers = {
370-
# always_run = timestamp() # This ensures it runs on every apply
371-
# }
372-
#
373-
# provisioner "local-exec" {
374-
# command = "${path.module}/scp.terraform.output.sh"
375-
# }
376-
#}
369+
triggers_replace = [
370+
timestamp()
371+
]
372+
# aws_instance.head_node.id
377373

374+
provisioner "local-exec" {
375+
command = "./scp.terraform.output.sh"
376+
}
377+
}
378378

terraform/mysettings.tfvars

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@
99
# The following variables must be defined, no defaults exist:
1010
#------------------------------------------------------------
1111

12-
# List of the specific IP's or IP address rangest the are allowed SSH access to the system
12+
# Specify the cloud sandbox branch or tag to use for the node setup
13+
# wil default to main if not defined.
14+
# Examples:
15+
# sandbox_version = "main"
16+
# sandbox_version = "v2.1.0"
17+
18+
sandbox_version = "main"
19+
20+
# List of the specific IP's or IP address ranges that are allowed SSH access to the system
1321
# They should be in the format ###.###.###.###/32 for a single IP, any number of IPs can be added to the list.
1422
# Example:
1523
allowed_ssh_cidr_list = ["72.0.162.256/32", "94.256.4.28/32" ]
@@ -19,7 +27,7 @@ allowed_ssh_cidr_list = ["72.0.162.256/32", "94.256.4.28/32" ]
1927

2028
# Example:
2129
key_name = "my-sandbox-key"
22-
public_key = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2cQ3fq/VNzP1R2+94nGwonW9k20nuQJcCd3g2ylW5clzyjun6eWz2PZKMwtJh7E28B1jp3F8YTP5XBPg+Z++hpvcthL2XtAwANd0ouvZO6gkcrbgjhuM0A4NKJM6RylGAOqqPY/ZE6gOUGrnIbhd9eI3RKhSQbxf5hwS7tIG1FebO9HuObaM23LDB1/Ra/YMTXB5LHPChlfxrEIlM/0//tO7OUfRPNgtudAb/MQZ+YD+6I77QDtTwZwQvebxLK62bP5CrpV4XY5ybWOZ0T3m4pVNfhfl7+QWAvWeStNpH3B3q1ZtPLTuAVvsR4RWk7t75IwpHwiPBcgZn/PTpN45z"
30+
public_key = "ssh-rsa AAAABbbccd+long-sequence-of-characters+a123abcd+XYX/z910A"
2331

2432
# (Optional VPC) If using an existing VPC use the ID to deploy resources to use that VPC ID, otherwise leave blank
2533
# vpc_id = "vpc-0dd381e9f82c9ae68e7"

terraform/outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,5 +72,5 @@ output "aws_placement_group" {
7272
*/
7373
output "login_command" {
7474
description = "SSH Login"
75-
value = one(aws_eip.head_node[*]) != null ? "ssh -i ~/.ssh/${var.key_name}.pem ec2-user@${one(aws_eip.head_node[*]).public_dns}" : "ssh -i ~/.ssh/${var.key_name}.pem ec2-user@${aws_instance.head_node.private_dns}"
75+
value = aws_instance.head_node.public_ip != null ? "ssh -i ~/.ssh/${var.key_name}.pem ec2-user@${aws_instance.head_node.public_ip}" : "ssh -i ~/.ssh/${var.key_name}.pem ec2-user@${aws_instance.head_node.private_dns}"
7676
}

terraform/scp.terraform.output.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ terraform output > $outputfile
88
key=`cat $outputfile | grep login_command | awk -F= '{print $2}' | awk '{print $3}'`
99
login=`cat $outputfile | grep login_command | awk -F= '{print $2}' | awk '{print $4}' | awk -F\" '{print $1}'`
1010

11+
remote_host=`cat deployment.info | grep login_command | awk -F@ '{print $2}' | awk -F\" '{print $1}'`
12+
ssh-keyscan -H $remote_host >> ~/.ssh/known_hosts
13+
1114
echo "Copying deployment.info to head node"
1215
echo "++++++++++++++++++++++++++++++++++++"
1316
echo "scp -i $key -p $outputfile ${login}:~/$outputfile"

terraform/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,9 @@ variable "ami_id" {
127127
type = string
128128
default = "unknown value"
129129
}
130+
131+
variable "sandbox_version" {
132+
description = "Specify the Cloud-Sandbox branch/tag to use"
133+
type = string
134+
default = "main"
135+
}

0 commit comments

Comments
 (0)