Skip to content
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

Consider documenting the specific terraform commands executed during acceptance tests #240

Open
2 of 6 tasks
bendbennett opened this issue Dec 6, 2023 · 1 comment
Open
2 of 6 tasks
Labels
documentation Improvements or additions to documentation

Comments

@bendbennett
Copy link
Contributor

Does this documentation exist?

  • This is new documentation
  • This is an enhancement to existing documentation

Where would you expect to find this documentation?

  • On terraform.io
  • In the GoDoc for this module
  • In this repo as a markdown file
  • Somewhere else

Details

This documentation could appear in Acceptance Tests and provide details of the specific terraform commands that are executed during a particular "test mode".

For example, if an acceptance test is set-up to use TestStep.Config:

func TestAccExampleResource(t *testing.T) {
	resource.Test(t, resource.TestCase{
		PreCheck:                 func() { testAccPreCheck(t) },
		ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
		Steps: []resource.TestStep{
			// Create and Read testing
			{
				Config: `resource "example_resource" "test" {
	id = "one"
}`,
				Check: resource.ComposeAggregateTestCheckFunc(
					resource.TestCheckResourceAttr("example_resource.test", "configurable_attribute", "1.797693134862315"),
					resource.TestCheckResourceAttr("example_resource.test", "id", "one"),
				),
			},
		},
	})
}

The following terraform commands are executed during the course of the test:

terraform init 
terraform plan
terraform apply
terraform show (state)
terraform plan
terraform show (plan)
terraform plan
terraform show (plan)
terraform show (state)
terraform destroy

Description

If the terraform command calls are documented and include details as to which flags are supplied (e.g., -refresh-only, -refresh=true|false) this might be useful for provider developers who are writing acceptance tests and aid in the generation of a mental model of which commands are being called and how this relates to direct execution of Terraform commands.

References

@bendbennett bendbennett added the documentation Improvements or additions to documentation label Dec 6, 2023
@bflad
Copy link
Contributor

bflad commented Dec 7, 2023

I'm generally 👍 for this, although I caution about putting too many implementation details into this sort of documentation as:

  • It can be difficult to accurately maintain over time
  • It can potentially cause consumers to depend on those specific implementation details
  • Some of the details are generally irrelevant for most provider developers, like how terraform show is used (many times) to inspect the plan/state -- that's the interface Terraform gives, so its expected/required

My recommendation would be saying things like:

  • A configuration-based step without PlanOnly runs plan, apply, a non-refresh plan, and a refresh plan
  • A configuration-based step with PlanOnly runs a non-refresh plan and a refresh plan

etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants