2017-03-06 22:59:24 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2017-07-31 16:28:39 +00:00
|
|
|
"reflect"
|
|
|
|
"sort"
|
2017-03-06 22:59:24 +00:00
|
|
|
"strconv"
|
2017-07-31 16:28:39 +00:00
|
|
|
"strings"
|
2017-03-06 22:59:24 +00:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccContainerNodePool_basic(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-26 20:21:51 +00:00
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
2017-03-06 22:59:24 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-07-26 20:21:51 +00:00
|
|
|
Config: testAccContainerNodePool_basic(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:41:35 +00:00
|
|
|
func TestAccContainerNodePool_namePrefix(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-04 23:41:35 +00:00
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_namePrefix(cluster, "tf-np-"),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAccContainerNodePool_noName(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-04 23:41:35 +00:00
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_noName(cluster),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
func TestAccContainerNodePool_withNodeConfig(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerNodePool_withNodeConfig(),
|
2017-07-31 16:28:39 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np_with_node_config"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-02-24 00:55:07 +00:00
|
|
|
func TestAccContainerNodePool_withGPU(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_withGPU(),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np_with_gpu"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np_with_gpu",
|
|
|
|
ImportState: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:56:29 +00:00
|
|
|
func TestAccContainerNodePool_withManagement(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
nodePool := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
management := `
|
|
|
|
management {
|
|
|
|
auto_repair = "true"
|
|
|
|
auto_upgrade = "true"
|
|
|
|
}`
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_withManagement(cluster, nodePool, ""),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np_with_management"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.0.auto_repair", "false"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.0.auto_repair", "false"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_withManagement(cluster, nodePool, management),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches(
|
|
|
|
"google_container_node_pool.np_with_management"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.#", "1"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.0.auto_repair", "true"),
|
|
|
|
resource.TestCheckResourceAttr(
|
|
|
|
"google_container_node_pool.np_with_management", "management.0.auto_repair", "true"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
func TestAccContainerNodePool_withNodeConfigScopeAlias(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2017-11-28 00:32:00 +00:00
|
|
|
Config: testAccContainerNodePool_withNodeConfigScopeAlias(),
|
2017-07-31 16:28:39 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np_with_node_config_scope_alias"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-07-26 20:21:51 +00:00
|
|
|
func TestAccContainerNodePool_autoscaling(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-07-26 20:21:51 +00:00
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerNodePoolDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_autoscaling(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
2017-09-26 22:57:51 +00:00
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "1"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "3"),
|
2017-07-26 20:21:51 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_updateAutoscaling(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
2017-09-26 22:57:51 +00:00
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count", "0"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count", "5"),
|
2017-07-26 20:21:51 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_basic(cluster, np),
|
2017-03-06 22:59:24 +00:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
2017-09-26 22:57:51 +00:00
|
|
|
resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.min_node_count"),
|
|
|
|
resource.TestCheckNoResourceAttr("google_container_node_pool.np", "autoscaling.0.max_node_count"),
|
2017-03-06 22:59:24 +00:00
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
func TestAccContainerNodePool_resize(t *testing.T) {
|
2017-10-12 22:07:29 +00:00
|
|
|
t.Parallel()
|
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
cluster := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
np := fmt.Sprintf("tf-nodepool-test-%s", acctest.RandString(10))
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerNodePool_additionalZones(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "2"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Config: testAccContainerNodePool_resize(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckContainerNodePoolMatches("google_container_node_pool.np"),
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "3"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-03-06 22:59:24 +00:00
|
|
|
func testAccCheckContainerNodePoolDestroy(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "google_container_node_pool" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes := rs.Primary.Attributes
|
|
|
|
_, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Get(
|
|
|
|
config.Project, attributes["zone"], attributes["cluster"], attributes["name"]).Do()
|
|
|
|
if err == nil {
|
|
|
|
return fmt.Errorf("NodePool still exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-11-03 22:07:01 +00:00
|
|
|
var nodepoolSetFields map[string]struct{} = map[string]struct{}{
|
|
|
|
"node_config.0.oauth_scopes": struct{}{},
|
|
|
|
}
|
|
|
|
|
2017-03-06 22:59:24 +00:00
|
|
|
func testAccCheckContainerNodePoolMatches(n string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
config := testAccProvider.Meta().(*Config)
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes := rs.Primary.Attributes
|
2017-07-31 16:28:39 +00:00
|
|
|
nodepool, err := config.clientContainer.Projects.Zones.Clusters.NodePools.Get(
|
2017-03-06 22:59:24 +00:00
|
|
|
config.Project, attributes["zone"], attributes["cluster"], attributes["name"]).Do()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
if nodepool.Name != attributes["name"] {
|
2017-03-06 22:59:24 +00:00
|
|
|
return fmt.Errorf("NodePool not found")
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
type nodepoolTestField struct {
|
|
|
|
tfAttr string
|
|
|
|
gcpAttr interface{}
|
2017-03-06 22:59:24 +00:00
|
|
|
}
|
2017-07-31 16:28:39 +00:00
|
|
|
|
|
|
|
nodepoolTests := []nodepoolTestField{
|
|
|
|
{"initial_node_count", strconv.FormatInt(nodepool.InitialNodeCount, 10)},
|
2017-11-21 20:56:29 +00:00
|
|
|
{"management.0.auto_repair", nodepool.Management.AutoRepair},
|
|
|
|
{"management.0.auto_upgrade", nodepool.Management.AutoUpgrade},
|
2017-07-31 16:28:39 +00:00
|
|
|
{"node_config.0.machine_type", nodepool.Config.MachineType},
|
|
|
|
{"node_config.0.disk_size_gb", strconv.FormatInt(nodepool.Config.DiskSizeGb, 10)},
|
|
|
|
{"node_config.0.local_ssd_count", strconv.FormatInt(nodepool.Config.LocalSsdCount, 10)},
|
|
|
|
{"node_config.0.oauth_scopes", nodepool.Config.OauthScopes},
|
|
|
|
{"node_config.0.service_account", nodepool.Config.ServiceAccount},
|
|
|
|
{"node_config.0.metadata", nodepool.Config.Metadata},
|
|
|
|
{"node_config.0.image_type", nodepool.Config.ImageType},
|
|
|
|
{"node_config.0.labels", nodepool.Config.Labels},
|
|
|
|
{"node_config.0.tags", nodepool.Config.Tags},
|
2017-09-01 20:02:26 +00:00
|
|
|
{"node_config.0.preemptible", nodepool.Config.Preemptible},
|
2017-10-25 21:08:48 +00:00
|
|
|
{"node_config.0.min_cpu_platform", nodepool.Config.MinCpuPlatform},
|
2017-07-31 16:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, attrs := range nodepoolTests {
|
|
|
|
if c := nodepoolCheckMatch(attributes, attrs.tfAttr, attrs.gcpAttr); c != "" {
|
|
|
|
return fmt.Errorf(c)
|
|
|
|
}
|
2017-03-06 22:59:24 +00:00
|
|
|
}
|
2017-07-26 20:21:51 +00:00
|
|
|
|
|
|
|
tfAS := attributes["autoscaling.#"] == "1"
|
2017-07-31 16:28:39 +00:00
|
|
|
if gcpAS := nodepool.Autoscaling != nil && nodepool.Autoscaling.Enabled == true; tfAS != gcpAS {
|
2017-07-26 20:21:51 +00:00
|
|
|
return fmt.Errorf("Mismatched autoscaling status. TF State: %t. GCP State: %t", tfAS, gcpAS)
|
|
|
|
}
|
|
|
|
if tfAS {
|
2017-07-31 16:28:39 +00:00
|
|
|
if tf := attributes["autoscaling.0.min_node_count"]; strconv.FormatInt(nodepool.Autoscaling.MinNodeCount, 10) != tf {
|
2017-07-26 20:21:51 +00:00
|
|
|
return fmt.Errorf("Mismatched Autoscaling.MinNodeCount. TF State: %s. GCP State: %d",
|
2017-07-31 16:28:39 +00:00
|
|
|
tf, nodepool.Autoscaling.MinNodeCount)
|
2017-07-26 20:21:51 +00:00
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
if tf := attributes["autoscaling.0.max_node_count"]; strconv.FormatInt(nodepool.Autoscaling.MaxNodeCount, 10) != tf {
|
2017-07-26 20:21:51 +00:00
|
|
|
return fmt.Errorf("Mismatched Autoscaling.MaxNodeCount. TF State: %s. GCP State: %d",
|
2017-07-31 16:28:39 +00:00
|
|
|
tf, nodepool.Autoscaling.MaxNodeCount)
|
2017-07-26 20:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-02-24 00:55:07 +00:00
|
|
|
tfGA := attributes["node_config.0.guest_accelerator.#"] == "1"
|
|
|
|
if gcpGA := nodepool.Config.Accelerators != nil && len(nodepool.Config.Accelerators) == 1; tfGA != gcpGA {
|
|
|
|
if tf := attributes["node_config.0.guest_accelerator.0.type"]; nodepool.Config.Accelerators[0].AcceleratorType != tf {
|
|
|
|
return fmt.Errorf("Mismatched NodeConfig.Accelerators type. TF State: %s. GCP State: %s",
|
|
|
|
tf, nodepool.Config.Accelerators[0].AcceleratorType)
|
|
|
|
}
|
|
|
|
if tf := attributes["node_config.0.guest_accelerator.0.count"]; strconv.FormatInt(nodepool.Config.Accelerators[0].AcceleratorCount, 10) != tf {
|
|
|
|
return fmt.Errorf("Mismatched NodeConfig.Accelerators count. TF State: %s. GCP State: %d",
|
|
|
|
tf, nodepool.Config.Accelerators[0].AcceleratorCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-06 22:59:24 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-26 20:21:51 +00:00
|
|
|
func testAccContainerNodePool_basic(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
2017-03-06 22:59:24 +00:00
|
|
|
resource "google_container_cluster" "cluster" {
|
2017-07-26 20:21:51 +00:00
|
|
|
name = "%s"
|
2017-03-06 22:59:24 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
2017-07-26 20:21:51 +00:00
|
|
|
name = "%s"
|
2017-03-06 22:59:24 +00:00
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 2
|
2017-07-26 20:21:51 +00:00
|
|
|
}`, cluster, np)
|
|
|
|
}
|
|
|
|
|
2017-10-04 23:41:35 +00:00
|
|
|
func testAccContainerNodePool_namePrefix(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
name_prefix = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 2
|
|
|
|
}`, cluster, np)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerNodePool_noName(cluster string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 2
|
|
|
|
}`, cluster)
|
|
|
|
}
|
|
|
|
|
2017-07-26 20:21:51 +00:00
|
|
|
func testAccContainerNodePool_autoscaling(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 2
|
|
|
|
autoscaling {
|
|
|
|
min_node_count = 1
|
|
|
|
max_node_count = 3
|
|
|
|
}
|
|
|
|
}`, cluster, np)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerNodePool_updateAutoscaling(cluster, np string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 3
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 2
|
|
|
|
autoscaling {
|
2017-09-26 22:57:51 +00:00
|
|
|
min_node_count = 0
|
2017-07-26 20:21:51 +00:00
|
|
|
max_node_count = 5
|
|
|
|
}
|
|
|
|
}`, cluster, np)
|
|
|
|
}
|
2017-07-31 16:28:39 +00:00
|
|
|
|
2017-10-04 00:09:34 +00:00
|
|
|
func testAccContainerNodePool_additionalZones(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
node_count = 2
|
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccContainerNodePool_resize(cluster, nodePool string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
additional_zones = [
|
|
|
|
"us-central1-b",
|
|
|
|
"us-central1-c"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
node_count = 3
|
|
|
|
}`, cluster, nodePool)
|
|
|
|
}
|
|
|
|
|
2017-11-21 20:56:29 +00:00
|
|
|
func testAccContainerNodePool_withManagement(cluster, nodePool, management string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "np_with_management" {
|
|
|
|
name = "%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 1
|
|
|
|
|
|
|
|
%s
|
|
|
|
|
|
|
|
node_config {
|
|
|
|
machine_type = "g1-small"
|
|
|
|
disk_size_gb = 10
|
|
|
|
oauth_scopes = ["compute-rw", "storage-ro", "logging-write", "monitoring"]
|
|
|
|
}
|
|
|
|
}`, cluster, nodePool, management)
|
|
|
|
}
|
|
|
|
|
2017-07-31 16:28:39 +00:00
|
|
|
func nodepoolCheckMatch(attributes map[string]string, attr string, gcp interface{}) string {
|
|
|
|
if gcpList, ok := gcp.([]string); ok {
|
2017-11-03 22:07:01 +00:00
|
|
|
if _, ok := nodepoolSetFields[attr]; ok {
|
|
|
|
return nodepoolCheckSetMatch(attributes, attr, gcpList)
|
|
|
|
}
|
2017-07-31 16:28:39 +00:00
|
|
|
return nodepoolCheckListMatch(attributes, attr, gcpList)
|
|
|
|
}
|
|
|
|
if gcpMap, ok := gcp.(map[string]string); ok {
|
|
|
|
return nodepoolCheckMapMatch(attributes, attr, gcpMap)
|
|
|
|
}
|
2017-09-01 20:02:26 +00:00
|
|
|
if gcpBool, ok := gcp.(bool); ok {
|
|
|
|
return checkBoolMatch(attributes, attr, gcpBool)
|
|
|
|
}
|
2017-07-31 16:28:39 +00:00
|
|
|
tf := attributes[attr]
|
|
|
|
if tf != gcp {
|
|
|
|
return nodepoolMatchError(attr, tf, gcp)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func nodepoolCheckSetMatch(attributes map[string]string, attr string, gcpList []string) string {
|
|
|
|
num, err := strconv.Atoi(attributes[attr+".#"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err)
|
|
|
|
}
|
|
|
|
if num != len(gcpList) {
|
|
|
|
return fmt.Sprintf("NodePool has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpList))
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't know the exact keys of the elements, so go through the whole list looking for matching ones
|
|
|
|
tfAttr := []string{}
|
|
|
|
for k, v := range attributes {
|
|
|
|
if strings.HasPrefix(k, attr) && !strings.HasSuffix(k, "#") {
|
|
|
|
tfAttr = append(tfAttr, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sort.Strings(tfAttr)
|
|
|
|
sort.Strings(gcpList)
|
|
|
|
if reflect.DeepEqual(tfAttr, gcpList) {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return nodepoolMatchError(attr, tfAttr, gcpList)
|
|
|
|
}
|
|
|
|
|
|
|
|
func nodepoolCheckListMatch(attributes map[string]string, attr string, gcpList []string) string {
|
|
|
|
num, err := strconv.Atoi(attributes[attr+".#"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err)
|
|
|
|
}
|
|
|
|
if num != len(gcpList) {
|
|
|
|
return fmt.Sprintf("NodePool has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpList))
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, gcp := range gcpList {
|
|
|
|
if tf := attributes[fmt.Sprintf("%s.%d", attr, i)]; tf != gcp {
|
|
|
|
return nodepoolMatchError(fmt.Sprintf("%s[%d]", attr, i), tf, gcp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func nodepoolCheckMapMatch(attributes map[string]string, attr string, gcpMap map[string]string) string {
|
|
|
|
num, err := strconv.Atoi(attributes[attr+".%"])
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Sprintf("Error in number conversion for attribute %s: %s", attr, err)
|
|
|
|
}
|
|
|
|
if num != len(gcpMap) {
|
|
|
|
return fmt.Sprintf("NodePool has mismatched %s size.\nTF Size: %d\nGCP Size: %d", attr, num, len(gcpMap))
|
|
|
|
}
|
|
|
|
|
|
|
|
for k, gcp := range gcpMap {
|
|
|
|
if tf := attributes[fmt.Sprintf("%s.%s", attr, k)]; tf != gcp {
|
|
|
|
return nodepoolMatchError(fmt.Sprintf("%s[%s]", attr, k), tf, gcp)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func nodepoolMatchError(attr, tf interface{}, gcp interface{}) string {
|
|
|
|
return fmt.Sprintf("NodePool has mismatched %s.\nTF State: %+v\nGCP State: %+v", attr, tf, gcp)
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerNodePool_withNodeConfig() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-07-31 16:28:39 +00:00
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
}
|
|
|
|
resource "google_container_node_pool" "np_with_node_config" {
|
|
|
|
name = "tf-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 1
|
|
|
|
node_config {
|
|
|
|
machine_type = "g1-small"
|
|
|
|
disk_size_gb = 10
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/compute",
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring"
|
|
|
|
]
|
2017-09-01 20:02:26 +00:00
|
|
|
preemptible = true
|
2017-10-25 21:08:48 +00:00
|
|
|
min_cpu_platform = "Intel Broadwell"
|
2017-07-31 16:28:39 +00:00
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|
2017-07-31 16:28:39 +00:00
|
|
|
|
2018-02-24 00:55:07 +00:00
|
|
|
func testAccContainerNodePool_withGPU() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
initial_node_count = 1
|
|
|
|
node_version = "1.9.2-gke.1"
|
|
|
|
min_master_version = "1.9.2-gke.1"
|
|
|
|
}
|
|
|
|
resource "google_container_node_pool" "np_with_gpu" {
|
|
|
|
name = "tf-nodepool-test-%s"
|
|
|
|
zone = "us-central1-c"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 1
|
|
|
|
node_config {
|
|
|
|
machine_type = "n1-standard-1"
|
|
|
|
disk_size_gb = 10
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/devstorage.read_only",
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring",
|
|
|
|
"https://www.googleapis.com/auth/service.management.readonly",
|
|
|
|
"https://www.googleapis.com/auth/servicecontrol",
|
|
|
|
"https://www.googleapis.com/auth/trace.append"
|
|
|
|
]
|
|
|
|
preemptible = true
|
|
|
|
service_account = "default"
|
|
|
|
image_type = "COS"
|
|
|
|
guest_accelerator = [
|
|
|
|
{
|
|
|
|
type = "nvidia-tesla-k80"
|
|
|
|
count = 1
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
2017-11-28 00:32:00 +00:00
|
|
|
func testAccContainerNodePool_withNodeConfigScopeAlias() string {
|
|
|
|
return fmt.Sprintf(`
|
2017-07-31 16:28:39 +00:00
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
}
|
|
|
|
resource "google_container_node_pool" "np_with_node_config_scope_alias" {
|
|
|
|
name = "tf-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 1
|
|
|
|
node_config {
|
|
|
|
machine_type = "g1-small"
|
|
|
|
disk_size_gb = 10
|
|
|
|
oauth_scopes = ["compute-rw", "storage-ro", "logging-write", "monitoring"]
|
|
|
|
}
|
|
|
|
}`, acctest.RandString(10), acctest.RandString(10))
|
2017-11-28 00:32:00 +00:00
|
|
|
}
|