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

have first-class enabled/disabled for modules and resources #24995

Closed
schollii opened this issue May 19, 2020 · 3 comments
Closed

have first-class enabled/disabled for modules and resources #24995

schollii opened this issue May 19, 2020 · 3 comments

Comments

@schollii
Copy link

Current Terraform Version

Terraform v0.12.24
+ provider.aws v2.50.0
+ provider.local v1.4.0
+ provider.null v2.1.2
+ provider.template v2.1.2

Use-cases

Give the user of your module the option to disable creation of certain resources or modules

Attempted Solutions

Use "count" (or different name) where 0 means disabled, and 1 means enabled.
This solution works but causes the resource to become a list of resources. Eg

resource "abc_type" "something" {
   count = var.enabled ? 0 : 1
   ...
}

causes abc_type.something to be a list of length 1 if "enabled" is true. This means everywhere in the code that this single resource is referenced, a '[0]' must be appended. This adds noise to the code and obfuscates intent.

The usage of "count" meta-variable has worked but it is now time for HCL2 resources to get a proper "enabled" meta-variable.

Proposal

HCL2 should support the following syntax:

resource "abc_type" "something" {
   enabled = var.enabled
   ...
}

If enabled is false, the resource should not be instantiated.

@wasfree
Copy link
Contributor

wasfree commented May 28, 2020

Hi @schollii,
agree with you, this would be a cool feature. But it seems your request is duplicate of #21953.

@schollii
Copy link
Author

schollii commented Jun 8, 2020

Awesome, thanks for the info I have added my vote.

@ghost
Copy link

ghost commented Mar 29, 2021

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 as resolved and limited conversation to collaborators Mar 29, 2021
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

2 participants