mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-05 17:52:38 +00:00
provider/google: Changed network argument in google_compute_instance_group as optional (#13493)
This commit is contained in:
parent
0bd8346b4b
commit
c3f292f9d4
|
@ -67,7 +67,9 @@ func resourceComputeInstanceGroup() *schema.Resource {
|
|||
|
||||
"network": {
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"project": {
|
||||
|
@ -129,6 +131,10 @@ func resourceComputeInstanceGroupCreate(d *schema.ResourceData, meta interface{}
|
|||
instanceGroup.NamedPorts = getNamedPorts(v.([]interface{}))
|
||||
}
|
||||
|
||||
if v, ok := d.GetOk("network"); ok {
|
||||
instanceGroup.Network = v.(string)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] InstanceGroup insert request: %#v", instanceGroup)
|
||||
op, err := config.clientCompute.InstanceGroups.Insert(
|
||||
project, d.Get("zone").(string), instanceGroup).Do()
|
||||
|
|
|
@ -90,6 +90,32 @@ func TestAccComputeInstanceGroup_outOfOrderInstances(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestAccComputeInstanceGroup_network(t *testing.T) {
|
||||
var instanceGroup compute.InstanceGroup
|
||||
var instanceName = fmt.Sprintf("instancegroup-test-%s", acctest.RandString(10))
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccComputeInstanceGroup_destroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccComputeInstanceGroup_network(instanceName),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccComputeInstanceGroup_exists(
|
||||
"google_compute_instance_group.with_instance", &instanceGroup),
|
||||
testAccComputeInstanceGroup_hasCorrectNetwork(
|
||||
"google_compute_instance_group.with_instance", "google_compute_network.ig_network", &instanceGroup),
|
||||
testAccComputeInstanceGroup_exists(
|
||||
"google_compute_instance_group.without_instance", &instanceGroup),
|
||||
testAccComputeInstanceGroup_hasCorrectNetwork(
|
||||
"google_compute_instance_group.without_instance", "google_compute_network.ig_network", &instanceGroup),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccComputeInstanceGroup_destroy(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
|
@ -201,6 +227,44 @@ func testAccComputeInstanceGroup_named_ports(n string, np map[string]int64, inst
|
|||
}
|
||||
}
|
||||
|
||||
func testAccComputeInstanceGroup_hasCorrectNetwork(nInstanceGroup string, nNetwork string, instanceGroup *compute.InstanceGroup) resource.TestCheckFunc {
|
||||
return func(s *terraform.State) error {
|
||||
config := testAccProvider.Meta().(*Config)
|
||||
|
||||
rsInstanceGroup, ok := s.RootModule().Resources[nInstanceGroup]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", nInstanceGroup)
|
||||
}
|
||||
if rsInstanceGroup.Primary.ID == "" {
|
||||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
instanceGroup, err := config.clientCompute.InstanceGroups.Get(
|
||||
config.Project, rsInstanceGroup.Primary.Attributes["zone"], rsInstanceGroup.Primary.ID).Do()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rsNetwork, ok := s.RootModule().Resources[nNetwork]
|
||||
if !ok {
|
||||
return fmt.Errorf("Not found: %s", nNetwork)
|
||||
}
|
||||
if rsNetwork.Primary.ID == "" {
|
||||
return fmt.Errorf("No ID is set")
|
||||
}
|
||||
network, err := config.clientCompute.Networks.Get(
|
||||
config.Project, rsNetwork.Primary.ID).Do()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if instanceGroup.Network != network.SelfLink {
|
||||
return fmt.Errorf("network incorrect: actual=%s vs expected=%s", instanceGroup.Network, network.SelfLink)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func testAccComputeInstanceGroup_basic(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_instance" "ig_instance" {
|
||||
|
@ -237,7 +301,7 @@ func testAccComputeInstanceGroup_basic(instance string) string {
|
|||
description = "Terraform test instance group empty"
|
||||
name = "%s-empty"
|
||||
zone = "us-central1-c"
|
||||
named_port {
|
||||
named_port {
|
||||
name = "http"
|
||||
port = "8080"
|
||||
}
|
||||
|
@ -365,3 +429,40 @@ func testAccComputeInstanceGroup_outOfOrderInstances(instance string) string {
|
|||
}
|
||||
}`, instance, instance, instance)
|
||||
}
|
||||
|
||||
func testAccComputeInstanceGroup_network(instance string) string {
|
||||
return fmt.Sprintf(`
|
||||
resource "google_compute_network" "ig_network" {
|
||||
name = "%[1]s"
|
||||
auto_create_subnetworks = true
|
||||
}
|
||||
|
||||
resource "google_compute_instance" "ig_instance" {
|
||||
name = "%[1]s"
|
||||
machine_type = "n1-standard-1"
|
||||
can_ip_forward = false
|
||||
zone = "us-central1-c"
|
||||
|
||||
disk {
|
||||
image = "debian-8-jessie-v20160803"
|
||||
}
|
||||
|
||||
network_interface {
|
||||
network = "${google_compute_network.ig_network.name}"
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group" "with_instance" {
|
||||
description = "Terraform test instance group"
|
||||
name = "%[1]s-with-instance"
|
||||
zone = "us-central1-c"
|
||||
instances = [ "${google_compute_instance.ig_instance.self_link}" ]
|
||||
}
|
||||
|
||||
resource "google_compute_instance_group" "without_instance" {
|
||||
description = "Terraform test instance group"
|
||||
name = "%[1]s-without-instance"
|
||||
zone = "us-central1-c"
|
||||
network = "${google_compute_network.ig_network.self_link}"
|
||||
}`, instance)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user