Ask Your Question
2

How can a secondary IP range be added to a subnetwork after it has been created using Terraform on GCP?

asked 2022-06-17 11:00:00 +0000

woof gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-05-21 02:00:00 +0000

bukephalos gravatar image

To add a secondary IP range to a subnetwork after it has been created using Terraform on GCP, the following steps will be necessary:

  1. Identify the existing subnetwork resource in your Terraform configuration file.

    resource "google_compute_subnetwork" "example" {
     name                     = "example-subnet"
     ip_cidr_range            = "10.0.1.0/24"
     network                  = google_compute_network.example.self_link
     region                   = "us-central1"
     private_ip_google_access = true
    }
    
  2. Add a secondaryiprange block inside the subnetwork resource.

    resource "google_compute_subnetwork" "example" {
     name                     = "example-subnet"
     ip_cidr_range            = "10.0.1.0/24"
     network                  = google_compute_network.example.self_link
     region                   = "us-central1"
     private_ip_google_access = true
    
     secondary_ip_range {
       range_name    = "example-range"
       ip_cidr_range = "10.0.2.0/24"
     }
    }
    
  3. Save the changes to the Terraform configuration file.

  4. Run the terraform apply command to apply the changes to the GCP environment.

    $ terraform apply
    

After these steps are completed, the secondary IP range will be added to the existing subnetwork.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-06-17 11:00:00 +0000

Seen: 10 times

Last updated: May 21 '21