Skip to content

Instantly share code, notes, and snippets.

@netturpin
Last active August 4, 2018 18:50
Show Gist options
  • Save netturpin/ae67747f2f25daa67b4661eff4e77211 to your computer and use it in GitHub Desktop.
Save netturpin/ae67747f2f25daa67b4661eff4e77211 to your computer and use it in GitHub Desktop.
Terraform google_compute_interconnect_attachment validation

Terraform file

# -- Terraform configuration

terraform {
  required_version = "0.11.7"
}

provider "google" {
  project = "my-project"
  region  = "europe-west4"
}
resource "google_compute_router" "test_router_peering" {
  bgp {
    asn = "65522"
  }

  name    = "test-router-peering"
  network = "my-network"
  region  = "europe-west4"
}

resource "google_compute_interconnect_attachment" "test-peering-attachment" {
  interconnect = "https://www.googleapis.com/compute/v1/projects/my-project/global/interconnects/my-interconnect"
  region = "europe-west4"
  name = "test-peering-attachment"
  router = "${google_compute_router.test_router_peering.self_link}"
}

Creating the interconnect

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + google_compute_interconnect_attachment.test-peering-attachment
      id:                          <computed>
      cloud_router_ip_address:     <computed>
      creation_timestamp:          <computed>
      customer_router_ip_address:  <computed>
      google_reference_id:         <computed>
      interconnect:                "https://www.googleapis.com/compute/v1/projects/my-project/global/interconnects/my-interconnect"
      name:                        "test-peering-attachment"
      operational_status:          <computed>
      private_interconnect_info.#: <computed>
      project:                     <computed>
      region:                      "europe-west4"
      router:                      "${google_compute_router.test_router_peering.self_link}"
      self_link:                   <computed>

  + google_compute_router.test_router_peering
      id:                          <computed>
      bgp.#:                       "1"
      bgp.0.asn:                   "65522"
      name:                        "test-router-peering"
      network:                     "my-network"
      project:                     <computed>
      region:                      "europe-west4"
      self_link:                   <computed>


Plan: 2 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

google_compute_router.test_router_peering: Creating...
  bgp.#:     "" => "1"
  bgp.0.asn: "" => "65522"
  name:      "" => "test-router-peering"
  network:   "" => "my-network"
  project:   "" => "<computed>"
  region:    "" => "europe-west4"
  self_link: "" => "<computed>"
google_compute_router.test_router_peering: Still creating... (10s elapsed)
google_compute_router.test_router_peering: Creation complete after 12s (ID: europe-west4/test-router-peering)
google_compute_interconnect_attachment.test-peering-attachment: Creating...
  cloud_router_ip_address:     "" => "<computed>"
  creation_timestamp:          "" => "<computed>"
  customer_router_ip_address:  "" => "<computed>"
  google_reference_id:         "" => "<computed>"
  interconnect:                "" => "https://www.googleapis.com/compute/v1/projects/my-project/global/interconnects/my-interconnect"
  name:                        "" => "test-peering-attachment"
  operational_status:          "" => "<computed>"
  private_interconnect_info.#: "" => "<computed>"
  project:                     "" => "<computed>"
  region:                      "" => "europe-west4"
  router:                      "" => "https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/routers/test-router-peering"
  self_link:                   "" => "<computed>"
google_compute_interconnect_attachment.test-peering-attachment: Still creating... (10s elapsed)
google_compute_interconnect_attachment.test-peering-attachment: Still creating... (20s elapsed)
google_compute_interconnect_attachment.test-peering-attachment: Creation complete after 27s (ID: test-peering-attachment)

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

Checking interconnect is available

With Terraform

$ terraform show
google_compute_interconnect_attachment.test-peering-attachment:
  id = test-peering-attachment
  cloud_router_ip_address = 169.254.246.137/29
  creation_timestamp = 2018-08-03T00:34:05.588-07:00
  customer_router_ip_address = 169.254.246.138/29
  description = 
  google_reference_id = 
  interconnect = https://www.googleapis.com/compute/v1/projects/my-project/global/interconnects/my-interconnect
  name = test-peering-attachment
  operational_status = OS_ACTIVE
  private_interconnect_info.# = 1
  private_interconnect_info.0.tag8021q = 1002
  project = my-project
  region = https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4
  router = https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/routers/test-router-peering
  self_link = https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/interconnectAttachments/test-peering-attachment
google_compute_router.test_router_peering:
  id = europe-west4/test-router-peering
  bgp.# = 1
  bgp.0.asn = 65522
  description = 
  name = test-router-peering
  network = https://www.googleapis.com/compute/v1/projects/my-project/global/networks/my-network
  project = my-project
  region = europe-west4
  self_link = https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/routers/test-router-peering

With gcloud

$ gcloud compute interconnects attachments describe test-peering-attachment --region=europe-west4
adminEnabled: true
bandwidth: BPS_10G
cloudRouterIpAddress: 169.254.27.169/29
creationTimestamp: '2018-08-02T08:45:16.884-07:00'
customerRouterIpAddress: 169.254.27.170/29
id: '3245133766180379107'
interconnect: https://www.googleapis.com/compute/v1/projects/my-project/global/interconnects/my-interconnect
kind: compute#interconnectAttachment
name: test-peering-attachment
operationalStatus: OS_ACTIVE
privateInterconnectInfo:
  tag8021q: 1002
region: https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4
router: https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/routers/test-router-peering
selfLink: https://www.googleapis.com/compute/v1/projects/my-project/regions/europe-west4/interconnectAttachments/test-peering-attachment
state: ACTIVE
type: DEDICATED
vlanTag8021q: 1002

Deleting the interconnect

$ terraform destroy
google_compute_router.test_router_peering: Refreshing state... (ID: europe-west4/test-router-peering)
google_compute_interconnect_attachment.test-peering-attachment: Refreshing state... (ID: test-peering-attachment)

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  - destroy

Terraform will perform the following actions:

  - google_compute_interconnect_attachment.test-peering-attachment

  - google_compute_router.test_router_peering


Plan: 0 to add, 0 to change, 2 to destroy.

Do you really want to destroy?
  Terraform will destroy all your managed infrastructure, as shown above.
  There is no undo. Only 'yes' will be accepted to confirm.

  Enter a value: yes

google_compute_interconnect_attachment.test-peering-attachment: Destroying... (ID: test-peering-attachment)
google_compute_interconnect_attachment.test-peering-attachment: Still destroying... (ID: test-peering-attachment, 10s elapsed)
google_compute_interconnect_attachment.test-peering-attachment: Destruction complete after 13s
google_compute_router.test_router_peering: Destroying... (ID: europe-west4/test-router-peering)
google_compute_router.test_router_peering: Still destroying... (ID: europe-west4/test-router-peering, 10s elapsed)
google_compute_router.test_router_peering: Destruction complete after 12s

Destroy complete! Resources: 2 destroyed.

Checking the attachment has been destroyed

$ gcloud compute interconnects attachments describe test-peering-attachment --region=europe-west4
ERROR: (gcloud.compute.interconnects.attachments.describe) Could not fetch resource:
 - The resource 'projects/my-project/regions/europe-west4/interconnectAttachments/test-peering-attachment' was not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment