2017-03-06 22:59:24 +00:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-07-26 20:21:51 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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-"),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
ImportStateVerifyIgnore: []string{"name_prefix"},
|
2017-10-04 23:41:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-10-04 23:41:35 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np_with_node_config",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
// autoscaling.# = 0 is equivalent to no autoscaling at all,
|
|
|
|
// but will still cause an import diff
|
|
|
|
ImportStateVerifyIgnore: []string{"autoscaling.#"},
|
2017-07-31 16:28:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2018-03-15 20:28:30 +00:00
|
|
|
func TestAccContainerNodePool_withWorkloadMetadataConfig(t *testing.T) {
|
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckContainerClusterDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
{
|
|
|
|
Config: testAccContainerNodePool_withWorkloadMetadataConfig(),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.with_workload_metadata_config",
|
|
|
|
"node_config.0.workload_metadata_config.0.node_metadata", "SECURE"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_node_pool.with_workload_metadata_config",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
// Import always uses the v1 API, so beta features don't get imported.
|
|
|
|
ImportStateVerifyIgnore: []string{
|
|
|
|
"node_config.0.workload_metadata_config.#",
|
|
|
|
"node_config.0.workload_metadata_config.0.node_metadata",
|
|
|
|
},
|
|
|
|
},
|
2018-03-15 20:28:30 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2018-03-16 00:08:39 +00:00
|
|
|
ResourceName: "google_container_node_pool.np_with_gpu",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2018-02-24 00:55:07 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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(
|
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np_with_management",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-11-21 20:56:29 +00:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_withManagement(cluster, nodePool, management),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
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"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np_with_management",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-11-21 20:56:29 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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(),
|
2018-03-16 00:08:39 +00:00
|
|
|
},
|
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np_with_node_config_scope_alias",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
2017-07-31 16:28:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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(
|
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
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-07-26 20:21:51 +00:00
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccContainerNodePool_updateAutoscaling(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
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
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
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(
|
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
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
resource.TestStep{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
// autoscaling.# = 0 is equivalent to no autoscaling at all,
|
|
|
|
// but will still cause an import diff
|
|
|
|
ImportStateVerifyIgnore: []string{"autoscaling.#"},
|
|
|
|
},
|
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(
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "2"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-04 00:09:34 +00:00
|
|
|
{
|
|
|
|
Config: testAccContainerNodePool_resize(cluster, np),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
resource.TestCheckResourceAttr("google_container_node_pool.np", "node_count", "3"),
|
|
|
|
),
|
|
|
|
},
|
2018-03-16 00:08:39 +00:00
|
|
|
{
|
|
|
|
ResourceName: "google_container_node_pool.np",
|
|
|
|
ImportState: true,
|
|
|
|
ImportStateVerify: true,
|
|
|
|
},
|
2017-10-04 00:09:34 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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-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-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-03-15 20:28:30 +00:00
|
|
|
func testAccContainerNodePool_withWorkloadMetadataConfig() string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
data "google_container_engine_versions" "central1a" {
|
|
|
|
zone = "us-central1-a"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_cluster" "cluster" {
|
|
|
|
name = "tf-cluster-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
initial_node_count = 1
|
|
|
|
min_master_version = "${data.google_container_engine_versions.central1a.latest_master_version}"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "google_container_node_pool" "with_workload_metadata_config" {
|
|
|
|
name = "tf-nodepool-test-%s"
|
|
|
|
zone = "us-central1-a"
|
|
|
|
cluster = "${google_container_cluster.cluster.name}"
|
|
|
|
initial_node_count = 1
|
|
|
|
node_config {
|
|
|
|
oauth_scopes = [
|
|
|
|
"https://www.googleapis.com/auth/logging.write",
|
|
|
|
"https://www.googleapis.com/auth/monitoring"
|
|
|
|
]
|
|
|
|
|
|
|
|
workload_metadata_config {
|
|
|
|
node_metadata = "SECURE"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, acctest.RandString(10), acctest.RandString(10))
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|