Skip to content

Commit d5e9e20

Browse files
authored
Merge pull request #30875 from hashicorp/t-nm-core-remove-policy-doc
networkmanager/core: Remove `policy_document` arg
2 parents 16b72ad + 52d30ea commit d5e9e20

File tree

5 files changed

+12
-170
lines changed

5 files changed

+12
-170
lines changed

.changelog/30875.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:breaking-change
2+
resource/aws_networkmanager_core_network: Removed `policy_document` argument -- use `aws_networkmanager_core_network_policy_attachment` resource instead
3+
```
4+
5+
```release-note:note
6+
resource/aws_networkmanager_core_network: Update configurations to use the `aws_networkmanager_core_network_policy_attachment` resource instead of the `policy_document` argument
7+
```

internal/service/networkmanager/core_network.go

+4-73
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ import (
1212
"github.com/aws/aws-sdk-go/service/networkmanager"
1313
"github.com/hashicorp/aws-sdk-go-base/v2/awsv1shim/v2/tfawserr"
1414
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
15-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
1615
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/id"
1716
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/retry"
1817
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
19-
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure"
2018
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
2119
"github.com/hashicorp/terraform-provider-aws/internal/conns"
2220
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
@@ -43,10 +41,7 @@ func ResourceCoreNetwork() *schema.Resource {
4341
StateContext: schema.ImportStatePassthroughContext,
4442
},
4543

46-
CustomizeDiff: customdiff.Sequence(
47-
resourceCoreNetworkCustomizeDiff,
48-
verify.SetTagsDiff,
49-
),
44+
CustomizeDiff: verify.SetTagsDiff,
5045

5146
Timeouts: &schema.ResourceTimeout{
5247
Create: schema.DefaultTimeout(30 * time.Minute),
@@ -77,10 +72,9 @@ func ResourceCoreNetwork() *schema.Resource {
7772
ConflictsWith: []string{"base_policy_region"},
7873
},
7974
"create_base_policy": {
80-
Type: schema.TypeBool,
81-
Optional: true,
82-
Default: false,
83-
ConflictsWith: []string{"policy_document"},
75+
Type: schema.TypeBool,
76+
Optional: true,
77+
Default: false,
8478
},
8579
"created_at": {
8680
Type: schema.TypeString,
@@ -118,23 +112,6 @@ func ResourceCoreNetwork() *schema.Resource {
118112
ForceNew: true,
119113
ValidateFunc: validation.StringLenBetween(0, 50),
120114
},
121-
"policy_document": {
122-
Deprecated: "Use the aws_networkmanager_core_network_policy_attachment resource instead. " +
123-
"This attribute will be removed in the next major version of the provider.",
124-
Type: schema.TypeString,
125-
Optional: true,
126-
Computed: true,
127-
ValidateFunc: validation.All(
128-
validation.StringLenBetween(0, 10000000),
129-
validation.StringIsJSON,
130-
),
131-
DiffSuppressFunc: verify.SuppressEquivalentJSONDiffs,
132-
StateFunc: func(v interface{}) string {
133-
json, _ := structure.NormalizeJsonString(v)
134-
return json
135-
},
136-
ConflictsWith: []string{"create_base_policy"},
137-
},
138115
"segments": {
139116
Type: schema.TypeList,
140117
Computed: true,
@@ -181,14 +158,9 @@ func resourceCoreNetworkCreate(ctx context.Context, d *schema.ResourceData, meta
181158
input.Description = aws.String(v.(string))
182159
}
183160

184-
if v, ok := d.GetOk("policy_document"); ok {
185-
input.PolicyDocument = aws.String(v.(string))
186-
}
187-
188161
// check if the user wants to create a base policy document
189162
// this creates the core network with a starting policy document set to LIVE
190163
// this is required for the first terraform apply if there attachments to the core network
191-
// and the core network is created without the policy_document argument set
192164
if _, ok := d.GetOk("create_base_policy"); ok {
193165
// if user supplies a region or multiple regions use it in the base policy, otherwise use current region
194166
regions := []interface{}{meta.(*conns.AWSClient).Region}
@@ -251,24 +223,6 @@ func resourceCoreNetworkRead(ctx context.Context, d *schema.ResourceData, meta i
251223
}
252224
d.Set("state", coreNetwork.State)
253225

254-
// getting the policy document uses a different API call
255-
// policy document is also optional
256-
coreNetworkPolicy, err := FindCoreNetworkPolicyByID(ctx, conn, d.Id())
257-
258-
if tfresource.NotFound(err) {
259-
d.Set("policy_document", nil)
260-
} else if err != nil {
261-
return diag.Errorf("reading Network Manager Core Network (%s) policy: %s", d.Id(), err)
262-
} else {
263-
encodedPolicyDocument, err := protocol.EncodeJSONValue(coreNetworkPolicy.PolicyDocument, protocol.NoEscape)
264-
265-
if err != nil {
266-
return diag.Errorf("encoding Network Manager Core Network (%s) policy document: %s", d.Id(), err)
267-
}
268-
269-
d.Set("policy_document", encodedPolicyDocument)
270-
}
271-
272226
SetTagsOut(ctx, coreNetwork.Tags)
273227

274228
return nil
@@ -292,18 +246,6 @@ func resourceCoreNetworkUpdate(ctx context.Context, d *schema.ResourceData, meta
292246
}
293247
}
294248

295-
if d.HasChange("policy_document") {
296-
err := PutAndExecuteCoreNetworkPolicy(ctx, conn, d.Id(), d.Get("policy_document").(string))
297-
298-
if err != nil {
299-
return diag.FromErr(err)
300-
}
301-
302-
if _, err := waitCoreNetworkUpdated(ctx, conn, d.Id(), d.Timeout(schema.TimeoutUpdate)); err != nil {
303-
return diag.Errorf("waiting for Network Manager Core Network (%s) update: %s", d.Id(), err)
304-
}
305-
}
306-
307249
if d.HasChange("create_base_policy") {
308250
if _, ok := d.GetOk("create_base_policy"); ok {
309251
// if user supplies a region or multiple regions use it in the base policy, otherwise use current region
@@ -358,17 +300,6 @@ func resourceCoreNetworkDelete(ctx context.Context, d *schema.ResourceData, meta
358300
return nil
359301
}
360302

361-
func resourceCoreNetworkCustomizeDiff(_ context.Context, d *schema.ResourceDiff, meta interface{}) error {
362-
if d.HasChange("policy_document") {
363-
if o, n := d.GetChange("policy_document"); !verify.JSONStringsEqual(o.(string), n.(string)) {
364-
d.SetNewComputed("edges")
365-
d.SetNewComputed("segments")
366-
}
367-
}
368-
369-
return nil
370-
}
371-
372303
func FindCoreNetworkByID(ctx context.Context, conn *networkmanager.NetworkManager, id string) (*networkmanager.CoreNetwork, error) {
373304
input := &networkmanager.GetCoreNetworkInput{
374305
CoreNetworkId: aws.String(id),

internal/service/networkmanager/core_network_test.go

-91
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestAccNetworkManagerCoreNetwork_basic(t *testing.T) {
3333
resource.TestCheckResourceAttrSet(resourceName, "created_at"),
3434
resource.TestCheckResourceAttr(resourceName, "description", ""),
3535
resource.TestMatchResourceAttr(resourceName, "id", regexp.MustCompile(`core-network-.+`)),
36-
resource.TestCheckResourceAttr(resourceName, "policy_document", ""),
3736
resource.TestCheckResourceAttr(resourceName, "state", networkmanager.CoreNetworkStateAvailable),
3837
resource.TestCheckResourceAttr(resourceName, "tags.%", "0"),
3938
),
@@ -151,64 +150,6 @@ func TestAccNetworkManagerCoreNetwork_description(t *testing.T) {
151150
})
152151
}
153152

154-
func TestAccNetworkManagerCoreNetwork_policyDocument(t *testing.T) {
155-
ctx := acctest.Context(t)
156-
resourceName := "aws_networkmanager_core_network.test"
157-
originalSegmentValue := "segmentValue1"
158-
updatedSegmentValue := "segmentValue2"
159-
160-
resource.ParallelTest(t, resource.TestCase{
161-
PreCheck: func() { acctest.PreCheck(ctx, t) },
162-
ErrorCheck: acctest.ErrorCheck(t, networkmanager.EndpointsID),
163-
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
164-
CheckDestroy: testAccCheckCoreNetworkDestroy(ctx),
165-
Steps: []resource.TestStep{
166-
{
167-
Config: testAccCoreNetworkConfig_policyDocument(originalSegmentValue),
168-
Check: resource.ComposeTestCheckFunc(
169-
testAccCheckCoreNetworkExists(ctx, resourceName),
170-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"65022-65534\"],\"edge-locations\":[{\"location\":\"%s\"}],\"vpn-ecmp-support\":true},\"segments\":[{\"isolate-attachments\":false,\"name\":\"%s\",\"require-attachment-acceptance\":true}],\"version\":\"2021.12\"}", acctest.Region(), originalSegmentValue)),
171-
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "edges.*", map[string]string{
172-
"asn": "65022",
173-
"edge_location": acctest.Region(),
174-
"inside_cidr_blocks.#": "0",
175-
}),
176-
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "segments.*", map[string]string{
177-
"edge_locations.#": "1",
178-
"edge_locations.0": acctest.Region(),
179-
"name": originalSegmentValue,
180-
"shared_segments.#": "0",
181-
}),
182-
),
183-
},
184-
{
185-
ResourceName: resourceName,
186-
ImportState: true,
187-
ImportStateVerify: true,
188-
ImportStateVerifyIgnore: []string{"create_base_policy"},
189-
},
190-
{
191-
Config: testAccCoreNetworkConfig_policyDocument(updatedSegmentValue),
192-
Check: resource.ComposeTestCheckFunc(
193-
testAccCheckCoreNetworkExists(ctx, resourceName),
194-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"65022-65534\"],\"edge-locations\":[{\"location\":\"%s\"}],\"vpn-ecmp-support\":true},\"segments\":[{\"isolate-attachments\":false,\"name\":\"%s\",\"require-attachment-acceptance\":true}],\"version\":\"2021.12\"}", acctest.Region(), updatedSegmentValue)),
195-
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "edges.*", map[string]string{
196-
"asn": "65022",
197-
"edge_location": acctest.Region(),
198-
"inside_cidr_blocks.#": "0",
199-
}),
200-
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "segments.*", map[string]string{
201-
"edge_locations.#": "1",
202-
"edge_locations.0": acctest.Region(),
203-
"name": updatedSegmentValue,
204-
"shared_segments.#": "0",
205-
}),
206-
),
207-
},
208-
},
209-
})
210-
}
211-
212153
func TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion(t *testing.T) {
213154
ctx := acctest.Context(t)
214155
resourceName := "aws_networkmanager_core_network.test"
@@ -224,7 +165,6 @@ func TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithoutRegion(t *t
224165
Check: resource.ComposeTestCheckFunc(
225166
testAccCheckCoreNetworkExists(ctx, resourceName),
226167
resource.TestCheckResourceAttr(resourceName, "create_base_policy", "true"),
227-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"64512-65534\"],\"edge-locations\":[{\"location\":\"%s\"}],\"vpn-ecmp-support\":false},\"segments\":[{\"description\":\"base-policy\",\"isolate-attachments\":false,\"name\":\"segment\",\"require-attachment-acceptance\":false}],\"version\":\"2021.12\"}", acctest.Region())),
228168
resource.TestCheckNoResourceAttr(resourceName, "base_policy_region"),
229169
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "edges.*", map[string]string{
230170
"asn": "64512",
@@ -264,7 +204,6 @@ func TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithRegion(t *test
264204
Check: resource.ComposeTestCheckFunc(
265205
testAccCheckCoreNetworkExists(ctx, resourceName),
266206
resource.TestCheckResourceAttr(resourceName, "create_base_policy", "true"),
267-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"64512-65534\"],\"edge-locations\":[{\"location\":\"%s\"}],\"vpn-ecmp-support\":false},\"segments\":[{\"description\":\"base-policy\",\"isolate-attachments\":false,\"name\":\"segment\",\"require-attachment-acceptance\":false}],\"version\":\"2021.12\"}", acctest.AlternateRegion())),
268207
resource.TestCheckResourceAttr(resourceName, "base_policy_region", acctest.AlternateRegion()),
269208
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "edges.*", map[string]string{
270209
"asn": "64512",
@@ -304,9 +243,6 @@ func TestAccNetworkManagerCoreNetwork_createBasePolicyDocumentWithMultiRegion(t
304243
Check: resource.ComposeTestCheckFunc(
305244
testAccCheckCoreNetworkExists(ctx, resourceName),
306245
resource.TestCheckResourceAttr(resourceName, "create_base_policy", "true"),
307-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"64512-65534\"],\"edge-locations\":[{\"location\":\"%s\"},{\"location\":\"%s\"}],\"vpn-ecmp-support\":false},\"segments\":[{\"description\":\"base-policy\",\"isolate-attachments\":false,\"name\":\"segment\",\"require-attachment-acceptance\":false}],\"version\":\"2021.12\"}", acctest.AlternateRegion(), acctest.Region())),
308-
// use test below if locations are unordered
309-
// resource.TestMatchResourceAttr(resourceName, "policy_document", regexp.MustCompile(`{"core-network-configuration":{"asn-ranges":\["64512-65534"\],"edge-locations":\[{"location":".+"},{"location":".+"}\],"vpn-ecmp-support":false},"segments":\[{"description":"base-policy","isolate-attachments":false,"name":"segment","require-attachment-acceptance":false}\],"version":"2021.12"}`)),
310246
resource.TestCheckResourceAttr(resourceName, "base_policy_regions.#", "2"),
311247
resource.TestCheckTypeSetElemAttr(resourceName, "base_policy_regions.*", acctest.AlternateRegion()),
312248
resource.TestCheckTypeSetElemAttr(resourceName, "base_policy_regions.*", acctest.Region()),
@@ -351,7 +287,6 @@ func TestAccNetworkManagerCoreNetwork_withoutPolicyDocumentUpdateToCreateBasePol
351287
Config: testAccCoreNetworkConfig_basic(),
352288
Check: resource.ComposeTestCheckFunc(
353289
testAccCheckCoreNetworkExists(ctx, resourceName),
354-
resource.TestCheckResourceAttr(resourceName, "policy_document", ""),
355290
),
356291
},
357292
{
@@ -365,7 +300,6 @@ func TestAccNetworkManagerCoreNetwork_withoutPolicyDocumentUpdateToCreateBasePol
365300
Check: resource.ComposeTestCheckFunc(
366301
testAccCheckCoreNetworkExists(ctx, resourceName),
367302
resource.TestCheckResourceAttr(resourceName, "create_base_policy", "true"),
368-
resource.TestCheckResourceAttr(resourceName, "policy_document", fmt.Sprintf("{\"core-network-configuration\":{\"asn-ranges\":[\"64512-65534\"],\"edge-locations\":[{\"location\":\"%s\"}],\"vpn-ecmp-support\":false},\"segments\":[{\"description\":\"base-policy\",\"isolate-attachments\":false,\"name\":\"segment\",\"require-attachment-acceptance\":false}],\"version\":\"2021.12\"}", acctest.Region())),
369303
resource.TestCheckNoResourceAttr(resourceName, "base_policy_region"),
370304
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "edges.*", map[string]string{
371305
"asn": "64512",
@@ -478,31 +412,6 @@ resource "aws_networkmanager_core_network" "test" {
478412
`, description)
479413
}
480414

481-
func testAccCoreNetworkConfig_policyDocument(segmentValue string) string {
482-
return fmt.Sprintf(`
483-
resource "aws_networkmanager_global_network" "test" {}
484-
485-
data "aws_networkmanager_core_network_policy_document" "test" {
486-
core_network_configuration {
487-
asn_ranges = ["65022-65534"]
488-
489-
edge_locations {
490-
location = %[2]q
491-
}
492-
}
493-
494-
segments {
495-
name = %[1]q
496-
}
497-
}
498-
499-
resource "aws_networkmanager_core_network" "test" {
500-
global_network_id = aws_networkmanager_global_network.test.id
501-
policy_document = data.aws_networkmanager_core_network_policy_document.test.json
502-
}
503-
`, segmentValue, acctest.Region())
504-
}
505-
506415
func testAccCoreNetworkConfig_basePolicyDocumentWithoutRegion() string {
507416
return `
508417
resource "aws_networkmanager_global_network" "test" {}

website/docs/r/networkmanager_core_network.html.markdown

+1-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ description: |-
1010

1111
Provides a core network resource.
1212

13-
~> **NOTE on Core Networks and Policy Attachments:** For a given core network, this resource's `policy_document` argument is incompatible with using the [`aws_networkmanager_core_network_policy_attachment` resource](/docs/providers/aws/r/networkmanager_core_network_policy_attachment.html). When using this resource's `policy_document` argument and the `aws_networkmanager_core_network_policy_attachment` resource, both will attempt to manage the core network's policy document and Terraform will show a permanent difference.
14-
1513
## Example Usage
1614

1715
### Basic
@@ -176,7 +174,7 @@ The following arguments are supported:
176174
* `description` - (Optional) Description of the Core Network.
177175
* `base_policy_region` - (Optional, **Deprecated** use the `base_policy_regions` argument instead) The base policy created by setting the `create_base_policy` argument to `true` requires a region to be set in the `edge-locations`, `location` key. If `base_policy_region` is not specified, the region used in the base policy defaults to the region specified in the `provider` block.
178176
* `base_policy_regions` - (Optional) A list of regions to add to the base policy. The base policy created by setting the `create_base_policy` argument to `true` requires one or more regions to be set in the `edge-locations`, `location` key. If `base_policy_regions` is not specified, the region used in the base policy defaults to the region specified in the `provider` block.
179-
* `create_base_policy` - (Optional) Specifies whether to create a base policy when a core network is created or updated. A base policy is created and set to `LIVE` to allow attachments to the core network (e.g. VPC Attachments) before applying a policy document provided using the [`aws_networkmanager_core_network_policy_attachment` resource](/docs/providers/aws/r/networkmanager_core_network_policy_attachment.html). This base policy is needed if your core network does not have any `LIVE` policies (e.g. a core network resource created without the `policy_document` argument) and your policy document has static routes pointing to VPC attachments and you want to attach your VPCs to the core network before applying the desired policy document. Valid values are `true` or `false`. Conflicts with `policy_document`. An example of this Terraform snippet can be found above [for VPC Attachment in a single region](#with-vpc-attachment-single-region) and [for VPC Attachment multi-region](#with-vpc-attachment-multi-region). An example base policy is shown below. This base policy is overridden with the policy that you specify in the [`aws_networkmanager_core_network_policy_attachment` resource](/docs/providers/aws/r/networkmanager_core_network_policy_attachment.html).
177+
* `create_base_policy` - (Optional) Specifies whether to create a base policy when a core network is created or updated. A base policy is created and set to `LIVE` to allow attachments to the core network (e.g. VPC Attachments) before applying a policy document provided using the [`aws_networkmanager_core_network_policy_attachment` resource](/docs/providers/aws/r/networkmanager_core_network_policy_attachment.html). This base policy is needed if your core network does not have any `LIVE` policies and your policy document has static routes pointing to VPC attachments and you want to attach your VPCs to the core network before applying the desired policy document. Valid values are `true` or `false`. An example of this Terraform snippet can be found above [for VPC Attachment in a single region](#with-vpc-attachment-single-region) and [for VPC Attachment multi-region](#with-vpc-attachment-multi-region). An example base policy is shown below. This base policy is overridden with the policy that you specify in the [`aws_networkmanager_core_network_policy_attachment` resource](/docs/providers/aws/r/networkmanager_core_network_policy_attachment.html).
180178

181179
```json
182180
{
@@ -204,7 +202,6 @@ The following arguments are supported:
204202
```
205203

206204
* `global_network_id` - (Required) The ID of the global network that a core network will be a part of.
207-
* `policy_document` - (Optional, **Deprecated** use the [`aws_networkmanager_core_network_policy_attachment`](networkmanager_core_network_policy_attachment.html) resource instead) Policy document for creating a core network. Note that updating this argument will result in the new policy document version being set as the `LATEST` and `LIVE` policy document. Refer to the [Core network policies documentation](https://docs.aws.amazon.com/network-manager/latest/cloudwan/cloudwan-policy-change-sets.html) for more information. Conflicts with `create_base_policy`.
208205
* `tags` - (Optional) Key-value tags for the Core Network. If configured with a provider [`default_tags` configuration block](https://registry.terraform.io/providers/hashicorp/aws/latest/docs#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level.
209206

210207
## Timeouts

0 commit comments

Comments
 (0)