Skip to content

Hold for file creation before releasing output variables #41

@aaronsteers

Description

@aaronsteers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions