简体   繁体   中英

Can Terraform create a Compute Engine on a defined IP Range?

I'm able to create a Compute Engine with either a:

  • Predefined IP address
  • Dynamic IP address

But I can't create a Compute Engine with a semi-dynamic address, ie the first 3 numbers being static but not the last one, eg 255.255.255.*

The Compute Engine is being created on a VPC whose IP address range is too wide for my requirements. I'm attempting to created all of my servers on a close range of IP addresses but I also don't want make each one static and have to maintain it in the Terraform code.

Does anyone know a means to reserve and assign IP's in this restricted way?

The best fit I see for your need is to use the "Google Address Terraform Module", where you can define a list of ip addresses that match a list of instance names and assign the corresponding values. Here, you can find a document describing the module and how to use it [1].

Below, there is an example for the allocation of 3 ip addresses to different instances as a reference:

module "address-fe" {
  source  = "terraform-google-modules/address/google"
  version = "0.1.0"

  subnetwork = "projects/gcp-network/regions/us-west1/subnetworks/dev-us-west1-dynamic"

  names = [
    "gusw1-dev-fooapp-fe-0001-a-001-ip",
    "gusw1-dev-fooapp-fe-0001-a-002-ip",
    "gusw1-dev-fooapp-fe-0001-a-003-ip"
  ]

  addresses = [
    "10.11.0.10",
    "10.11.0.11",
    "10.11.0.12"
  ]
}

[1] https://registry.terraform.io/modules/terraform-google-modules/address/google/latest

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM