diff --git a/google-beta/resource_compute_network_peering.go b/google-beta/resource_compute_network_peering.go index 288d3a5fa3..210a6f2751 100644 --- a/google-beta/resource_compute_network_peering.go +++ b/google-beta/resource_compute_network_peering.go @@ -6,6 +6,7 @@ import ( "sort" "github.com/hashicorp/terraform/helper/schema" + computeBeta "google.golang.org/api/compute/v0.beta" "google.golang.org/api/compute/v1" "google.golang.org/api/googleapi" ) @@ -39,11 +40,14 @@ func resourceComputeNetworkPeering() *schema.Resource { ValidateFunc: validateRegexp(peerNetworkLinkRegex), DiffSuppressFunc: compareSelfLinkRelativePaths, }, + // The API only accepts true as a value for exchange_subnet_routes or auto_create_routes (of which only one can be set in a valid request). + // Also, you can't set auto_create_routes if you use the networkPeering object. auto_create_routes is also deprecated "auto_create_routes": { - Type: schema.TypeBool, - ForceNew: true, - Optional: true, - Default: true, + Type: schema.TypeBool, + Optional: true, + Deprecated: "auto_create_routes has been deprecated because it's redundant and not user-configurable. It can safely be removed from your config", + ForceNew: true, + Default: true, }, "state": { Type: schema.TypeString, @@ -53,6 +57,18 @@ func resourceComputeNetworkPeering() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "export_custom_routes": { + Type: schema.TypeBool, + ForceNew: true, + Optional: true, + Default: false, + }, + "import_custom_routes": { + Type: schema.TypeBool, + ForceNew: true, + Optional: true, + Default: false, + }, }, } } @@ -64,18 +80,15 @@ func resourceComputeNetworkPeeringCreate(d *schema.ResourceData, meta interface{ return err } - request := &compute.NetworksAddPeeringRequest{ - Name: d.Get("name").(string), - PeerNetwork: d.Get("peer_network").(string), - AutoCreateRoutes: d.Get("auto_create_routes").(bool), - } + request := &computeBeta.NetworksAddPeeringRequest{} + request.NetworkPeering = expandNetworkPeering(d) - addOp, err := config.clientCompute.Networks.AddPeering(networkFieldValue.Project, networkFieldValue.Name, request).Do() + addOp, err := config.clientComputeBeta.Networks.AddPeering(networkFieldValue.Project, networkFieldValue.Name, request).Do() if err != nil { return fmt.Errorf("Error adding network peering: %s", err) } - err = computeOperationWait(config.clientCompute, addOp, networkFieldValue.Project, "Adding Network Peering") + err = computeSharedOperationWait(config.clientCompute, addOp, networkFieldValue.Project, "Adding Network Peering") if err != nil { return err } @@ -94,7 +107,7 @@ func resourceComputeNetworkPeeringRead(d *schema.ResourceData, meta interface{}) return err } - network, err := config.clientCompute.Networks.Get(networkFieldValue.Project, networkFieldValue.Name).Do() + network, err := config.clientComputeBeta.Networks.Get(networkFieldValue.Project, networkFieldValue.Name).Do() if err != nil { return handleNotFoundError(err, d, fmt.Sprintf("Network %q", networkFieldValue.Name)) } @@ -107,7 +120,9 @@ func resourceComputeNetworkPeeringRead(d *schema.ResourceData, meta interface{}) } d.Set("peer_network", peering.Network) - d.Set("auto_create_routes", peering.AutoCreateRoutes) + d.Set("name", peering.Name) + d.Set("import_custom_routes", peering.ImportCustomRoutes) + d.Set("export_custom_routes", peering.ExportCustomRoutes) d.Set("state", peering.State) d.Set("state_details", peering.StateDetails) @@ -145,7 +160,7 @@ func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{ return fmt.Errorf("Error removing peering `%s` from network `%s`: %s", name, networkFieldValue.Name, err) } } else { - err = computeOperationWait(config.clientCompute, removeOp, networkFieldValue.Project, "Removing Network Peering") + err = computeSharedOperationWait(config.clientCompute, removeOp, networkFieldValue.Project, "Removing Network Peering") if err != nil { return err } @@ -154,7 +169,7 @@ func resourceComputeNetworkPeeringDelete(d *schema.ResourceData, meta interface{ return nil } -func findPeeringFromNetwork(network *compute.Network, peeringName string) *compute.NetworkPeering { +func findPeeringFromNetwork(network *computeBeta.Network, peeringName string) *computeBeta.NetworkPeering { for _, p := range network.Peerings { if p.Name == peeringName { return p @@ -162,6 +177,16 @@ func findPeeringFromNetwork(network *compute.Network, peeringName string) *compu } return nil } +func expandNetworkPeering(d *schema.ResourceData) *computeBeta.NetworkPeering { + return &computeBeta.NetworkPeering{ + ExportCustomRoutes: d.Get("export_custom_routes").(bool), + ImportCustomRoutes: d.Get("import_custom_routes").(bool), + // auto_create_routes was replaced by exchange_subnet_routes in the network peering object + ExchangeSubnetRoutes: true, + Name: d.Get("name").(string), + Network: d.Get("peer_network").(string), + } +} func getNetworkPeeringLockName(networkName, peerNetworkName string) string { // Whether you delete the peering from network A to B or the one from B to A, they diff --git a/google-beta/resource_compute_network_peering_test.go b/google-beta/resource_compute_network_peering_test.go index 2ac126f193..e84aaa5278 100644 --- a/google-beta/resource_compute_network_peering_test.go +++ b/google-beta/resource_compute_network_peering_test.go @@ -2,18 +2,18 @@ package google import ( "fmt" + "strings" + "testing" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" - "google.golang.org/api/compute/v1" - "strings" - "testing" + computeBeta "google.golang.org/api/compute/v0.beta" ) func TestAccComputeNetworkPeering_basic(t *testing.T) { t.Parallel() - - var peering compute.NetworkPeering + var peering_beta computeBeta.NetworkPeering resource.Test(t, resource.TestCase{ PreCheck: func() { testAccPreCheck(t) }, @@ -23,10 +23,14 @@ func TestAccComputeNetworkPeering_basic(t *testing.T) { { Config: testAccComputeNetworkPeering_basic(), Check: resource.ComposeTestCheckFunc( - testAccCheckComputeNetworkPeeringExist("google_compute_network_peering.foo", &peering), - testAccCheckComputeNetworkPeeringAutoCreateRoutes(true, &peering), - testAccCheckComputeNetworkPeeringExist("google_compute_network_peering.bar", &peering), - testAccCheckComputeNetworkPeeringAutoCreateRoutes(true, &peering), + testAccCheckComputeNetworkPeeringExist("google_compute_network_peering.foo", &peering_beta), + testAccCheckComputeNetworkPeeringAutoCreateRoutes(true, &peering_beta), + testAccCheckComputeNetworkPeeringImportCustomRoutes(false, &peering_beta), + testAccCheckComputeNetworkPeeringExportCustomRoutes(false, &peering_beta), + testAccCheckComputeNetworkPeeringExist("google_compute_network_peering.bar", &peering_beta), + testAccCheckComputeNetworkPeeringAutoCreateRoutes(true, &peering_beta), + testAccCheckComputeNetworkPeeringImportCustomRoutes(true, &peering_beta), + testAccCheckComputeNetworkPeeringExportCustomRoutes(true, &peering_beta), ), }, }, @@ -42,7 +46,7 @@ func testAccComputeNetworkPeeringDestroy(s *terraform.State) error { continue } - _, err := config.clientCompute.Networks.Get( + _, err := config.clientComputeBeta.Networks.Get( config.Project, rs.Primary.ID).Do() if err == nil { return fmt.Errorf("Network peering still exists") @@ -52,7 +56,7 @@ func testAccComputeNetworkPeeringDestroy(s *terraform.State) error { return nil } -func testAccCheckComputeNetworkPeeringExist(n string, peering *compute.NetworkPeering) resource.TestCheckFunc { +func testAccCheckComputeNetworkPeeringExist(n string, peering *computeBeta.NetworkPeering) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -72,7 +76,7 @@ func testAccCheckComputeNetworkPeeringExist(n string, peering *compute.NetworkPe networkName, peeringName := parts[0], parts[1] - network, err := config.clientCompute.Networks.Get(config.Project, networkName).Do() + network, err := config.clientComputeBeta.Networks.Get(config.Project, networkName).Do() if err != nil { return err } @@ -87,39 +91,65 @@ func testAccCheckComputeNetworkPeeringExist(n string, peering *compute.NetworkPe } } -func testAccCheckComputeNetworkPeeringAutoCreateRoutes(v bool, peering *compute.NetworkPeering) resource.TestCheckFunc { +func testAccCheckComputeNetworkPeeringAutoCreateRoutes(v bool, peering *computeBeta.NetworkPeering) resource.TestCheckFunc { return func(s *terraform.State) error { - if peering.AutoCreateRoutes != v { - return fmt.Errorf("should AutoCreateRoutes set to %t", v) - } + if peering.ExchangeSubnetRoutes != v { + return fmt.Errorf("should ExchangeSubnetRouts set to %t if AutoCreateRoutes is set to %t", v, v) + } return nil } } -func testAccComputeNetworkPeering_basic() string { - return fmt.Sprintf(` -resource "google_compute_network" "network1" { - name = "network-test-1-%s" - auto_create_subnetworks = false -} +func testAccCheckComputeNetworkPeeringImportCustomRoutes(v bool, peering *computeBeta.NetworkPeering) resource.TestCheckFunc { + return func(s *terraform.State) error { + if peering.ImportCustomRoutes != v { + return fmt.Errorf("should ImportCustomRoutes set to %t", v) + } -resource "google_compute_network" "network2" { - name = "network-test-2-%s" - auto_create_subnetworks = false + return nil + } } -resource "google_compute_network_peering" "foo" { - name = "peering-test-1-%s" - network = "${google_compute_network.network1.self_link}" - peer_network = "${google_compute_network.network2.self_link}" -} +func testAccCheckComputeNetworkPeeringExportCustomRoutes(v bool, peering *computeBeta.NetworkPeering) resource.TestCheckFunc { + return func(s *terraform.State) error { + if peering.ExportCustomRoutes != v { + return fmt.Errorf("should ExportCustomRoutes set to %t", v) + } -resource "google_compute_network_peering" "bar" { - name = "peering-test-2-%s" - auto_create_routes = true - network = "${google_compute_network.network2.self_link}" - peer_network = "${google_compute_network.network1.self_link}" + return nil + } } -`, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) + +func testAccComputeNetworkPeering_basic() string { + s := ` + resource "google_compute_network" "network1" { + name = "network-test-1-%s" + auto_create_subnetworks = false + } + + resource "google_compute_network" "network2" { + name = "network-test-2-%s" + auto_create_subnetworks = false + } + + resource "google_compute_network_peering" "foo" { + name = "peering-test-1-%s" + network = "${google_compute_network.network1.self_link}" + peer_network = "${google_compute_network.network2.self_link}" + } + + resource "google_compute_network_peering" "bar" { + network = "${google_compute_network.network2.self_link}" + peer_network = "${google_compute_network.network1.self_link}" + name = "peering-test-2-%s" + auto_create_routes = true + ` + + s = s + + `import_custom_routes = true + export_custom_routes = true + ` + s = s + `}` + return fmt.Sprintf(s, acctest.RandString(10), acctest.RandString(10), acctest.RandString(10), acctest.RandString(10)) } diff --git a/google-beta/resource_container_cluster.go b/google-beta/resource_container_cluster.go index 2a11d6a636..0906971dca 100644 --- a/google-beta/resource_container_cluster.go +++ b/google-beta/resource_container_cluster.go @@ -644,20 +644,6 @@ func resourceContainerCluster() *schema.Resource { }, }, - "vertical_pod_autoscaling": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "enabled": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - "resource_labels": { Type: schema.TypeMap, Optional: true, @@ -853,10 +839,6 @@ func resourceContainerClusterCreate(d *schema.ResourceData, meta interface{}) er cluster.PrivateClusterConfig = expandPrivateClusterConfig(v) } - if v, ok := d.GetOk("vertical_pod_autoscaling"); ok { - cluster.VerticalPodAutoscaling = expandVerticalPodAutoscaling(v) - } - if v, ok := d.GetOk("database_encryption"); ok { cluster.DatabaseEncryption = expandDatabaseEncryption(v) } @@ -1021,10 +1003,6 @@ func resourceContainerClusterRead(d *schema.ResourceData, meta interface{}) erro return err } - if err := d.Set("vertical_pod_autoscaling", flattenVerticalPodAutoscaling(cluster.VerticalPodAutoscaling)); err != nil { - return err - } - igUrls, err := getInstanceGroupUrlsFromManagerUrls(config, cluster.InstanceGroupUrls) if err != nil { return err @@ -1976,17 +1954,6 @@ func expandPrivateClusterConfig(configured interface{}) *containerBeta.PrivateCl } } -func expandVerticalPodAutoscaling(configured interface{}) *containerBeta.VerticalPodAutoscaling { - l := configured.([]interface{}) - if len(l) == 0 { - return nil - } - config := l[0].(map[string]interface{}) - return &containerBeta.VerticalPodAutoscaling{ - Enabled: config["enabled"].(bool), - } -} - func expandDatabaseEncryption(configured interface{}) *containerBeta.DatabaseEncryption { l := configured.([]interface{}) if len(l) == 0 { diff --git a/google-beta/resource_container_cluster_test.go b/google-beta/resource_container_cluster_test.go index 4277956c09..31a80efa3d 100644 --- a/google-beta/resource_container_cluster_test.go +++ b/google-beta/resource_container_cluster_test.go @@ -3091,34 +3091,6 @@ resource "google_container_cluster" "shared_vpc_cluster" { }`, projectName, org, billingId, projectName, org, billingId, acctest.RandString(10), acctest.RandString(10), name) } -func testAccContainerCluster_withVerticalPodAutoscalingEnabled(clusterName string) string { - return fmt.Sprintf(` -resource "google_container_cluster" "with_vertical_pod_autoscaling" { - name = "%s" - zone = "us-central1-a" - initial_node_count = 1 - - vertical_pod_autoscaling { - enabled = true - } -} -`, clusterName) -} - -func testAccContainerCluster_withVerticalPodAutoscalingDisabled(clusterName string) string { - return fmt.Sprintf(` -resource "google_container_cluster" "with_vertical_pod_autoscaling" { - name = "%s" - zone = "us-central1-a" - initial_node_count = 1 - - vertical_pod_autoscaling { - enabled = false - } -} -`, clusterName) -} - func testAccContainerCluster_withoutResourceLabels(clusterName string) string { return fmt.Sprintf(` resource "google_container_cluster" "with_resource_labels" {