Skip to content

Commit

Permalink
Enable multiple alias IP ranges for compute instance. (#2029)
Browse files Browse the repository at this point in the history
* Enable multiple alias IP ranges for compute instance.
  • Loading branch information
nat-henderson authored Sep 12, 2018
1 parent 46001de commit f05d62c
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 93 deletions.
1 change: 0 additions & 1 deletion google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func resourceComputeInstance() *schema.Resource {

"alias_ip_range": &schema.Schema{
Type: schema.TypeList,
MaxItems: 1,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
198 changes: 106 additions & 92 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ resource "google_compute_instance" "foobar" {
labels {
my_key = "my_value"
my_other_key = "my_other_value"
}
}
}
`, instance)
}
Expand Down Expand Up @@ -2788,83 +2788,83 @@ data "google_compute_image" "my_image" {
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
network = "default"
}
scheduling {
# Instances with guest accelerators do not support live migration.
on_host_maintenance = "TERMINATE"
}
guest_accelerator {
count = %d
type = "nvidia-tesla-k80"
}
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
network = "default"
}
scheduling {
# Instances with guest accelerators do not support live migration.
on_host_maintenance = "TERMINATE"
}
guest_accelerator {
count = %d
type = "nvidia-tesla-k80"
}
}`, instance, count)
}

func testAccComputeInstance_minCpuPlatform(instance string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
family = "debian-9"
project = "debian-cloud"
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
network = "default"
}
network_interface {
network = "default"
}
min_cpu_platform = "Intel Haswell"
min_cpu_platform = "Intel Haswell"
}`, instance)
}

func testAccComputeInstance_primaryAliasIpRange(instance string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-9"
project = "debian-cloud"
family = "debian-9"
project = "debian-cloud"
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
network = "default"
alias_ip_range {
ip_cidr_range = "/24"
}
}
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
network = "default"
alias_ip_range {
ip_cidr_range = "/24"
}
}
}`, instance)
}

Expand All @@ -2887,26 +2887,37 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" {
range_name = "inst-test-secondary"
ip_cidr_range = "172.16.0.0/20"
}
secondary_ip_range {
range_name = "inst-test-tertiary"
ip_cidr_range = "10.1.0.0/16"
}
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
alias_ip_range {
subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}"
ip_cidr_range = "172.16.0.0/24"
}
}
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
alias_ip_range = [
{
subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.0.range_name}"
ip_cidr_range = "172.16.0.0/24"
},
{
subnetwork_range_name = "${google_compute_subnetwork.inst-test-subnetwork.secondary_ip_range.1.range_name}"
ip_cidr_range = "10.1.0.0/20"
}
]
}
}`, network, subnet, instance)
}

Expand All @@ -2929,25 +2940,28 @@ resource "google_compute_subnetwork" "inst-test-subnetwork" {
range_name = "inst-test-secondary"
ip_cidr_range = "172.16.0.0/20"
}
secondary_ip_range {
range_name = "inst-test-tertiary"
ip_cidr_range = "10.1.0.0/16"
}
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
alias_ip_range {
ip_cidr_range = "10.0.1.0/24"
}
}
name = "%s"
machine_type = "n1-standard-1"
zone = "us-east1-d"
boot_disk {
initialize_params {
image = "${data.google_compute_image.my_image.self_link}"
}
}
network_interface {
subnetwork = "${google_compute_subnetwork.inst-test-subnetwork.self_link}"
alias_ip_range {
ip_cidr_range = "10.0.1.0/24"
}
}
}`, network, subnet, instance)
}

Expand Down

0 comments on commit f05d62c

Please sign in to comment.