2016-02-16 03:04:44 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
"google.golang.org/api/compute/v1"
|
|
|
|
)
|
|
|
|
|
2018-01-17 20:58:37 +00:00
|
|
|
// Unit tests
|
|
|
|
|
|
|
|
func TestIsShrinkageIpCidr(t *testing.T) {
|
|
|
|
cases := map[string]struct {
|
|
|
|
Old, New string
|
|
|
|
Shrinkage bool
|
|
|
|
}{
|
|
|
|
"Expansion same network ip": {
|
|
|
|
Old: "10.0.0.0/24",
|
|
|
|
New: "10.0.0.0/16",
|
|
|
|
Shrinkage: false,
|
|
|
|
},
|
|
|
|
"Expansion different network ip": {
|
|
|
|
Old: "10.0.1.0/24",
|
|
|
|
New: "10.0.0.0/16",
|
|
|
|
Shrinkage: false,
|
|
|
|
},
|
|
|
|
"Shrinkage same network ip": {
|
|
|
|
Old: "10.0.0.0/16",
|
|
|
|
New: "10.0.0.0/24",
|
|
|
|
Shrinkage: true,
|
|
|
|
},
|
|
|
|
"Shrinkage different network ip": {
|
|
|
|
Old: "10.0.0.0/16",
|
|
|
|
New: "10.1.0.0/16",
|
|
|
|
Shrinkage: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for tn, tc := range cases {
|
|
|
|
if isShrinkageIpCidr(tc.Old, tc.New, nil) != tc.Shrinkage {
|
|
|
|
t.Errorf("%s failed: Shrinkage should be %t", tn, tc.Shrinkage)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Acceptance tests
|
|
|
|
|
2016-02-16 03:04:44 +00:00
|
|
|
func TestAccComputeSubnetwork_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2016-09-03 09:51:20 +00:00
|
|
|
var subnetwork1 compute.Subnetwork
|
|
|
|
var subnetwork2 compute.Subnetwork
|
2016-02-16 03:04:44 +00:00
|
|
|
|
2017-06-07 13:52:14 +00:00
|
|
|
cnName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetwork1Name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetwork2Name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetwork3Name := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
|
2016-02-16 03:04:44 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeSubnetworkDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-06-07 13:52:14 +00:00
|
|
|
Config: testAccComputeSubnetwork_basic(cnName, subnetwork1Name, subnetwork2Name, subnetwork3Name),
|
2016-02-16 03:04:44 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
2016-09-03 09:51:20 +00:00
|
|
|
"google_compute_subnetwork.network-ref-by-url", &subnetwork1),
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-ref-by-name", &subnetwork2),
|
2016-02-16 03:04:44 +00:00
|
|
|
),
|
|
|
|
},
|
2017-12-19 23:33:20 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_subnetwork.network-ref-by-url",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_compute_subnetwork.network-with-private-google-access",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2016-02-16 03:04:44 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:52:14 +00:00
|
|
|
func TestAccComputeSubnetwork_update(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-06-07 13:52:14 +00:00
|
|
|
var subnetwork compute.Subnetwork
|
|
|
|
|
|
|
|
cnName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetworkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeSubnetworkDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2018-01-17 20:58:37 +00:00
|
|
|
Config: testAccComputeSubnetwork_update1(cnName, "10.2.0.0/24", subnetworkName),
|
2017-06-07 13:52:14 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-with-private-google-access", &subnetwork),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2018-01-17 20:58:37 +00:00
|
|
|
// Expand IP CIDR range and update private_ip_google_access
|
|
|
|
Config: testAccComputeSubnetwork_update2(cnName, "10.2.0.0/16", subnetworkName),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-with-private-google-access", &subnetwork),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
// Shrink IP CIDR range and update private_ip_google_access
|
|
|
|
Config: testAccComputeSubnetwork_update2(cnName, "10.2.0.0/24", subnetworkName),
|
2017-06-07 13:52:14 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-with-private-google-access", &subnetwork),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if subnetwork.PrivateIpGoogleAccess {
|
|
|
|
t.Errorf("Expected PrivateIpGoogleAccess to be false, got %v", subnetwork.PrivateIpGoogleAccess)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-19 23:33:20 +00:00
|
|
|
func TestAccComputeSubnetwork_secondaryIpRanges(t *testing.T) {
|
2017-12-08 21:11:09 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var subnetwork compute.Subnetwork
|
|
|
|
|
|
|
|
cnName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetworkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeSubnetworkDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeSubnetwork_secondaryIpRanges_update1(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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccComputeSubnetwork_secondaryIpRanges_update2(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"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2017-12-19 23:33:20 +00:00
|
|
|
Config: testAccComputeSubnetwork_secondaryIpRanges_update1(cnName, subnetworkName),
|
2017-12-08 21:11:09 +00:00
|
|
|
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"),
|
|
|
|
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-04-26 11:49:16 +00:00
|
|
|
func TestAccComputeSubnetwork_flowLogs(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var subnetwork compute.Subnetwork
|
|
|
|
|
|
|
|
cnName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
subnetworkName := fmt.Sprintf("tf-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckComputeSubnetworkDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccComputeSubnetwork_flowLogs(cnName, subnetworkName, true),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-with-flow-logs", &subnetwork),
|
|
|
|
resource.TestCheckResourceAttr("google_compute_subnetwork.network-with-flow-logs",
|
|
|
|
"enable_flow_logs", "true"),
|
|
|
|
),
|
|
|
|
},
|
2018-05-09 18:24:40 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_compute_subnetwork.network-with-flow-logs",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-04-26 11:49:16 +00:00
|
|
|
{
|
|
|
|
Config: testAccComputeSubnetwork_flowLogs(cnName, subnetworkName, false),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckComputeSubnetworkExists(
|
|
|
|
"google_compute_subnetwork.network-with-flow-logs", &subnetwork),
|
|
|
|
resource.TestCheckResourceAttr("google_compute_subnetwork.network-with-flow-logs",
|
|
|
|
"enable_flow_logs", "false"),
|
|
|
|
),
|
|
|
|
},
|
2018-05-09 18:24:40 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_compute_subnetwork.network-with-flow-logs",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2018-04-26 11:49:16 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-02-16 03:04:44 +00:00
|
|
|
func testAccCheckComputeSubnetworkDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_compute_subnetwork" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
region, subnet_name := splitSubnetID(rs.Primary.ID)
|
|
|
|
_, err := config.clientCompute.Subnetworks.Get(
|
|
|
|
config.Project, region, subnet_name).Do()
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("Network still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckComputeSubnetworkExists(n string, subnetwork *compute.Subnetwork) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
region, subnet_name := splitSubnetID(rs.Primary.ID)
|
|
|
|
found, err := config.clientCompute.Subnetworks.Get(
|
|
|
|
config.Project, region, subnet_name).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if found.Name != subnet_name {
|
|
|
|
return fmt.Errorf("Subnetwork not found")
|
|
|
|
}
|
|
|
|
|
|
|
|
*subnetwork = *found
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-27 23:13:00 +00:00
|
|
|
func testAccCheckComputeSubnetworkHasSecondaryIpRange(subnetwork *compute.Subnetwork, rangeName, ipCidrRange string) resource.TestCheckFunc {
|
2017-08-09 22:02:54 +00:00
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, secondaryRange := range subnetwork.SecondaryIpRanges {
|
|
|
|
if secondaryRange.RangeName == rangeName {
|
|
|
|
if secondaryRange.IpCidrRange == ipCidrRange {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return fmt.Errorf("Secondary range %s has the wrong ip_cidr_range. Expected %s, got %s", rangeName, ipCidrRange, secondaryRange.IpCidrRange)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Errorf("Secondary range %s not found", rangeName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 21:11:09 +00:00
|
|
|
func testAccCheckComputeSubnetworkHasNotSecondaryIpRange(subnetwork *compute.Subnetwork, rangeName, ipCidrRange string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
for _, secondaryRange := range subnetwork.SecondaryIpRanges {
|
|
|
|
if secondaryRange.RangeName == rangeName {
|
|
|
|
if secondaryRange.IpCidrRange == ipCidrRange {
|
|
|
|
return fmt.Errorf("Secondary range %s has the wrong ip_cidr_range. Expected %s, got %s", rangeName, ipCidrRange, secondaryRange.IpCidrRange)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:52:14 +00:00
|
|
|
func testAccComputeSubnetwork_basic(cnName, subnetwork1Name, subnetwork2Name, subnetwork3Name string) string {
|
|
|
|
return fmt.Sprintf(`
|
2016-02-16 03:04:44 +00:00
|
|
|
resource "google_compute_network" "custom-test" {
|
2017-06-07 13:52:14 +00:00
|
|
|
name = "%s"
|
2016-02-16 03:04:44 +00:00
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
2016-09-03 09:51:20 +00:00
|
|
|
resource "google_compute_subnetwork" "network-ref-by-url" {
|
2017-06-07 13:52:14 +00:00
|
|
|
name = "%s"
|
2016-02-16 03:04:44 +00:00
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.self_link}"
|
2016-09-03 09:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "network-ref-by-name" {
|
2017-06-07 13:52:14 +00:00
|
|
|
name = "%s"
|
2016-09-03 09:51:20 +00:00
|
|
|
ip_cidr_range = "10.1.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.name}"
|
|
|
|
}
|
|
|
|
|
2017-05-18 20:35:02 +00:00
|
|
|
resource "google_compute_subnetwork" "network-with-private-google-access" {
|
2017-06-07 13:52:14 +00:00
|
|
|
name = "%s"
|
2017-05-18 20:35:02 +00:00
|
|
|
ip_cidr_range = "10.2.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.self_link}"
|
|
|
|
private_ip_google_access = true
|
|
|
|
}
|
2017-06-07 13:52:14 +00:00
|
|
|
`, cnName, subnetwork1Name, subnetwork2Name, subnetwork3Name)
|
|
|
|
}
|
|
|
|
|
2018-01-17 20:58:37 +00:00
|
|
|
func testAccComputeSubnetwork_update1(cnName, cidrRange, subnetworkName string) string {
|
2017-06-07 13:52:14 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "custom-test" {
|
|
|
|
name = "%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
2017-05-18 20:35:02 +00:00
|
|
|
|
2017-06-07 13:52:14 +00:00
|
|
|
resource "google_compute_subnetwork" "network-with-private-google-access" {
|
|
|
|
name = "%s"
|
2018-01-17 20:58:37 +00:00
|
|
|
ip_cidr_range = "%s"
|
2017-06-07 13:52:14 +00:00
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.self_link}"
|
|
|
|
private_ip_google_access = true
|
|
|
|
}
|
2018-01-17 20:58:37 +00:00
|
|
|
`, cnName, subnetworkName, cidrRange)
|
2017-06-07 13:52:14 +00:00
|
|
|
}
|
|
|
|
|
2018-01-17 20:58:37 +00:00
|
|
|
func testAccComputeSubnetwork_update2(cnName, cidrRange, subnetworkName string) string {
|
2017-06-07 13:52:14 +00:00
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "custom-test" {
|
|
|
|
name = "%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "network-with-private-google-access" {
|
|
|
|
name = "%s"
|
2018-01-17 20:58:37 +00:00
|
|
|
ip_cidr_range = "%s"
|
2017-06-07 13:52:14 +00:00
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.self_link}"
|
|
|
|
}
|
2018-01-17 20:58:37 +00:00
|
|
|
`, cnName, subnetworkName, cidrRange)
|
2017-06-07 13:52:14 +00:00
|
|
|
}
|
2017-08-09 22:02:54 +00:00
|
|
|
|
2017-12-08 21:11:09 +00:00
|
|
|
func testAccComputeSubnetwork_secondaryIpRanges_update1(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-update1"
|
|
|
|
ip_cidr_range = "192.168.10.0/24"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, cnName, subnetworkName)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccComputeSubnetwork_secondaryIpRanges_update2(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-update1"
|
|
|
|
ip_cidr_range = "192.168.10.0/24"
|
|
|
|
}
|
|
|
|
secondary_ip_range {
|
|
|
|
range_name = "tf-test-secondary-range-update2"
|
|
|
|
ip_cidr_range = "192.168.11.0/24"
|
|
|
|
},
|
|
|
|
}
|
|
|
|
`, cnName, subnetworkName)
|
|
|
|
}
|
2018-04-26 11:49:16 +00:00
|
|
|
|
|
|
|
func testAccComputeSubnetwork_flowLogs(cnName, subnetworkName string, enableLogs bool) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_compute_network" "custom-test" {
|
|
|
|
name = "%s"
|
|
|
|
auto_create_subnetworks = false
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_compute_subnetwork" "network-with-flow-logs" {
|
|
|
|
name = "%s"
|
|
|
|
ip_cidr_range = "10.0.0.0/16"
|
|
|
|
region = "us-central1"
|
|
|
|
network = "${google_compute_network.custom-test.self_link}"
|
|
|
|
enable_flow_logs = %v
|
|
|
|
}
|
|
|
|
`, cnName, subnetworkName, enableLogs)
|
|
|
|
}
|