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

Add hotfix for Terraform "count" issue #1

Merged
merged 3 commits into from
Oct 24, 2019

Conversation

fatbasstard
Copy link
Contributor

@fatbasstard fatbasstard commented Oct 23, 2019

This PR adds the option to explicitly create the Role Policy (or not), whether a policy is given or not. This is optional and should only be used to a (possible) issue that Terraform cannot determine a count value:


  on .terraform/modules/mx001un_cb_brewery.iot-core-to-s3.iot_topic_role_firehose/main.tf line 26, in resource "aws_iam_role_policy" "default":
  26:   count  = var.role_policy != "" ? 1 : 0

The "count" value depends on resource attributes that cannot be determined
until apply, so Terraform cannot predict how many instances will be created.
To work around this, use the -target argument to first apply only the
resources that the count depends on.

When this error occurs depends on the explicit setup with modules, data resources and variables and therefor does not always occur.

Normally, a Policy resource is created if a policy document is specified. Normally we specify the policy in a data resource. If there is no state file present, Terraform cannot always determine the value of the data resource (because there is no state yet) and fails the plan.

In this specific situation this can be fixed by "hardcoding" the check if the policy has to be created, basically "helping" terraform with the plan... (See Issue links below for more (detailed) context)

Example usage

module "my_role" {
  providers             = { aws = aws }
  source                = "github.com/schubergphilis/terraform-aws-mcaf-role?ref=v0.1.6"
  name                  = "Test"
  role_policy           = data.aws_iam_policy_document.redshift_spectrum_policy.json
  force_create_policy   = true 
}

The force_create_policy explicitly tells Terraform to create the role, removing the "cannot be determined" error

Issues:

@fatbasstard fatbasstard merged commit abf086b into master Oct 24, 2019
@svanharmelen svanharmelen deleted the fvb/terraform-count-hotfix branch October 24, 2019 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants