Skip to content

Remove SchemaConfigModeAttr #11506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/content/develop/breaking-changes/breaking-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ For more information, see
* <a name="field-removing-diff-suppress"></a> Removing diff suppression from a field.
* For MMv1 resources, removing `diff_suppress_func` from a field.
* For handwritten resources, removing `DiffSuppressFunc` from a field.
* <a name="field-adding-subfield-to-config-mode-attr"></a> Adding a subfield to
a SchemaConfigModeAttr field.
* Subfields of SchemaConfigModeAttr fields are treated as required even if the schema says they are optional.
* Removing update support from a field.

### Making validation more strict
Expand Down
1 change: 0 additions & 1 deletion mmv1/products/compute/Subnetwork.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ properties:
api_name: secondaryIpRanges
unordered_list: true
default_from_api: true
schema_config_mode_attr: true
send_empty_value: true
description: |
An array of configurations for secondary IP ranges for VM instances
Expand Down
3 changes: 0 additions & 3 deletions mmv1/templates/terraform/schema_property.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
<% if property.default_from_api -%>
Computed: true,
Optional: true,
<% if property.schema_config_mode_attr -%>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick way to stop accidental generation going forward. Will need to fully remove probably after/during Go Rewrite

ConfigMode: schema.SchemaConfigModeAttr,
<% end -%>
<% elsif property.required -%>
Required: true,
<% elsif property.output -%>
Expand Down
3 changes: 0 additions & 3 deletions mmv1/templates/terraform/schema_property.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
{{ if .DefaultFromApi -}}
Computed: true,
Optional: true,
{{ if .SchemaConfigModeAttr -}}
ConfigMode: schema.SchemaConfigModeAttr,
{{ end -}}
{{ else if .Required -}}
Required: true,
{{ else if .Output -}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,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
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,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
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,6 @@ func computeInstanceFromMachineImageSchema() 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
}

recurseOnSchema(s, func(field *schema.Schema) {
// We don't want to accidentally use default values to override the instance
// machine image, so remove defaults.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,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 @@ -378,49 +378,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 @@ -1496,84 +1453,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
Original file line number Diff line number Diff line change
Expand Up @@ -1741,20 +1741,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 @@ -7154,38 +7140,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
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,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 @@ -244,12 +236,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 @@ -282,14 +268,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 @@ -691,23 +669,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 @@ -725,24 +686,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
Loading
Loading