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

create variable #78

Closed
b6pzeusbc54tvhw5jgpyw8pwz2x6gs opened this issue Mar 14, 2021 · 8 comments
Closed

create variable #78

b6pzeusbc54tvhw5jgpyw8pwz2x6gs opened this issue Mar 14, 2021 · 8 comments
Labels
question Question about usage of the library wontfix This will not be worked on

Comments

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Copy link
Contributor

many terraform module support create or create_xx variables to controls whether resource should be created. I think, one of the reasons for doing this is, it's hard to use count or for_each in module block.

terraform-aws-next-js also has create_domain_name_records and create_image_optimization. But no option to skip for other resources.

Do you have any plans to add a create variable that controls the creation of the entire resource? Or can I create a PR?

@ofhouse
Copy link
Member

ofhouse commented Mar 14, 2021

Do you have a specific resource in mind?
My philosophy here is to support optional resources when they are not necessary or can be replaced with self-written constructs.

The next optional resource to add will be the main CloudFront distribution, which is targeted in #55.
IMHO I currently don't see other resources where this would make sense, but I am open for suggestions 🙂

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Copy link
Contributor Author

@ofhouse In many use cases, one Terraform code covers multiple environments. For example, in the code below, I would like to decide to create the next-tf module according to the environment.

module "next-tf" {
  source = "dealmore/next-js/aws"
  create = terraform.workspace == "prod"
  // or
  // create = var.env == "prod"

  next_tf_dir     = var.next_tf_dir
  deployment_name = var.deployment_name
}

This pattern can be used in many modules, including the following two modules used by this module:

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Copy link
Contributor Author

b6pzeusbc54tvhw5jgpyw8pwz2x6gs commented Mar 15, 2021

My philosophy here is to support optional resources when they are not necessary or can be replaced with self-written constructs.

This can also be achieved by just using var.create && var.create_xxx. Example:

resouce "aws_cloudfront_distribution" "this" {
  count = var.create && var.create_cloudfront_distribution ? 1 : 0
}

@ofhouse
Copy link
Member

ofhouse commented Mar 15, 2021

Ah, thanks for clarification.
I think the create variables there were originally added for versions of Terraform below 0.13 since it was not possible to use count or for_each on modules.

Terraform 0.13 (which is already the minimal required version for this module) and up support count on modules which I would prefer here since it is an official Terraform feature and no workaround like a create variable would be.

However, using count on this module currently does not work because we use an internal AWS provider to ensure that some resources are created in us-east-1 region. #50
The plan is to drop this internal provider in the next version which should lift the limitation on using count.

@b6pzeusbc54tvhw5jgpyw8pwz2x6gs
Copy link
Contributor Author

b6pzeusbc54tvhw5jgpyw8pwz2x6gs commented Mar 15, 2021

You're right. Using count in module, blocks the use of provider inside the module, I think the create variable is still useful in many cases.

@ofhouse
Copy link
Member

ofhouse commented Mar 17, 2021

Would like to reevaluate this after #50 is implemented.
Introducing a create variable would require a lot of changes and it must also be ensured that the submodules support it.

For this reason I would appreciate it when this could be handled in userland with a simple count on the module itself.

@ofhouse
Copy link
Member

ofhouse commented Apr 27, 2021

Is this still needed?
With the release of v0.8.0 it is now possible to use count on the module like this:

module "next-tf" {
  source = "dealmore/next-js/aws"

  count = terraform.workspace == "prod" ? 1 : 0
}

@ofhouse ofhouse added the question Question about usage of the library label May 1, 2021
@ofhouse
Copy link
Member

ofhouse commented Jun 7, 2021

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

@ofhouse ofhouse closed this as completed Jun 7, 2021
@ofhouse ofhouse added the wontfix This will not be worked on label Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about usage of the library wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants