Skip to content

Commit

Permalink
Remove SchemaConfigModeAttr (#11506) (#19207)
Browse files Browse the repository at this point in the history
[upstream:93bcf85b934cdfdc5d45ae2f876118ab8dd8d3e9]

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 21, 2024
1 parent cfed4de commit 301eeab
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 348 deletions.
18 changes: 18 additions & 0 deletions .changelog/11506.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
```release-note:breaking-change
composer: `ip_allocation_policy = []` in `google_composer_environment` is no longer valid configuration. Removing the field from configuration should not produce a diff.
```
```release-note:breaking-change
compute: `secondary_ip_ranges = []` in `google_compute_subnetwork` is no longer valid configuration. To set an explicitly empty list, use `send_secondary_ip_range_if_empty` and completely remove `secondary_ip_range` from config.
```
```release-note:breaking-change
compute: `guest_accelerator = []` is no longer valid configuration in `google_compute_instance`. To explicitly set an empty list of objects, set guest_accelerator.count = 0.
```
```release-note:breaking-change
compute: `google_compute_instance_from_template` and `google_compute_instance_from_machine_image` `network_interface.alias_ip_range, network_interface.access_config, attached_disk, guest_accelerator, service_account, scratch_disk` can no longer be set to an empty block `[]`. Removing the fields from configuration should not produce a diff.
```
```release-note:breaking-change
container: `guest_accelerator = []` is no longer valid configuration in `google_container_cluster` and `google_container_node_pool`. To explicitly set an empty list of objects, set guest_accelerator.count = 0.
```
```release-note:breaking-change
container: `guest_accelerator.gpu_driver_installation_config = []` and `guest_accelerator.gpu_sharing_config = []` are no longer valid configuration in `google_container_cluster` and `google_container_node_pool`. Removing the fields from configuration should not produce a diff.
```
1 change: 0 additions & 1 deletion google/services/composer/resource_composer_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func ResourceComposerEnvironment() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
MaxItems: 1,
Description: `Configuration for controlling how IPs are allocated in the GKE cluster. Cannot be updated.`,
Elem: &schema.Resource{
Expand Down
1 change: 0 additions & 1 deletion google/services/compute/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ func ResourceComputeInstance() *schema.Resource {
Optional: true,
Computed: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Description: `List of the type and count of accelerator cards attached to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
11 changes: 0 additions & 11 deletions google/services/compute/resource_compute_instance_from_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,6 @@ func computeInstanceFromTemplateSchema() map[string]*schema.Schema {
s[field].Optional = true
}

// schema.SchemaConfigModeAttr allows these fields to be removed in Terraform 0.12.
// Passing field_name = [] in this mode differentiates between an intentionally empty
// block vs an ignored computed block.
nic := s["network_interface"].Elem.(*schema.Resource)
nic.Schema["alias_ip_range"].ConfigMode = schema.SchemaConfigModeAttr
nic.Schema["access_config"].ConfigMode = schema.SchemaConfigModeAttr

for _, field := range []string{"attached_disk", "guest_accelerator", "service_account", "scratch_disk"} {
s[field].ConfigMode = schema.SchemaConfigModeAttr
}

// Remove deprecated/removed fields that are never d.Set. We can't
// programmatically remove all of them, because some of them still have d.Set
// calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,49 +243,6 @@ func TestAccComputeInstanceFromTemplate_overrideScheduling(t *testing.T) {
})
}

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

var instance compute.Instance
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
templateName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
resourceName := "google_compute_instance_from_template.inst"

// First config is a basic instance from template, second tests the empty list syntax
config1 := testAccComputeInstanceFromTemplate_012_removableFieldsTpl(templateName) +
testAccComputeInstanceFromTemplate_012_removableFields1(instanceName)
config2 := testAccComputeInstanceFromTemplate_012_removableFieldsTpl(templateName) +
testAccComputeInstanceFromTemplate_012_removableFields2(instanceName)

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeInstanceFromTemplateDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: config1,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, resourceName, &instance),

resource.TestCheckResourceAttr(resourceName, "service_account.#", "1"),
resource.TestCheckResourceAttr(resourceName, "service_account.0.scopes.#", "3"),
),
},
{
Config: config2,
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, resourceName, &instance),

// Check that fields were able to be removed
resource.TestCheckResourceAttr(resourceName, "scratch_disk.#", "0"),
resource.TestCheckResourceAttr(resourceName, "attached_disk.#", "0"),
resource.TestCheckResourceAttr(resourceName, "network_interface.0.alias_ip_range.#", "0"),
),
},
},
})
}

func TestAccComputeInstanceFromTemplate_overrideMetadataDotStartupScript(t *testing.T) {
var instance compute.Instance
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
Expand Down Expand Up @@ -973,84 +930,6 @@ resource "google_compute_instance_from_template" "inst" {
`, templateDisk, template, instance)
}

func testAccComputeInstanceFromTemplate_012_removableFieldsTpl(template string) string {

return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance_template" "foobar" {
name = "%s"
machine_type = "e2-medium"
disk {
source_image = data.google_compute_image.my_image.self_link
auto_delete = true
disk_size_gb = 20
boot = true
}
network_interface {
network = "default"
}
metadata = {
foo = "bar"
}
service_account {
scopes = ["userinfo-email", "compute-ro", "storage-ro"]
}
can_ip_forward = true
}
`, template)
}

func testAccComputeInstanceFromTemplate_012_removableFields1(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance_from_template" "inst" {
name = "%s"
zone = "us-central1-a"
allow_stopping_for_update = true
source_instance_template = google_compute_instance_template.foobar.self_link
}
`, instance)
}

func testAccComputeInstanceFromTemplate_012_removableFields2(instance string) string {
return fmt.Sprintf(`
resource "google_compute_instance_from_template" "inst" {
name = "%s"
zone = "us-central1-a"
allow_stopping_for_update = true
source_instance_template = google_compute_instance_template.foobar.self_link
// Overrides
network_interface {
alias_ip_range = []
}
service_account = []
scratch_disk = []
attached_disk = []
timeouts {
create = "10m"
update = "10m"
}
}
`, instance)
}

func testAccComputeInstanceFromTemplate_overrideMetadataDotStartupScript(instance, template string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down
46 changes: 0 additions & 46 deletions google/services/compute/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,20 +1731,6 @@ func TestAccComputeInstance_guestAcceleratorSkip(t *testing.T) {
testAccCheckComputeInstanceLacksGuestAccelerator(&instance),
),
},
// Recreate with guest_accelerator = []
{
Config: testAccComputeInstance_guestAcceleratorEmptyBlock(instanceName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
testAccCheckComputeInstanceLacksGuestAccelerator(&instance),
),
},
// Check that count = 0 is the same as empty block []
{
Config: testAccComputeInstance_guestAccelerator(instanceName, 0),
ExpectNonEmptyPlan: false,
PlanOnly: true,
},
},
})

Expand Down Expand Up @@ -6526,38 +6512,6 @@ resource "google_compute_instance" "foobar" {
`, instance, count)
}

func testAccComputeInstance_guestAcceleratorEmptyBlock(instance string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "foobar" {
name = "%s"
machine_type = "n1-standard-1" // can't be e2 because of guest_accelerator
zone = "us-east1-d"
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}
network_interface {
network = "default"
}
scheduling {
# Instances with guest accelerators do not support live migration.
on_host_maintenance = "TERMINATE"
}
guest_accelerator = []
}
`, instance)
}

func testAccComputeInstance_minCpuPlatform(instance string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
Expand Down
7 changes: 3 additions & 4 deletions google/services/compute/resource_compute_subnetwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,10 +283,9 @@ An 'ACTIVE' subnetwork is one that is currently being used for Envoy-based load
A 'BACKUP' subnetwork is one that is ready to be promoted to 'ACTIVE' or is currently draining. Possible values: ["ACTIVE", "BACKUP"]`,
},
"secondary_ip_range": {
Type: schema.TypeList,
Computed: true,
Optional: true,
ConfigMode: schema.SchemaConfigModeAttr,
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `An array of configurations for secondary IP ranges for VM instances
contained in this subnetwork. The primary IP of such VM must belong
to the primary ipCidrRange of the subnetwork. The alias IPs may belong
Expand Down
57 changes: 0 additions & 57 deletions google/services/compute/resource_compute_subnetwork_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,6 @@ func TestAccComputeSubnetwork_secondaryIpRanges(t *testing.T) {
testAccCheckComputeSubnetworkHasSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
),
},
{
Config: testAccComputeSubnetwork_secondaryIpRanges_update4(cnName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeSubnetworkExists(t, "google_compute_subnetwork.network-with-private-secondary-ip-ranges", &subnetwork),
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update1", "192.168.10.0/24"),
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update2", "192.168.11.0/24"),
),
},
{
Config: testAccComputeSubnetwork_secondaryIpRanges_update1(cnName, subnetworkName),
Check: resource.ComposeTestCheckFunc(
Expand Down Expand Up @@ -241,12 +233,6 @@ func TestAccComputeSubnetwork_secondaryIpRanges_sendEmpty(t *testing.T) {
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update1", "192.168.10.0/24"),
),
},
// Check that empty block secondary_ip_range = [] is not different
{
Config: testAccComputeSubnetwork_sendEmpty_emptyBlock(cnName, subnetworkName, "true"),
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
// Apply two secondary_ip_range
{
Config: testAccComputeSubnetwork_sendEmpty_double(cnName, subnetworkName, "true"),
Expand Down Expand Up @@ -279,14 +265,6 @@ func TestAccComputeSubnetwork_secondaryIpRanges_sendEmpty(t *testing.T) {
PlanOnly: true,
ExpectNonEmptyPlan: false,
},
// Remove with empty block []
{
Config: testAccComputeSubnetwork_sendEmpty_emptyBlock(cnName, subnetworkName, "true"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeSubnetworkExists(t, "google_compute_subnetwork.network-with-private-secondary-ip-ranges", &subnetwork),
testAccCheckComputeSubnetworkHasNotSecondaryIpRange(&subnetwork, "tf-test-secondary-range-update1", "192.168.10.0/24"),
),
},
},
})
}
Expand Down Expand Up @@ -688,23 +666,6 @@ resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges"
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_secondaryIpRanges_update4(cnName, subnetworkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.custom-test.self_link
secondary_ip_range = []
}
`, cnName, subnetworkName)
}

func testAccComputeSubnetwork_sendEmpty_removed(cnName, subnetworkName, sendEmpty string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
Expand All @@ -722,24 +683,6 @@ resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges"
`, cnName, subnetworkName, sendEmpty)
}

func testAccComputeSubnetwork_sendEmpty_emptyBlock(cnName, subnetworkName, sendEmpty string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
name = "%s"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "network-with-private-secondary-ip-ranges" {
name = "%s"
ip_cidr_range = "10.2.0.0/16"
region = "us-central1"
network = google_compute_network.custom-test.self_link
secondary_ip_range = []
send_secondary_ip_range_if_empty = "%s"
}
`, cnName, subnetworkName, sendEmpty)
}

func testAccComputeSubnetwork_sendEmpty_single(cnName, subnetworkName, sendEmpty string) string {
return fmt.Sprintf(`
resource "google_compute_network" "custom-test" {
Expand Down
13 changes: 4 additions & 9 deletions google/services/container/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,10 @@ func schemaNodeConfig() *schema.Schema {
},

"guest_accelerator": {
Type: schema.TypeList,
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,
Type: schema.TypeList,
Optional: true,
Computed: true,
ForceNew: true,
Description: `List of the type and count of accelerator cards attached to the instance.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -157,7 +154,6 @@ func schemaNodeConfig() *schema.Schema {
Optional: true,
Computed: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Description: `Configuration for auto installation of GPU driver.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand All @@ -182,7 +178,6 @@ func schemaNodeConfig() *schema.Schema {
MaxItems: 1,
Optional: true,
ForceNew: true,
ConfigMode: schema.SchemaConfigModeAttr,
Description: `Configuration for GPU sharing.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
Expand Down
Loading

0 comments on commit 301eeab

Please sign in to comment.