@@ -22,7 +22,46 @@ This example demonstrates how to attach a VPC to an AWS Network Manager Core Net
22
22
data "aws_caller_identity" "current" {}
23
23
data "aws_region" "current" {}
24
24
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
+
26
65
resource "awscc_ec2_vpc" "example" {
27
66
cidr_block = "10.0.0.0/16"
28
67
tags = [{
@@ -34,7 +73,7 @@ resource "awscc_ec2_vpc" "example" {
34
73
resource "awscc_ec2_subnet" "example_subnet1" {
35
74
vpc_id = awscc_ec2_vpc.example.id
36
75
cidr_block = "10.0.1.0/24"
37
- availability_zone = "${data.aws_region.current.name }a"
76
+ availability_zone = "${local.region }a"
38
77
tags = [{
39
78
key = "Name"
40
79
value = "example-subnet-1"
@@ -44,71 +83,19 @@ resource "awscc_ec2_subnet" "example_subnet1" {
44
83
resource "awscc_ec2_subnet" "example_subnet2" {
45
84
vpc_id = awscc_ec2_vpc.example.id
46
85
cidr_block = "10.0.2.0/24"
47
- availability_zone = "${data.aws_region.current.name }b"
86
+ availability_zone = "${local.region }b"
48
87
tags = [{
49
88
key = "Name"
50
89
value = "example-subnet-2"
51
90
}]
52
91
}
53
92
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
106
93
resource "awscc_networkmanager_vpc_attachment" "example" {
107
94
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)
109
96
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)
112
99
]
113
100
options = {
114
101
appliance_mode_support = false
0 commit comments