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.72k stars 9.08k forks source link

[Bug]: Message: "$.network-function-groups: null found, array expected" even when there is a network function group defined #38255

Closed sameesin closed 4 weeks ago

sameesin commented 2 months ago

Terraform Core Version

1.9.1

AWS Provider Version

5.57.0

Affected Resource(s)

data source - "aws_networkmanager_core_network_policy_document"

data "aws_networkmanager_core_network_policy_document" "policy1" {
  core_network_configuration {
    asn_ranges = ["65022-65534"]

    edge_locations {
      location = "ap-south-1"
    }
  }

  segments {
    name = "segment1"
    require_attachment_acceptance = false
  }

  network_function_groups {
    name = "ftdgroup"
    require_attachment_acceptance = false
  }
}

Expected Behavior

The core network should get created but the code fails with an error stating incorrect policy

Actual Behavior

{ │ RespMetadata: { │ StatusCode: 400, │ RequestID: "<>" │ }, │ Errors: [{ │ ErrorCode: "TYPEMISMATCH", │ Message: "$.network-function-groups: null found, array expected", │ Path: "$.network-function-groups" │ }], │ Message: "Incorrect policy." │ }

Relevant Error/Panic Output Snippet

{
│   RespMetadata: {
│     StatusCode: 400,
│     RequestID: "<>"
│   },
│   Errors: [{
│       ErrorCode: "TYPE_MISMATCH",
│       Message: "$.network-function-groups: null found, array expected",
│       Path: "$.network-function-groups"
│     }],
│   Message_: "Incorrect policy."
│ }

Terraform Configuration Files

resource "aws_networkmanager_global_network" "cloudwan-automation-test" {
  description = "cloudwan-automation-test"
}

data "aws_networkmanager_core_network_policy_document" "policy1" {
  core_network_configuration {
    asn_ranges = ["65022-65534"]

    edge_locations {
      location = "ap-south-1"
    }
  }

  segments {
    name = "segment1"
    require_attachment_acceptance = false
  }

  network_function_groups {
    name = "ftdgroup"
    require_attachment_acceptance = false
  }
}

resource "aws_networkmanager_core_network" "core_network" {
  global_network_id = aws_networkmanager_global_network.cloudwan-automation-test.id
  create_base_policy = true
}

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.policy1.json
}

Steps to Reproduce

terraform init terraform plan --out t terraform apply t

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

github-actions[bot] commented 2 months ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

ddericco commented 1 month ago

I'm able to reproduce this using the configuration files provided by @sameesin. It looks like using the create_base_policy argument with no other arguments causes the provider to generate an invalid base policy.

Note this is also causing multiple acceptance test failures:

make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go1.22.5 test ./internal/service/networkmanager/... -v -count 1 -parallel 1 -run='TestAccNetworkManagerCoreNetwork_createBasePolicyDocument*'  -timeout 360m
=== RUN   TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion
=== PAUSE TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion
=== RUN   TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion
=== PAUSE TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion
=== RUN   TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithMultiRegion
=== PAUSE TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithMultiRegion
=== RUN   TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithPolicyDocument
=== PAUSE TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithPolicyDocument
=== CONT  TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion
    core_network_test.go:161: Step 1/2 error: Error running apply: exit status 1

        Error: creating Core Network: CoreNetworkPolicyException: Incorrect policy.
        {
          RespMetadata: {
            StatusCode: 400,
            RequestID: "dad105b7-d07d-43c8-90ef-9e039a62e05b"
          },
          Errors: [{
              ErrorCode: "TYPE_MISMATCH",
              Message: "$.network-function-groups: null found, array expected",
              Path: "$.network-function-groups"
            }],
          Message_: "Incorrect policy."
        }

          with aws_networkmanager_core_network.test,
          on terraform_plugin_test.tf line 14, in resource "aws_networkmanager_core_network" "test":
          14: resource "aws_networkmanager_core_network" "test" {

--- FAIL: TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion (11.52s)
=== CONT  TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithMultiRegion
    core_network_test.go:239: Step 1/2 error: Error running apply: exit status 1

        Error: creating Core Network: CoreNetworkPolicyException: Incorrect policy.
        {
          RespMetadata: {
            StatusCode: 400,
            RequestID: "43f62dae-fa67-4d83-81bb-fe9320adf038"
          },
          Errors: [{
              ErrorCode: "TYPE_MISMATCH",
              Message: "$.network-function-groups: null found, array expected",
              Path: "$.network-function-groups"
            }],
          Message_: "Incorrect policy."
        }

          with aws_networkmanager_core_network.test,
          on terraform_plugin_test.tf line 14, in resource "aws_networkmanager_core_network" "test":
          14: resource "aws_networkmanager_core_network" "test" {

--- FAIL: TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithMultiRegion (9.49s)
=== CONT  TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithPolicyDocument
=== CONT  TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion
--- PASS: TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithPolicyDocument (1488.82s)
=== NAME  TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion
    core_network_test.go:200: Step 1/2 error: Error running apply: exit status 1

        Error: creating Core Network: CoreNetworkPolicyException: Incorrect policy.
        {
          RespMetadata: {
            StatusCode: 400,
            RequestID: "95c44732-d429-463d-bd36-3c72459eb55e"
          },
          Errors: [{
              ErrorCode: "TYPE_MISMATCH",
              Message: "$.network-function-groups: null found, array expected",
              Path: "$.network-function-groups"
            }],
          Message_: "Incorrect policy."
        }

          with aws_networkmanager_core_network.test,
          on terraform_plugin_test.tf line 14, in resource "aws_networkmanager_core_network" "test":
          14: resource "aws_networkmanager_core_network" "test" {

--- FAIL: TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion (9.14s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-aws/internal/service/networkmanager     1524.612s
FAIL
make: *** [testacc] Error 1

Possible workarounds

  1. Use the base_policy_document argument in the aws_networkmanager_core_network resource to force the use of a working policy:

    resource "aws_networkmanager_core_network" "core_network" {
    global_network_id = aws_networkmanager_global_network.cloudwan-automation-test.id
    create_base_policy = true
    base_policy_document = data.aws_networkmanager_core_network_policy_document.policy1.json
    }
  2. Use the AWSCC provider and the corresponding resource type to create and manage the core network:

    resource "awscc_networkmanager_core_network" "example" {
    global_network_id = aws_networkmanager_global_network.cloudwan-automation-test.id
    description       = "example"
    }
github-actions[bot] commented 4 weeks 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 3 weeks ago

This functionality has been released in v5.62.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!