hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.83k stars 9.17k forks source link

[Docs]: It is not clear how to supply a list of cidr_blocks #33574

Open EugenKon opened 1 year ago

EugenKon commented 1 year ago

Documentation Link

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule#example-usage

Description

What is the docs issue?

It is not clear how to provide cidr_blocks.

should it be ["0.0.0.0/0, 192.168.0.0/16"] or ["0.0.0.0/0", "192.168.0.0/16"]

Proposal

Provide example how it should look like.

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

michal-zubac-auriga commented 1 year ago

What adds to confusion is my experience, that cidr_blocks can only contain only 1 entry in the list. For multiple items apply operation fails. AWS API does not seem to really support multiple CIDR entries in security group rule object. You must create multiple security group rule resources.

I have these thoughts related to this:

References:

EugenKon commented 1 year ago

For my project I did this and it works fine:

cidr_blocks     = split(",", var.allowlist_ip)

Where allowlist_ip = "1.1.1.1/32,2.2.2.2/32"

michal-zubac-auriga commented 1 year ago

@EugenKon, thanks for your angle.

I looked at sources and it seems TF module supports multiple items to be passed as list. It seems that AWS API accepts comma separated string as input, but internally it creates multiple SG rules from this input.

Where I hit the issue was subsequent change of codebase, where I added more items to the list. From TF data model it seemed like multiple CIDRS are attribute of 1 SG rule object, but in reality multiple SG rules were created. TF does not seem to handle this situation.

@EugenKon I believe if you changed the allowlist_ip your apply would fail. What is your experience?

EugenKon commented 1 year ago

@michal-zubac-auriga I'll check that when possible.