Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hold for file creation before releasing output variables #41

Closed
aaronsteers opened this issue Jul 2, 2020 · 1 comment · Fixed by #42
Closed

Hold for file creation before releasing output variables #41

aaronsteers opened this issue Jul 2, 2020 · 1 comment · Fixed by #42

Comments

@aaronsteers
Copy link

aaronsteers commented Jul 2, 2020

Issue Description

Hello - I love this module; it's made it much easier for me to create full pipelines for connecting to EC2 instances. However, I do have one major issue - the output variables "public_key_filename" and "private_key_filename" are released to downstream modules/resources too early, aka they are released immediately (during plan) before the files are actually created. This creates problems as other modules will try to parse those files and will fail because the file does not exist.

Workaround

My workaround is to hide the input of these variables behind a "fake" if-then block, as below:

module "tableau_server_on_aws" {
  ...
  # The if-then clause gives the same result regardless of length(public_key); the real purpose is to force a wait on file creation.
  ssh_public_key_filepath  = length(module.ssh_key_pair2.public_key) > 0 ? module.ssh_key_pair2.public_key_filename : module.ssh_key_pair2.public_key_filename
  ssh_private_key_filepath = length(module.ssh_key_pair2.public_key) > 0 ? module.ssh_key_pair2.private_key_filename : module.ssh_key_pair2.private_key_filename
  ...
}

module "ssh_key_pair" {
  source                = "git::https://github.com/cloudposse/terraform-aws-key-pair.git?ref=master"
  namespace             = lower(local.name_prefix)
  ssh_public_key_path   = abspath(local.secrets_folder)
  name                  = "aws-ssh-key"
  ...
}

Because the public_key output variable is not known until after the files are created, this workaround forces the downstream consumer to wait until the files exist before evaluating downstream conditions.

Requested Change

My ask would be to create a similar hold on the module's filename outputs, until those files have been created and can be consumed.

@aaronsteers
Copy link
Author

Created PR with proposed fix here: #42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant