Exhaustive acceptance testing#
Exhaustive acceptance testing verifies that newly added configurable fields work across their full Terraform lifecycle—SET, in-place MODIFY, and UNSET—at every level of nesting.
What --exhaustive checks#
When enabled, diff-processor detect-missing-tests --exhaustive inspects every newly added configurable field (both leaf attributes and nested blocks, excluding project, deletion_policy, IAM condition blocks, and Computed-only outputs) for three transitions:
| Transition | Requirement | Exempt when |
|---|---|---|
SET | Present (non-null) in at least one applied test step. | Never exempt for configurable fields. |
MODIFY | Changes value across consecutive steps on the same resource instance with an in-place PreApply plan check (plancheck.ResourceActionUpdate or acctest.ExpectNoDelete()). Optional defaultless single-value enums and optional empty MaxItems: 1 nested blocks satisfy MODIFY via an in-place unset -> set transition. | Resource is not updatable (resource_not_updatable), field is ForceNew / immutable: true (force_new), field is a Required or schema-defaulted single-value enum (single_value_enum), or field is a Required empty MaxItems: 1 nested block (empty_block). |
UNSET | Mutable fields/blocks: transitions from present to absent (omitted or = null) in an in-place update step while its immediate parent block remains present.ForceNew fields or non-updatable resources: omitted in at least one valid apply step (for example, a separate minimal test) while its parent remains present. | Top-level Required (required), nested Required (required_in_parent), or Optional+Computed such as default_from_api: true (optional_computed). |
Single-child block shortcut: If an optional, non-
Computedancestor block has only one configurable child lineage in the schema and that child has no schema default (Default/DefaultFunc), omitting the ancestor block (while its own parent stays present) satisfiesUNSETfor that child without writing an emptyblock {}.
Steps with ExpectError, PlanOnly: true, Destroy: true, ImportState: true, or RefreshState: true are ignored and do not count toward coverage.
Running the check#
Run the full GA + Beta provider validation script (including --exhaustive missing-test detection) from the magic-modules root:
./.agents/skills/utils/validate-provider-changes/scripts/validate_provider_changes.sh --exhaustiveOr invoke diff-processor directly (using --format=markdown for a readable per-field coverage table):
./bin/diff-processor detect-missing-tests --exhaustive --format=markdown <SERVICES_DIR>MMv1 sample patterns#
Prefer MMv1 samples over handwritten tests whenever possible. For full attribute details, see MMv1 sample reference.
Sample-level defaults and shorthand#
Define shared config_path, resource_id_vars, vars, test_env_vars, test_vars_overrides, oics_vars_overrides, and ignore_read_extra once at the sample level. Steps inherit those defaults and override only what changes (ignore_read_extra merges without duplicates).
- 0-step shorthand: Omit
steps:on a single-step sample to generate a single step named<sample.name>. - Unnamed steps: Omit
step.namewhen it matchessample.name;config_pathinherits from the sample (or defaults totemplates/terraform/samples/services/<product>/<step_name>.tf.tmpl). - Unused inherited var pruning: Sample-inherited variables unused by a step’s template (for example, helper resource IDs omitted in a clear/unset step) are automatically pruned from that step’s generated test
context, while sample-level validation still fails if a variable is unused across every step.
Mutable scalars (string, bool, int)#
Use a single .tf.tmpl with vars: for SET -> MODIFY -> UNSET. Setting a vars: key to YAML null (or ~) renders nil in test context (attr = null in tests) and omits the attribute line in docs and OiCS configs. Exercise bool fields across both true and false (for example, true -> false -> null).
samples:
- name: example_widget_update
primary_resource_id: default
config_path: templates/terraform/samples/services/example/example_widget_update.tf.tmpl
resource_id_vars:
widget_id: my-widget
steps:
- vars:
description: initial description
enabled: 'true'
max_retries: '3'
- vars:
description: updated description
enabled: 'false'
max_retries: '5'
- vars:
description: null
enabled: null
max_retries: nullresource "google_example_widget" "{{$.PrimaryResourceId}}" {
widget_id = "{{index $.ResourceIdVars "widget_id"}}"
description = "{{index $.Vars "description"}}"
enabled = {{index $.Vars "enabled"}}
max_retries = {{index $.Vars "max_retries"}}
}Nested blocks, lists, maps, and references#
Nested HCL blocks cannot be assigned = null. Use separate plain-HCL .tf.tmpl files per structural step, and tear down blocks bottom-up so each child is unset while its parent remains present:
- Single-child optional non-
Computedblock (defaultless child): unsetting the parent block directly covers both child and parentUNSET.- Optional empty
MaxItems: 1block (properties: []or only children withoutput: true, withallow_empty_object: true): Because the block only has two HCL states (absent and{}), coverSET,UNSET, andMODIFYwith an in-placeSET -> UNSET -> re-SET(orUNSET -> SET -> UNSET) sequence while its parent block remains present.
- Optional empty
- Multi-child block that disallows empty objects (
!allow_empty_object): Use a 2-step sibling swap before removing the parent (scales to any number of optional childrenc1..cNin 2 steps):- Create (
_full): setc1andc2..cN. - Modify (
_update): modifyc1andc2..cNin place. - Unset
c2..cN(_unset_rest): keepc1set, omitc2..cN(parent stays non-empty). - Unset
c1(_unset_first): omitc1, restorec2..cN(parent stays non-empty). - Unset parent (
_unset_parent): omit the parent block entirely.
- Create (
samples:
- name: example_widget_policy_full
primary_resource_id: default
resource_id_vars:
widget_id: my-widget
steps:
- name: example_widget_policy_full
- name: example_widget_policy_update
- name: example_widget_policy_unset_rest
- name: example_widget_policy_unset_first
- name: example_widget_policy_unset_parentOnly Step 0 (unless exclude_basic_doc: true) and steps with include_step_doc: true generate documentation and Open in Cloud Shell (OiCS) configs, so internal update/unset steps stay out of docs and OiCS automatically.
ForceNew / immutable fields and non-updatable resources#
Never omit or mutate a ForceNew (immutable: true) field mid-sample—subsequent steps in an MMv1 sample assert plancheck.ResourceActionUpdate and fail on replacement. Instead, cover omission UNSET with a separate minimal sample (for example, a 0-step _basic sample):
samples:
- name: example_widget_basic
primary_resource_id: default
resource_id_vars:
widget_id: my-widget
- name: example_widget_full
primary_resource_id: default
resource_id_vars:
widget_id: my-widget
steps:
- name: example_widget_full
- name: example_widget_updateVersion gating and provider = google-beta#
MMv1 chooses ProtoV5ProviderBetaFactories vs ProtoV5ProviderFactories from the resource or sample min_version only—not from steps[].min_version:
- Resource or sample has
min_version: beta(ornightly): Setprovider = google-beta(orgoogle-nightly) on every Google resource/data block in the template (ProtoV5ProviderBetaFactoriesregisters only the versioned provider). - GA sample with a beta-only step (
steps[].min_version: beta): Omitprovider = google-betain that step’s template (ProtoV5ProviderFactoriesregisters"google", which is already backed by the beta provider ingoogle-betabuilds; addingprovider = google-betafails with an inconsistent dependency lock file / missing provider error).
Template hygiene#
- Always reference the primary resource label with
{{$.PrimaryResourceId}}(not{{.PrimaryResourceId}}). - Do not wrap values in literal quotes in
vars,resource_id_vars, oroics_vars_overrides(for example, writemode: DELETE, notmode: '"DELETE"'). These values are substituted verbatim into HCL templates and quote-wrapped strings fail MMv1 validation (unliketest_vars_overrides, which holds Go expressions). - Templates execute with
missingkey=errorand strict map indexing, so every key referenced viaindex $.Vars,index $.ResourceIdVars, orindex $.TestEnvVarsmust be defined.
Handwritten _test.go patterns#
When a resource requires handwritten acceptance tests in mmv1/third_party/terraform/services/<product>/:
- Config helper signature: Accept only
context map[string]interface{}(for example,func testAccExampleWidget_update(context map[string]interface{}) string) sotools/test-readercan statically evaluateacctest.Nprintfplaceholders andnilunsets. - In-place update plan checks: Attach
ConfigPlanCheckswithplancheck.ExpectResourceAction("<resource_type>.<label>", plancheck.ResourceActionUpdate)to every modify and in-place unset step; without it,diff-processor --exhaustiveskips the transition. - Import checks: Follow every create, modify, and unset step with an
ImportState: true+ImportStateVerify: truestep. ForceNewomission: CoverUNSETfor optionalForceNewfields in a separateTestAcc...function rather than triggering replacement inside an update test.
func TestAccExampleWidget_update(t *testing.T) {
t.Parallel()
randomSuffix := acctest.RandString(t, 10)
context := map[string]interface{}{
"random_suffix": randomSuffix,
"description": "initial description",
}
contextUpdate := map[string]interface{}{
"random_suffix": randomSuffix,
"description": "updated description",
}
contextUnset := map[string]interface{}{
"random_suffix": randomSuffix,
"description": nil,
}
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckExampleWidgetDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccExampleWidget_config(context),
},
{
ResourceName: "google_example_widget.default",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccExampleWidget_config(contextUpdate),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_example_widget.default", plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: "google_example_widget.default",
ImportState: true,
ImportStateVerify: true,
},
{
Config: testAccExampleWidget_config(contextUnset),
ConfigPlanChecks: resource.ConfigPlanChecks{
PreApply: []plancheck.PlanCheck{
plancheck.ExpectResourceAction("google_example_widget.default", plancheck.ResourceActionUpdate),
},
},
},
{
ResourceName: "google_example_widget.default",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccExampleWidget_config(context map[string]interface{}) string {
return acctest.Nprintf(`
resource "google_example_widget" "default" {
widget_id = "tf-test-widget%{random_suffix}"
description = "%{description}"
}
`, context)
}