Skip to content

Commit a966be3

Browse files
authored
fix: examples for awscc_networkmanager_vpc_attachment (#2797)
1 parent 2993aec commit a966be3

File tree

2 files changed

+91
-117
lines changed

2 files changed

+91
-117
lines changed

docs/resources/networkmanager_vpc_attachment.md

Lines changed: 45 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,46 @@ This example demonstrates how to attach a VPC to an AWS Network Manager Core Net
2222
data "aws_caller_identity" "current" {}
2323
data "aws_region" "current" {}
2424
25-
# Create VPC and subnets
25+
locals {
26+
account_id = data.aws_caller_identity.current.account_id
27+
region = data.aws_region.current.name
28+
}
29+
30+
resource "awscc_networkmanager_global_network" "example" {
31+
description = "Example Global Network"
32+
tags = [{
33+
key = "Modified By"
34+
value = "AWSCC"
35+
}]
36+
}
37+
38+
# Core Network - segment-actions cannot reference attachment IDs during creation
39+
# as attachments don't exist yet. This creates circular dependencies on both
40+
# create and destroy operations. Use blackhole or add segment-actions later.
41+
resource "awscc_networkmanager_core_network" "example" {
42+
description = "Example Core Network"
43+
global_network_id = awscc_networkmanager_global_network.example.id
44+
policy_document = jsonencode({
45+
"version" : "2021.12",
46+
"core-network-configuration" : {
47+
"vpn-ecmp-support" : true,
48+
"asn-ranges" : ["64512-65534"],
49+
"edge-locations" : [{
50+
"location" : local.region
51+
}]
52+
},
53+
"segments" : [{
54+
"name" : "shared",
55+
"description" : "Segment for shared services",
56+
"require-attachment-acceptance" : false
57+
}]
58+
})
59+
tags = [{
60+
key = "Modified By"
61+
value = "AWSCC"
62+
}]
63+
}
64+
2665
resource "awscc_ec2_vpc" "example" {
2766
cidr_block = "10.0.0.0/16"
2867
tags = [{
@@ -34,7 +73,7 @@ resource "awscc_ec2_vpc" "example" {
3473
resource "awscc_ec2_subnet" "example_subnet1" {
3574
vpc_id = awscc_ec2_vpc.example.id
3675
cidr_block = "10.0.1.0/24"
37-
availability_zone = "${data.aws_region.current.name}a"
76+
availability_zone = "${local.region}a"
3877
tags = [{
3978
key = "Name"
4079
value = "example-subnet-1"
@@ -44,71 +83,19 @@ resource "awscc_ec2_subnet" "example_subnet1" {
4483
resource "awscc_ec2_subnet" "example_subnet2" {
4584
vpc_id = awscc_ec2_vpc.example.id
4685
cidr_block = "10.0.2.0/24"
47-
availability_zone = "${data.aws_region.current.name}b"
86+
availability_zone = "${local.region}b"
4887
tags = [{
4988
key = "Name"
5089
value = "example-subnet-2"
5190
}]
5291
}
5392
54-
# Create Network Manager resources
55-
resource "awscc_networkmanager_global_network" "example" {
56-
description = "Example Global Network"
57-
tags = [{
58-
key = "Modified By"
59-
value = "AWSCC"
60-
}]
61-
}
62-
63-
resource "awscc_networkmanager_core_network" "example" {
64-
description = "Example Core Network"
65-
global_network_id = awscc_networkmanager_global_network.example.id
66-
policy_document = jsonencode({
67-
"version" : "2021.12",
68-
"core-network-configuration" : {
69-
"vpn-ecmp-support" : true,
70-
"asn-ranges" : [
71-
"64512-65534"
72-
],
73-
"edge-locations" : [
74-
{
75-
"location" : data.aws_region.current.name
76-
}
77-
]
78-
},
79-
"segments" : [
80-
{
81-
"name" : "shared",
82-
"description" : "Segment for shared services",
83-
"require-attachment-acceptance" : false
84-
}
85-
],
86-
"segment-actions" : [
87-
{
88-
"action" : "create-route",
89-
"destination-cidr-blocks" : [
90-
"0.0.0.0/0"
91-
],
92-
"destinations" : [
93-
"attachment"
94-
],
95-
"segment" : "shared"
96-
}
97-
]
98-
})
99-
tags = [{
100-
key = "Modified By"
101-
value = "AWSCC"
102-
}]
103-
}
104-
105-
# Create VPC Attachment
10693
resource "awscc_networkmanager_vpc_attachment" "example" {
10794
core_network_id = awscc_networkmanager_core_network.example.id
108-
vpc_arn = format("arn:aws:ec2:%s:%s:vpc/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_vpc.example.id)
95+
vpc_arn = format("arn:aws:ec2:%s:%s:vpc/%s", local.region, local.account_id, awscc_ec2_vpc.example.id)
10996
subnet_arns = [
110-
format("arn:aws:ec2:%s:%s:subnet/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_subnet.example_subnet1.id),
111-
format("arn:aws:ec2:%s:%s:subnet/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_subnet.example_subnet2.id)
97+
format("arn:aws:ec2:%s:%s:subnet/%s", local.region, local.account_id, awscc_ec2_subnet.example_subnet1.id),
98+
format("arn:aws:ec2:%s:%s:subnet/%s", local.region, local.account_id, awscc_ec2_subnet.example_subnet2.id)
11299
]
113100
options = {
114101
appliance_mode_support = false
Lines changed: 46 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
11
data "aws_caller_identity" "current" {}
22
data "aws_region" "current" {}
33

4-
# Create VPC and subnets
4+
locals {
5+
account_id = data.aws_caller_identity.current.account_id
6+
region = data.aws_region.current.name
7+
}
8+
9+
resource "awscc_networkmanager_global_network" "example" {
10+
description = "Example Global Network"
11+
tags = [{
12+
key = "Modified By"
13+
value = "AWSCC"
14+
}]
15+
}
16+
17+
# Core Network - segment-actions cannot reference attachment IDs during creation
18+
# as attachments don't exist yet. This creates circular dependencies on both
19+
# create and destroy operations. Use blackhole or add segment-actions later.
20+
resource "awscc_networkmanager_core_network" "example" {
21+
description = "Example Core Network"
22+
global_network_id = awscc_networkmanager_global_network.example.id
23+
policy_document = jsonencode({
24+
"version" : "2021.12",
25+
"core-network-configuration" : {
26+
"vpn-ecmp-support" : true,
27+
"asn-ranges" : ["64512-65534"],
28+
"edge-locations" : [{
29+
"location" : local.region
30+
}]
31+
},
32+
"segments" : [{
33+
"name" : "shared",
34+
"description" : "Segment for shared services",
35+
"require-attachment-acceptance" : false
36+
}]
37+
})
38+
tags = [{
39+
key = "Modified By"
40+
value = "AWSCC"
41+
}]
42+
}
43+
544
resource "awscc_ec2_vpc" "example" {
645
cidr_block = "10.0.0.0/16"
746
tags = [{
@@ -13,7 +52,7 @@ resource "awscc_ec2_vpc" "example" {
1352
resource "awscc_ec2_subnet" "example_subnet1" {
1453
vpc_id = awscc_ec2_vpc.example.id
1554
cidr_block = "10.0.1.0/24"
16-
availability_zone = "${data.aws_region.current.name}a"
55+
availability_zone = "${local.region}a"
1756
tags = [{
1857
key = "Name"
1958
value = "example-subnet-1"
@@ -23,71 +62,19 @@ resource "awscc_ec2_subnet" "example_subnet1" {
2362
resource "awscc_ec2_subnet" "example_subnet2" {
2463
vpc_id = awscc_ec2_vpc.example.id
2564
cidr_block = "10.0.2.0/24"
26-
availability_zone = "${data.aws_region.current.name}b"
65+
availability_zone = "${local.region}b"
2766
tags = [{
2867
key = "Name"
2968
value = "example-subnet-2"
3069
}]
3170
}
3271

33-
# Create Network Manager resources
34-
resource "awscc_networkmanager_global_network" "example" {
35-
description = "Example Global Network"
36-
tags = [{
37-
key = "Modified By"
38-
value = "AWSCC"
39-
}]
40-
}
41-
42-
resource "awscc_networkmanager_core_network" "example" {
43-
description = "Example Core Network"
44-
global_network_id = awscc_networkmanager_global_network.example.id
45-
policy_document = jsonencode({
46-
"version" : "2021.12",
47-
"core-network-configuration" : {
48-
"vpn-ecmp-support" : true,
49-
"asn-ranges" : [
50-
"64512-65534"
51-
],
52-
"edge-locations" : [
53-
{
54-
"location" : data.aws_region.current.name
55-
}
56-
]
57-
},
58-
"segments" : [
59-
{
60-
"name" : "shared",
61-
"description" : "Segment for shared services",
62-
"require-attachment-acceptance" : false
63-
}
64-
],
65-
"segment-actions" : [
66-
{
67-
"action" : "create-route",
68-
"destination-cidr-blocks" : [
69-
"0.0.0.0/0"
70-
],
71-
"destinations" : [
72-
"attachment"
73-
],
74-
"segment" : "shared"
75-
}
76-
]
77-
})
78-
tags = [{
79-
key = "Modified By"
80-
value = "AWSCC"
81-
}]
82-
}
83-
84-
# Create VPC Attachment
8572
resource "awscc_networkmanager_vpc_attachment" "example" {
8673
core_network_id = awscc_networkmanager_core_network.example.id
87-
vpc_arn = format("arn:aws:ec2:%s:%s:vpc/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_vpc.example.id)
74+
vpc_arn = format("arn:aws:ec2:%s:%s:vpc/%s", local.region, local.account_id, awscc_ec2_vpc.example.id)
8875
subnet_arns = [
89-
format("arn:aws:ec2:%s:%s:subnet/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_subnet.example_subnet1.id),
90-
format("arn:aws:ec2:%s:%s:subnet/%s", data.aws_region.current.name, data.aws_caller_identity.current.account_id, awscc_ec2_subnet.example_subnet2.id)
76+
format("arn:aws:ec2:%s:%s:subnet/%s", local.region, local.account_id, awscc_ec2_subnet.example_subnet1.id),
77+
format("arn:aws:ec2:%s:%s:subnet/%s", local.region, local.account_id, awscc_ec2_subnet.example_subnet2.id)
9178
]
9279
options = {
9380
appliance_mode_support = false
@@ -100,4 +87,4 @@ resource "awscc_networkmanager_vpc_attachment" "example" {
10087
key = "Modified By"
10188
value = "AWSCC"
10289
}]
103-
}
90+
}

0 commit comments

Comments
 (0)