-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#11206] Add BGP Peer Router Appliance instance argument #6874
Merged
slevenick
merged 1 commit into
GoogleCloudPlatform:main
from
LucaPrete:11206-add-bgp-peer-ra-instance
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
mmv1/templates/terraform/examples/router_peer_router_appliance.tf.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
resource "google_compute_network" "network" { | ||
name = "<%= ctx[:vars]['router_name'] %>-net" | ||
auto_create_subnetworks = false | ||
} | ||
|
||
resource "google_compute_subnetwork" "subnetwork" { | ||
name = "<%= ctx[:vars]['router_name'] %>-sub" | ||
network = google_compute_network.network.self_link | ||
ip_cidr_range = "10.0.0.0/16" | ||
region = "us-central1" | ||
} | ||
|
||
resource "google_compute_address" "addr_intf" { | ||
name = "<%= ctx[:vars]['router_name'] %>-addr-intf" | ||
region = google_compute_subnetwork.subnetwork.region | ||
subnetwork = google_compute_subnetwork.subnetwork.id | ||
address_type = "INTERNAL" | ||
} | ||
|
||
resource "google_compute_address" "addr_intf_redundant" { | ||
name = "<%= ctx[:vars]['router_name'] %>-addr-intf-red" | ||
region = google_compute_subnetwork.subnetwork.region | ||
subnetwork = google_compute_subnetwork.subnetwork.id | ||
address_type = "INTERNAL" | ||
} | ||
|
||
resource "google_compute_address" "addr_peer" { | ||
name = "<%= ctx[:vars]['router_name'] %>-addr-peer" | ||
region = google_compute_subnetwork.subnetwork.region | ||
subnetwork = google_compute_subnetwork.subnetwork.id | ||
address_type = "INTERNAL" | ||
} | ||
|
||
resource "google_compute_instance" "instance" { | ||
name = "router-appliance" | ||
zone = "us-central1-a" | ||
machine_type = "e2-medium" | ||
can_ip_forward = true | ||
|
||
boot_disk { | ||
initialize_params { | ||
image = "debian-cloud/debian-11" | ||
} | ||
} | ||
|
||
network_interface { | ||
network_ip = google_compute_address.addr_peer.address | ||
subnetwork = google_compute_subnetwork.subnetwork.self_link | ||
} | ||
} | ||
|
||
resource "google_network_connectivity_hub" "hub" { | ||
name = "<%= ctx[:vars]['router_name'] %>-hub" | ||
} | ||
|
||
resource "google_network_connectivity_spoke" "spoke" { | ||
name = "<%= ctx[:vars]['router_name'] %>-spoke" | ||
location = google_compute_subnetwork.subnetwork.region | ||
hub = google_network_connectivity_hub.hub.id | ||
|
||
linked_router_appliance_instances { | ||
instances { | ||
virtual_machine = google_compute_instance.instance.self_link | ||
ip_address = google_compute_address.addr_peer.address | ||
} | ||
site_to_site_data_transfer = false | ||
} | ||
} | ||
|
||
resource "google_compute_router" "router" { | ||
name = "<%= ctx[:vars]['router_name'] %>-router" | ||
region = google_compute_subnetwork.subnetwork.region | ||
network = google_compute_network.network.self_link | ||
bgp { | ||
asn = 64514 | ||
} | ||
} | ||
|
||
resource "google_compute_router_interface" "interface_redundant" { | ||
name = "<%= ctx[:vars]['router_name'] %>-intf-red" | ||
region = google_compute_router.router.region | ||
router = google_compute_router.router.name | ||
subnetwork = google_compute_subnetwork.subnetwork.self_link | ||
private_ip_address = google_compute_address.addr_intf_redundant.address | ||
} | ||
|
||
resource "google_compute_router_interface" "interface" { | ||
name = "<%= ctx[:vars]['router_name'] %>-intf" | ||
region = google_compute_router.router.region | ||
router = google_compute_router.router.name | ||
subnetwork = google_compute_subnetwork.subnetwork.self_link | ||
private_ip_address = google_compute_address.addr_intf.address | ||
redundant_interface = google_compute_router_interface.interface_redundant.name | ||
} | ||
|
||
resource "google_compute_router_peer" "peer" { | ||
name = "<%= ctx[:vars]['peer_name'] %>" | ||
router = google_compute_router.router.name | ||
region = google_compute_router.router.region | ||
interface = google_compute_router_interface.interface.name | ||
router_appliance_instance = google_compute_instance.instance.self_link | ||
peer_asn = 65513 | ||
peer_ip_address = google_compute_address.addr_peer.address | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only part I'm concerned about here. Why remove the interface if it's already marked Computed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TL;DR
The API automatically sets the redundant_interface field under an interface that interface has been set as redundant of another interface. Anyway, the API is not able to automatically clean up the redundant interface field, if the interface referenced in redundant_interface is removed.
Longer explanation with example:
Assume you create two interfaces. You insert the first one, then the other one.
On the second interface you set redundant_interface, referencing the one formerly created.
The API automatically sets redundant interface also on the first interface created, referencing the second one, so each interface is set as the redundant of the other. This is why I put Optional and Computed equal to true.
We now remove either the first or the second interface. The API is not automatically able to look for redundant interface fields in other interfaces on that router that reference the interface we're removing. As such, we've to look for it and remove it manually.