@@ -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
0 commit comments