Exhaustive acceptance testing

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:

TransitionRequirementExempt when
SETPresent (non-null) in at least one applied test step.Never exempt for configurable fields.
MODIFYChanges 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).
UNSETMutable 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-Computed ancestor 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) satisfies UNSET for that child without writing an empty block {}.

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 --exhaustive

Or 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.name when it matches sample.name; config_path inherits from the sample (or defaults to templates/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: null
resource "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-Computed block (defaultless child): unsetting the parent block directly covers both child and parent UNSET.
    • Optional empty MaxItems: 1 block (properties: [] or only children with output: true, with allow_empty_object: true): Because the block only has two HCL states (absent and {}), cover SET, UNSET, and MODIFY with an in-place SET -> UNSET -> re-SET (or UNSET -> SET -> UNSET) sequence while its parent block remains present.
  • 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 children c1..cN in 2 steps):
    1. Create (_full): set c1 and c2..cN.
    2. Modify (_update): modify c1 and c2..cN in place.
    3. Unset c2..cN (_unset_rest): keep c1 set, omit c2..cN (parent stays non-empty).
    4. Unset c1 (_unset_first): omit c1, restore c2..cN (parent stays non-empty).
    5. Unset parent (_unset_parent): omit the parent block entirely.
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_parent

Only 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_update

Version 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 (or nightly): Set provider = google-beta (or google-nightly) on every Google resource/data block in the template (ProtoV5ProviderBetaFactories registers only the versioned provider).
  • GA sample with a beta-only step (steps[].min_version: beta): Omit provider = google-beta in that step’s template (ProtoV5ProviderFactories registers "google", which is already backed by the beta provider in google-beta builds; adding provider = google-beta fails 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, or oics_vars_overrides (for example, write mode: DELETE, not mode: '"DELETE"'). These values are substituted verbatim into HCL templates and quote-wrapped strings fail MMv1 validation (unlike test_vars_overrides, which holds Go expressions).
  • Templates execute with missingkey=error and strict map indexing, so every key referenced via index $.Vars, index $.ResourceIdVars, or index $.TestEnvVars must 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) so tools/test-reader can statically evaluate acctest.Nprintf placeholders and nil unsets.
  • In-place update plan checks: Attach ConfigPlanChecks with plancheck.ExpectResourceAction("<resource_type>.<label>", plancheck.ResourceActionUpdate) to every modify and in-place unset step; without it, diff-processor --exhaustive skips the transition.
  • Import checks: Follow every create, modify, and unset step with an ImportState: true + ImportStateVerify: true step.
  • ForceNew omission: Cover UNSET for optional ForceNew fields in a separate TestAcc... 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)
}

References#