terraform-ibm-modules/terraform-ibm-satellite

`/tmp/.schematics/addhost.sh` Doesn't exist on `terraform plan`

Opened this issue · 0 comments

Issue

When running terraform init; terraform plan, I get the following error

  on .terraform/modules/apply_aws_sat_location/aws/sat-location/modules/ec2/ec2.tf line 11, in resource "aws_instance" "ec2_instance":
  11:   user_data = file("/tmp/.schematics/addhost.sh")

Invalid value for "path" parameter: no file exists at
/tmp/.schematics/addhost.sh; this function works only with files that are
distributed as part of the configuration source code, so if this file will be
created by a resource in this configuration you must instead obtain this
result from an attribute of that resource.

Debugging

Attempt 1

Terrafom seems to expect the file to exist before a plan and apply. By running

mkdir /tmp/.schematics; touch /tmp.schematics/addhost.sh

I'm able to bypass the error locally; however, we're using this in a terraform as a service cloud and can't rely on local setup commands

Attempt 2

Adding the above local commands to the module location.sh.

Still got the same error because terraform doesn't see the file at initialization. Even with a depends_on = [module.satellite-location], terraform errors.

Solution thoughts

Perhaps Terraform's local_file will be the solution. That would require refactoring the last part of the module, but the file could also be passed as output from the module and imported into ec2 instances.