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

Remote States - ${path.module{ hardcodes the full machine path in the state file (intended?) #6459

Closed
mechastorm opened this issue May 3, 2016 · 3 comments

Comments

@mechastorm
Copy link
Contributor

mechastorm commented May 3, 2016

I was wondering is this intended and is it something we need to take into account when adopting remote states.

We are currently adopting remote states for our usage of terraform and having Jenkins run our terraform plan and apply commands to simplify auditing and controls.

What we have found is on terraform stacks that use the ${path.moduel}, the value is hardcoded on the tfstate file. This complicates matter when we run terraform apply on another location as this is usually run on another location/machine that would not have access to the locaiton where terraform plan was run.

Is this expected behaviour and something we should take into account for when using remote states?

Terraform Version

0.6.15

Affected Resource(s)

path.module - mostly usage in template_file

Expected Behavior

Unknown

Actual Behavior

The tfstate file has the path to the file hardcoded

Steps to Reproduce

Run terraform plan on Machine A and generate a plan
Run terraform apply on Machine B with the generated plan

@apparentlymart
Copy link
Contributor

Hi @mechastorm! Thanks for this question.

In general we've been moving away from including filenames directly in Terraform configs for a number of reasons, including this one. Instead, we now prefer to make an attribute for the file's contents and use the file(...) to fill it, so that it's the contents rather than the filename that get written into the state.

For template_file in particular, the recommendation is now to use the template argument instead of the filename argument:

resource "template_file" "init" {
    template = "${file("${path.module}/init.tpl")}"

    vars {
        consul_address = "${aws_instance.consul.private_ip}"
    }
}

@phinze
Copy link
Contributor

phinze commented May 24, 2016

@apparentlymart's comment here is precisely the direction we are heading in - if you have a specific example that you're having trouble with we can help you figure out how to refactor it to deal in file contents rather than paths.

In the meantime I'm going to close this as answered! 👍

@ghost
Copy link

ghost commented Apr 25, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants