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

support lifecycle on data sources #8849

Closed
mengesb opened this issue Sep 15, 2016 · 4 comments
Closed

support lifecycle on data sources #8849

mengesb opened this issue Sep 15, 2016 · 4 comments

Comments

@mengesb
Copy link
Contributor

mengesb commented Sep 15, 2016

I'm using UUID() interpolation on several segments in template generation and noticed that lifecycle blocks aren't allowed. Strangely enough, I'm also noticing that the changes in the data (because UUID() generates new values each invocation) aren't resulting in changed resources. Is this deliberate or an oversight?

Desired functionality

It would be splendid if outputs could include lifecycle management blocks for just raw uuid() invocation as well, however even in this invocation I would expect that any block utilizing uuid() that we don't want changing values to require lifecycle blocks preventing the unique generation. It'd also be great if there was a uuid(string) method where we can generate UUIDs based on a string input, which I would expect to NOT change... thus solving for the need of a lifecycle block in these cases.

Terraform Version

  • v0.7.0
  • v0.7.3

Affected Resource(s)

Please list the resources as a list, for example:

  • data

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

data "template_file" "rdb_insert_script" {
  template         = "${file("${path.module}/files/dbuser.tpl")}"
  vars {
    userGuid       = "${replace(uuid(),"-","")}"
    firstName      = "${var.dbuser["firstName"]}"
    lastName       = "${var.dbuser["lastName"]}"
    emailAddress   = "${var.dbuser["emailAddress"]}"
    userIdentityGuid = "${replace(uuid(),"-","")}"
  }
}

Debug Output

Unable to provide currently (sensitive data in very large plan)

Panic Output

N/A

Expected Behavior

Expect that uuid() invocations on data sources result in new values; recreating the data source and requiring lifecycle {} to prevent this behavior

Actual Behavior

Nothing

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Generating uuid() values for template usage

References

@apparentlymart
Copy link
Contributor

apparentlymart commented Sep 15, 2016

Hi @mengesb!

Data sources are re-fetched on every run, regardless of whether the parameters are changed... their lifecycle only includes the "read" action, so there is no concept of updating or replacing them.

The lifecycle block on managed resources affects how it behaves for the purpose of the update, replace and delete actions, so those settings have no meaning on a data resource, since it lacks these actions.

I can't really follow from your example what exactly you want to achieve here, but here are some pointers that might help:

  • If you have some resource using the result of this template that you want to preserve once it is created, you could use ignore_changes on that resource, rather than on the template itself.
  • If you need to generate an identical result each time from the template, could use the random_id resource to "create" a random id that then lives in the state until you explicitly replace it. This makes the random number itself be a resource, so you can control when a new id is generated.

@mengesb
Copy link
Contributor Author

mengesb commented Sep 15, 2016

@apparentlymart I was not aware of resource "random_id" so I'll have to see how this is useful. Generally I do many things in modules so it looks like I'll have to expose something like this through outputs potentially. I'll tinker with something and if solved I'll close this.

What I'm trying to achieve is a reliable way to generate a GUID (uuid) that doesn't change based on some static text input really. This is then used in several other places including DB inserts (templates to generate these scripts).

@mengesb
Copy link
Contributor Author

mengesb commented Sep 22, 2016

@apparentlymart So I looked into random_id... seems I can use it to generate my use case however it isn't quite the same objective that I was hoping for.

In the case of RFC 4122v4 strings, there are hyphens which generally I'd be stripping out ; should I want those I'm guessing I'll have to be more creative.

That said, I can utilize random_id with keepers and output the value for ${random_id.<name>.hex} so long as I set my byte_length to 16.

I'd like to think that it is simpler to add the ability to generate immutable UUID values (unless expressly terraform destroy), however no code is ultimately easier =)

@mengesb mengesb closed this as completed Sep 23, 2016
@ghost
Copy link

ghost commented Apr 22, 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 22, 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