Skip to content

Commit

Permalink
0.12 Computed+Optional Attr syntax fixes (hashicorp#617)
Browse files Browse the repository at this point in the history
<!-- This change is generated by MagicModules. -->
Original Author: @rileykarson
  • Loading branch information
modular-magician authored and rileykarson committed Apr 17, 2019
1 parent 2b2111a commit 53b0f39
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 7 deletions.
3 changes: 3 additions & 0 deletions google-beta/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ var schemaNodeConfig = &schema.Schema{
Optional: true,
Computed: true,
ForceNew: true,
// Legacy config mode allows removing GPU's from an existing resource
// See https://www.terraform.io/docs/configuration/attr-as-blocks.html
ConfigMode: schema.SchemaConfigModeAttr,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"count": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func TestAccComputeInstanceFromTemplate_012_removableFields(t *testing.T) {
testAccCheckComputeInstanceExists(resourceName, &instance),

// Check that fields were able to be removed
resource.TestCheckResourceAttr(resourceName, "service_account.#", "0"),
resource.TestCheckResourceAttr(resourceName, "scratch_disk.#", "0"),
resource.TestCheckResourceAttr(resourceName, "attached_disk.#", "0"),
resource.TestCheckResourceAttr(resourceName, "network_interface.0.alias_ip_range.#", "0"),
Expand Down
84 changes: 80 additions & 4 deletions google-beta/resource_container_node_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,39 @@ func TestAccContainerNodePool_regionalClusters(t *testing.T) {
})
}

func TestAccContainerNodePool_012_ConfigModeAttr(t *testing.T) {
t.Parallel()

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{
{
Config: testAccContainerNodePool_012_ConfigModeAttr1(cluster, np),
},
{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"max_pods_per_node"},
},
{
Config: testAccContainerNodePool_012_ConfigModeAttr2(cluster, np),
},
{
ResourceName: "google_container_node_pool.np",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"max_pods_per_node"},
},
},
})
}

func testAccCheckContainerNodePoolDestroy(s *terraform.State) error {
config := testAccProvider.Meta().(*Config)

Expand Down Expand Up @@ -935,11 +968,11 @@ resource "google_container_node_pool" "np_with_gpu" {
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/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/servicecontrol",
"https://www.googleapis.com/auth/trace.append"
]
Expand Down Expand Up @@ -1020,3 +1053,46 @@ resource "google_container_node_pool" "np" {
version = "${data.google_container_engine_versions.central1a.valid_node_versions.0}"
}`, cluster, np)
}

func testAccContainerNodePool_012_ConfigModeAttr1(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
zone = "us-central1-f"
initial_node_count = 3
}
resource "google_container_node_pool" "np" {
name = "%s"
zone = "us-central1-f"
cluster = "${google_container_cluster.cluster.name}"
initial_node_count = 1
node_config {
guest_accelerator {
count = 1
type = "nvidia-tesla-p100"
}
}
}`, cluster, np)
}

func testAccContainerNodePool_012_ConfigModeAttr2(cluster, np string) string {
return fmt.Sprintf(`
resource "google_container_cluster" "cluster" {
name = "%s"
zone = "us-central1-f"
initial_node_count = 3
}
resource "google_container_node_pool" "np" {
name = "%s"
zone = "us-central1-f"
cluster = "${google_container_cluster.cluster.name}"
initial_node_count = 1
node_config {
guest_accelerator = []
}
}`, cluster, np)
}
6 changes: 4 additions & 2 deletions website/docs/r/container_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ should be located. These must be in the same region as the cluster zone for
zonal clusters, or in the region of a regional cluster. In a multi-zonal cluster,
the number of nodes specified in `initial_node_count` is created in
all specified zones as well as the primary zone. If specified for a regional
cluster, nodes will only be created in these zones. `additional_zones` has been
deprecated in favour of `node_locations`.
cluster, nodes will only be created in these zones. `additional_zones` has been
deprecated in favour of `node_locations`.

* `addons_config` - (Optional) The configuration for addons supported by GKE.
Structure is documented below.
Expand Down Expand Up @@ -472,6 +472,8 @@ The `node_config` block supports:

* `guest_accelerator` - (Optional) List of the type and count of accelerator cards attached to the instance.
Structure documented below.
To support removal of guest_accelerators in Terraform 0.12 this field is an
[Attribute as Block](/docs/configuration/attr-as-blocks.html)

* `image_type` - (Optional) The image type to use for this node. Note that changing the image type
will delete and recreate all nodes in the node pool.
Expand Down

0 comments on commit 53b0f39

Please sign in to comment.