unfunco / terraform-aws-oidc-github

Terraform module to configure GitHub Actions as an IAM OIDC identity provider in AWS.
https://registry.terraform.io/modules/unfunco/oidc-github/aws/latest
Apache License 2.0
99 stars 54 forks source link

Using module with var.enabled=false throws an error #14

Closed mackenzie-oa closed 2 years ago

mackenzie-oa commented 2 years ago

Firstly thank you for this module - I got up and running with GHA way quicker and way easier than was reasonable to expect thanks to this module!

I'm struggling to use it my environment though when I try to set the enabled variable to false the module errors out. I have reproduced the error using the examples/complete directory. This is on 0.7.0.

I tried tweaking the create_oidc_provider variable to false as well, but that hasn't helped.

$ cd examples/complete
$ terraform init -reconfigure 
$ terraform plan -var=region=us-east-1 -var='github_repositories=["invalid/example"]' -var=enabled=true

<snip>
Plan: 3 to add, 0 to change, 0 to destroy.
<snip>

$ terraform plan -var=region=us-east-1 -var='github_repositories=["invalid/example"]' -var=enabled=false
╷
│ Error: Invalid index
│
│   on ../../main.tf line 17, in locals:
│   17:   oidc_provider_arn    = var.create_oidc_provider ? aws_iam_openid_connect_provider.github[0].arn : data.aws_iam_openid_connect_provider.github[0].arn
│     ├────────────────
│     │ aws_iam_openid_connect_provider.github is empty tuple
│
│ The given key does not identify an element in this collection value: the collection has no elements.
╵
unfunco commented 2 years ago

Hello @mackenzie-oa, thank you for finding/reporting this bug. I have implemented a fix in #15 and have released v0.8.0 which contains the fix.

mackenzie-oa commented 2 years ago

Thank you so much for the quick fix @unfunco - I can confirm you have fixed the bug 👍