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.77k stars 9.12k forks source link

[Bug]: network-function-groups wildcard fails in data source aws_networkmanager_core_network_policy_document #38145

Closed sgreathouse-rgare closed 2 months ago

sgreathouse-rgare commented 3 months ago

Terraform Core Version

1.8.5

AWS Provider Version

5.55.0

Affected Resource(s)

Wildcard for segments fails in network_function_groups.

json version works:

"segment-actions": [
  {
    "action": "send-via",
    "segment": "production",
    "mode": "single-hop",
    "when-sent-to": {
      "segments": "*"
    },
    "via": {
      "network-function-groups": [
        "inspection"
      ]
    }
  }
]

tf version fails in data.aws_networkmanager_core_network_policy_document

segment_actions {
    action = "send-via"
    segment = "prouction"
    mode = "single-hop"
    when_sent_to {
      segments = "*"
    }
    via {
      network_function_groups = ["inspection"]
   }
  }

with Terraform error:

Error: Incorrect attribute value type
  on policy_document.tf line 94, in data "aws_networkmanager_core_network_policy_document" "this":
  94:       segments = "*"
Inappropriate value for attribute "segments": set of string required.

placing the wildcard in brackets ["*"] fails with AWS API error:

Error: putting Network Manager Core Network (core-network-01e65ecf64c59aca1) policy: CoreNetworkPolicyException: Incorrect policy.
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "6cbbef9d-64bf-4872-8012-95d1513e206f"
  },
  Errors: [
    {
      ErrorCode: "TYPE_MISMATCH",
      Message: "$.segment-actions[0].when-sent-to.segments: array found, object expected",
      Path: "$.segment-actions[0].when-sent-to.segments"
    },
    {
      ErrorCode: "TYPE_MISMATCH",
      Message: "$.segment-actions[0].when-sent-to.segments: array found, string expected",
      Path: "$.segment-actions[0].when-sent-to.segments"
    },
    {
      ErrorCode: "CONSTANT_VIOLATION",
      Message: "$.segment-actions[0].when-sent-to.segments: send-via segments only accept wildcard \"*\" as a string",
      Path: "$.segment-actions[0].when-sent-to.segments"
    },
    {
      ErrorCode: "INVALID_STRING",
      Message: "$.segment-actions[0].when-sent-to.segments[0]: segment names must start with a letter, be less than 64 characters long in length, and may include \"a..z\", \"A..Z\", or, \"0..9\"",
      Path: "$.segment-actions[0].when-sent-to.segments[0]"
    }
  ],
  Message_: "Incorrect policy."
}
with aws_networkmanager_core_network_policy_attachment.policy_attachment,
on core_network.tf line 12, in resource "aws_networkmanager_core_network_policy_attachment" "policy_attachment":
12: resource "aws_networkmanager_core_network_policy_attachment" "policy_attachment" 

as do other variants:

segments = *
segments = [*]

Expected Behavior

It should work like the json version

Actual Behavior

errors, as shown above

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

see below

Steps to Reproduce

Convert any module using service insertion via json:

resource "aws_networkmanager_core_network_policy_attachment" "policy_attachment" {
  core_network_id = aws_networkmanager_core_network.core_network.id
  policy_document = jsonencode(jsondecode(file("${path.module}/policy_document.json")))
}

That contains a wildcard in send-via

"segment-actions": [
  {
    "action": "send-via",
    "segment": "production",
    "mode": "single-hop",
    "when-sent-to": {
      "segments": "*"
    },
    "via": {
      "network-function-groups": [
        "inspection"
      ]
    }
  }
]

To use data.aws_networkmanager_core_network_policy_document

resource "aws_networkmanager_core_network_policy_attachment" "policy_attachment" {
  core_network_id = aws_networkmanager_core_network.core_network.id
  policy_document = data.aws_networkmanager_core_network_policy_document.this.json
}

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

Relates https://github.com/hashicorp/terraform-provider-aws/pull/38013. Relates https://github.com/hashicorp/terraform-provider-aws/issues/38134.

Would you like to implement a fix?

None

github-actions[bot] commented 3 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ewbankkit commented 3 months ago

We'll probably have to apply the same custom marshaling logic as for share-with:

    if v := c.ShareWith; v != nil {
        v := v.([]string)
        if v[0] == "*" {
            share = v[0]
        } else {
            share = v
        }
    }
sgreathouse-rgare commented 2 months ago

@ewbankkit Any updates or ETA on this issue?

github-actions[bot] commented 2 months ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 2 months ago

[!WARNING] This issue has been closed, meaning that any additional comments are hard for our team to see. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

github-actions[bot] commented 2 months ago

This functionality has been released in v5.61.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

github-actions[bot] commented 1 month ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.