Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Subnetwork secondary_ranges Computed again, apply fixup, fix patch #3496

Merged
merged 1 commit into from
Apr 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions google/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ func resourceComputeSubnetwork() *schema.Resource {
DiffSuppressFunc: compareSelfLinkOrResourceName,
},
"secondary_ip_range": {
Type: schema.TypeList,
Optional: true,
Type: schema.TypeList,
Computed: true,
Optional: true,
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"ip_cidr_range": {
Expand Down Expand Up @@ -244,7 +246,7 @@ func resourceComputeSubnetworkCreate(d *schema.ResourceData, meta interface{}) e
secondaryIpRangesProp, err := expandComputeSubnetworkSecondaryIpRange(d.Get("secondary_ip_range"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("secondary_ip_range"); !isEmptyValue(reflect.ValueOf(secondaryIpRangesProp)) && (ok || !reflect.DeepEqual(v, secondaryIpRangesProp)) {
} else if v, ok := d.GetOkExists("secondary_ip_range"); ok || !reflect.DeepEqual(v, secondaryIpRangesProp) {
obj["secondaryIpRanges"] = secondaryIpRangesProp
}
privateIpGoogleAccessProp, err := expandComputeSubnetworkPrivateIpGoogleAccess(d.Get("private_ip_google_access"), d, config)
Expand Down Expand Up @@ -424,7 +426,7 @@ func resourceComputeSubnetworkUpdate(d *schema.ResourceData, meta interface{}) e
secondaryIpRangesProp, err := expandComputeSubnetworkSecondaryIpRange(d.Get("secondary_ip_range"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("secondary_ip_range"); !isEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, secondaryIpRangesProp)) {
} else if v, ok := d.GetOkExists("secondary_ip_range"); ok || !reflect.DeepEqual(v, secondaryIpRangesProp) {
obj["secondaryIpRanges"] = secondaryIpRangesProp
}

Expand Down
57 changes: 57 additions & 0 deletions google/resource_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,22 @@ func TestAccComputeSubnetwork_secondaryIpRanges(t *testing.T) {
testAccCheckComputeSubnetworkHasSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
),
},
{
Config: testAccComputeSubnetwork_secondaryIpRanges_update3(cnName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeSubnetworkExists("google_compute_subnetwork.network-with-private-secondary-ip-ranges", &subnetwork),
testAccCheckComputeSubnetworkHasSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update1", "192.168.10.0/24"),
testAccCheckComputeSubnetworkHasSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
),
},
{
Config: testAccComputeSubnetwork_secondaryIpRanges_update4(cnName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeSubnetworkExists("google_compute_subnetwork.network-with-private-secondary-ip-ranges", &subnetwork),
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update1", "192.168.10.0/24"),
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
),
},
{
Config: testAccComputeSubnetwork_secondaryIpRanges_update1(cnName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -384,6 +400,47 @@ resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges"
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_secondaryIpRanges_update3(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
secondary_ip_range {
range_name = "tf-test-secondary-range-update2"
ip_cidr_range = "192.168.11.0/24"
}
secondary_ip_range {
range_name = "tf-test-secondary-range-update1"
ip_cidr_range = "192.168.10.0/24"
}
}
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_secondaryIpRanges_update4(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}

resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = "${google_compute_network.custom-test.self_link}"
secondary_ip_range = []
}
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_flowLogs(cnName, subnetworkName string, enableLogs bool) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
Expand Down