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

Attempt to fix Invalid for_each argument for var.custom_iam_policy_arns #11

Merged
merged 39 commits into from
Apr 22, 2022

Conversation

jamengual
Copy link
Contributor

@jamengual jamengual commented Apr 20, 2022

what

  • Attempt to fix dependency logic when policy is created at the same time as the lambda function
  • Expand tests to include an iam policy
  • Output IAM role name
  • Output IAM role ARN
  • Fix remaining test TestExamplesCompleteDisabled cc: @mcalhoun for guidance

why

  • The error message
╷
│ Error: Invalid for_each argument
│
│   on ../../iam-role.tf line 77, in resource "aws_iam_role_policy_attachment" "custom":77:   for_each   = local.enabled ? toset(var.custom_iam_policy_arns) : toset([])
│     ├────────────────
│     │ local.enabled is true
│     │ var.custom_iam_policy_arns is list of string with 2 elements
│
│ The "for_each" 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 for_each depends on.

Basically, we cannot pass in a policy arn that isn't already created.

We get around this in the test by creating a local input var for the policy name and pass that local to both the aws_iam_policy resource as well as the var.custom_iam_policy_arns of the module.

Another way around this is to attach the custom policies outside of this module by using the role_name output

references

@jamengual jamengual requested review from a team as code owners April 20, 2022 20:06
@jamengual
Copy link
Contributor Author

/test all

iam-role.tf Outdated Show resolved Hide resolved
variables.tf Outdated Show resolved Hide resolved
Copy link
Member

@nitrocode nitrocode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see comments

@jamengual
Copy link
Contributor Author

/test all

@jamengual
Copy link
Contributor Author

/test all

@nitrocode
Copy link
Member

/test all

@nitrocode nitrocode added the patch A minor, backward compatible change label Apr 21, 2022
@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/test test/terratest

@nitrocode
Copy link
Member

/test test/terratest

@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/test all

@nitrocode nitrocode requested a review from mcalhoun April 21, 2022 18:01
@nitrocode
Copy link
Member

/test all

@nitrocode
Copy link
Member

/test all

@nitrocode nitrocode merged commit cb734da into main Apr 22, 2022
@nitrocode nitrocode deleted the fix_custom_lambda_policy branch April 22, 2022 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch A minor, backward compatible change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants