Skip to content

Commit

Permalink
Merge pull request #38013 from hashicorp/f-d/aws_networkmanager_core_…
Browse files Browse the repository at this point in the history
…network_policy_document-service-insertion

d/aws_networkmanager_core_network_policy_document: Add support for service insertion
  • Loading branch information
ewbankkit committed Jun 17, 2024
2 parents 9f3dbf4 + e35577c commit 11055cc
Show file tree
Hide file tree
Showing 7 changed files with 848 additions and 433 deletions.
23 changes: 23 additions & 0 deletions .changelog/38013.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
```release-note:enhancement
data-source/aws_networkmanager_core_network_policy_document: Add `attachment_policies.action.add_to_network_function_group` argument
```

```release-note:enhancement
data-source/aws_networkmanager_core_network_policy_document: Add `send-via` and `send-to` as valid values for `segment_actions.action`
```

```release-note:enhancement
data-source/aws_networkmanager_core_network_policy_document: Add `single-hop` and `dual-hop` as valid values for `segment_actions.mode`
```

```release-note:enhancement
data-source/aws_networkmanager_core_network_policy_document: Add `when_sent_to` and `via` configuration blocks to `segment_actions`
```

```release-note:bug
data-source/aws_networkmanager_core_network_policy_document: Add correct `except` values to the returned JSON document when `segment_actions.share_with_except` is configured
```

```release-note:enhancement
data-source/aws_networkmanager_core_network_policy_document: Add `network_function_groups` configuration block
```
26 changes: 8 additions & 18 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,23 +652,13 @@ func CheckResourceAttrRFC3339(resourceName, attributeName string) resource.TestC
return resource.TestMatchResourceAttr(resourceName, attributeName, regexache.MustCompile(RFC3339RegexPattern))
}

// CheckResourceAttrEquivalentJSON is a TestCheckFunc that compares a JSON value with an expected value. Both JSON
// values are normalized before being compared.
func CheckResourceAttrEquivalentJSON(resourceName, attributeName, expectedJSON string) resource.TestCheckFunc {
return func(s *terraform.State) error {
is, err := PrimaryInstanceState(s, resourceName)
if err != nil {
return err
}

v, ok := is.Attributes[attributeName]
if !ok {
return fmt.Errorf("%s: No attribute %q found", resourceName, attributeName)
}

vNormal, err := structure.NormalizeJsonString(v)
// CheckResourceAttrEquivalentJSON is a TestCheckFunc that compares a JSON value with an expected value.
// Both JSON values are normalized before being compared.
func CheckResourceAttrEquivalentJSON(n, key, expectedJSON string) resource.TestCheckFunc {
return resource.TestCheckResourceAttrWith(n, key, func(value string) error {
vNormal, err := structure.NormalizeJsonString(value)
if err != nil {
return fmt.Errorf("%s: Error normalizing JSON in %q: %w", resourceName, attributeName, err)
return fmt.Errorf("%s: Error normalizing JSON in %q: %w", n, key, err)
}

expectedNormal, err := structure.NormalizeJsonString(expectedJSON)
Expand All @@ -677,10 +667,10 @@ func CheckResourceAttrEquivalentJSON(resourceName, attributeName, expectedJSON s
}

if vNormal != expectedNormal {
return fmt.Errorf("%s: Attribute %q expected\n%s\ngot\n%s", resourceName, attributeName, expectedJSON, v)
return fmt.Errorf("%s: Attribute %q expected\n%s\ngot\n%s", n, key, expectedJSON, value)
}
return nil
}
})
}

func CheckResourceAttrJMES(name, key, jmesPath, value string) resource.TestCheckFunc {
Expand Down
12 changes: 6 additions & 6 deletions internal/service/networkmanager/core_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,18 +625,18 @@ func waitCoreNetworkPolicyCreated(ctx context.Context, conn *networkmanager.Netw

// buildCoreNetworkBasePolicyDocument returns a base policy document
func buildCoreNetworkBasePolicyDocument(regions []interface{}) (string, error) {
edgeLocations := make([]*CoreNetworkEdgeLocation, len(regions))
edgeLocations := make([]*coreNetworkPolicyCoreNetworkEdgeLocation, len(regions))
for i, location := range regions {
edgeLocations[i] = &CoreNetworkEdgeLocation{Location: location.(string)}
edgeLocations[i] = &coreNetworkPolicyCoreNetworkEdgeLocation{Location: location.(string)}
}

basePolicy := &CoreNetworkPolicyDoc{
basePolicy := &coreNetworkPolicyDocument{
Version: "2021.12",
CoreNetworkConfiguration: &CoreNetworkPolicyCoreNetworkConfiguration{
AsnRanges: CoreNetworkPolicyDecodeConfigStringList([]interface{}{"64512-65534"}),
CoreNetworkConfiguration: &coreNetworkPolicyCoreNetworkConfiguration{
AsnRanges: coreNetworkPolicyExpandStringList([]interface{}{"64512-65534"}),
EdgeLocations: edgeLocations,
},
Segments: []*CoreNetworkPolicySegment{
Segments: []*coreNetworkPolicySegment{
{
Name: "segment",
Description: "base-policy",
Expand Down
Loading

0 comments on commit 11055cc

Please sign in to comment.