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 Known Value and Type Plan Checks for Resource Attributes and Output Values #243

Closed
bendbennett opened this issue Dec 13, 2023 · 1 comment · Fixed by #248
Closed
Labels
enhancement New feature or request
Milestone

Comments

@bendbennett
Copy link
Contributor

terraform-plugin-testing version

v.1.6.0

Use cases

The plancheck package within terraform-plugin-testing has plan checks for the following:

Being able to assert that resource attributes, and output values in the plan have a known type and value is a use-case that is not yet catered for in the existing plan checks.

Attempted solutions

The only option currently available to provider developers who wish to assert that a resource attribute, or an output value has a known value and type is to implement custom plan checks using the plancheck.PlanCheck interface.

Proposal

The proposal is to

  • Add plan checks for ExpectKnownValue, ExpectKnownOutputValue, and ExpectKnownOutputValueAtPath
  • Add a KnownValue interface and types implementing this interface which can be used within the known value plan checks to assert that a resource attribute, or output value has a specified type and value.
type KnownValue interface {
	Equal(other any) bool
}

var _ KnownValue = stringValue{}

type stringValue struct {
	value string
}

func (v stringValue) Equal(other any) bool {
	otherVal, ok := other.(string)

	if !ok {
		return false
	}

	if otherVal != v.value {
		return false
	}

	return true
}

func StringValue(value string) stringValue {
	return stringValue{
		value: value,
	}
}
@bendbennett bendbennett added the enhancement New feature or request label Dec 13, 2023
@bendbennett bendbennett added this to the v1.7.0 milestone Dec 13, 2023
bendbennett added a commit that referenced this issue Dec 18, 2023
…pe and value, and known value type and value (#243)
bendbennett added a commit that referenced this issue Dec 18, 2023
bendbennett added a commit that referenced this issue Dec 18, 2023
bendbennett added a commit that referenced this issue Jan 3, 2024
bendbennett added a commit that referenced this issue Jan 3, 2024
bendbennett added a commit that referenced this issue Jan 4, 2024
bendbennett added a commit that referenced this issue Jan 4, 2024
bendbennett added a commit that referenced this issue Jan 5, 2024
bendbennett added a commit that referenced this issue Jan 5, 2024
…ue, ExpectKnownOutputValue and ExpectKnownOutputValueAtPath (#243)
bendbennett added a commit that referenced this issue Jan 15, 2024
…and `ExpectKnownOutputValueAtPath` (#248)

* Add KnownValue interface and types (#243)

* Add ExpectKnownValue plan check (#243)

* Handling different permutations for equality checking of interface type and value, and known value type and value (#243)

* Adding tests for missing resource, and attribute value null (#243)

* Adding plan checks for known output value and known output value at path (#243)

* Adding documentation (#243)

* Adding changelog entries (#243)

* Adding TerraformVersionChecks (#243)

* Modifying to handle numerical values returned as json.Number for tfjson.Plan (#243)

* Renaming known value constructors (#243)

* Refactoring to Check interface (#243)

* Linting (#243)

* Modifying known value check error messages and tests (#243)

* Updating tests for ExpectKnownValue, ExpectKnownOutputValue and ExpectKnownOutputValueAtPaath (#243)

* Adding changelog entry to note the switch to using json.Number for numerical value representation in the plan (#243)

* Remove reference to state checks (#243)

* Moving concepts under title and removing reference to Framework types (#243)

* Updating Go doc comments to clarify usage of partial equality and remove references to KnownValue interface (#243)

* Modifying known-values.mdx page description (#243)

* Restructuring and updating references to knownvalue.Check (#243)

* Adding individual docs pages for each type of known value check (#243)

* Removing references to num elements (#243)

* Removing references to state (#243)

* Adding docs page for custom known value checks (#243)

* Fixing error message (#243)

* Refactoring to accomodate custom known value checks in ExpectKnownValue, ExpectKnownOutputValue and ExpectKnownOutputValueAtPath (#243)

* Apply suggestions from code review

Co-authored-by: Brian Flad <bflad417@gmail.com>

* Unexporting types that implement known value check (#266)

* Document usage of 512-bit precision in the number known value check (#266)

* Adding attribute or output path to error message (#266)

* Replacing alias in example code (#266)

* Rename file (#266)

* Renamed list, map, and set element length checks to <List|Map|Set>SizeExact (#243)

* Removing ObjectAttributesExact (#243)

* Renaming known value check types (#243)

---------

Co-authored-by: Brian Flad <bflad417@gmail.com>
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
1 participant