0.12 Computed+Optional Attr syntax fixes (#3452)

<!-- This change is generated by MagicModules. -->
Original Author: @rileykarson
This commit is contained in:
The Magician 2019-04-17 11:11:47 -07:00 committed by Riley Karson
parent 2747e8261d
commit 9ac574e185
4 changed files with 87 additions and 7 deletions

View File

@ -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": {

View File

@ -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"),

View File

@ -430,6 +430,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)
@ -739,11 +772,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"
]
@ -824,3 +857,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)
}

View File

@ -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.
@ -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.