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

Allow "generic" use of State.GetAttribute #230

Closed
ewbankkit opened this issue Dec 2, 2021 · 1 comment · Fixed by #232
Closed

Allow "generic" use of State.GetAttribute #230

ewbankkit opened this issue Dec 2, 2021 · 1 comment · Fixed by #232
Labels
enhancement New feature or request

Comments

@ewbankkit
Copy link
Contributor

Module version

v0.5.0

Use-cases

The changes made in #167 prevent the "generic" use of State.GetAttribute to be used to copy a value, for example:

https://github.com/hashicorp/terraform-provider-awscc/blob/3cdc5b061801143a621f3d571c53e0e36b22ab96/internal/generic/state.go#L12-L26

// CopyValueAtPath copies the value at a specified path from source State to destination State.
func CopyValueAtPath(ctx context.Context, dst, src *tfsdk.State, path *tftypes.AttributePath) error {
	val, diags := src.GetAttribute(ctx, path)

	if diags.HasError() {
		return tfresource.DiagsError(diags)
	}

	diags = dst.SetAttribute(ctx, path, val)

	if diags.HasError() {
		return tfresource.DiagsError(diags)
	}

	return nil
}

I have tried using a pointer to attr.Value:

func CopyValueAtPath(ctx context.Context, dst, src *tfsdk.State, path *tftypes.AttributePath) error {
	var val attr.Value
	diags := src.GetAttribute(ctx, path, &val)

	if diags.HasError() {
		return tfresource.DiagsError(diags)
	}

	diags = dst.SetAttribute(ctx, path, val)

	if diags.HasError() {
		return tfresource.DiagsError(diags)
	}

	return nil
}

but this fails:

    state_test.go:471: unexpected error from CopyValueAtPath: 1 error occurred:
        	* An unexpected error was encountered trying to convert into a Terraform value. This is always an error in the provider. Please report the following to the provider developer:
        
        Cannot use attr.Value attr.Value, only types.Number is supported because types.primitive is the type in the schema
@github-actions
Copy link

github-actions bot commented Jan 7, 2022

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 Jan 7, 2022
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
Development

Successfully merging a pull request may close this issue.

1 participant