Skip to content

Any call to .AtName(), .AtListIndex(), etc. removes the root flag on root expressions #419

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

Closed
detro opened this issue Jul 20, 2022 · 1 comment · Fixed by #420
Closed
Labels
bug Something isn't working schema Issues and pull requests about the abstraction for specifying schemas.
Milestone

Comments

@detro
Copy link
Contributor

detro commented Jul 20, 2022

Module version

0.10.0

Description

For a terraform configuration like:

provider "tls" {
  proxy {
    // url: conflicting with `from_env`
    from_env = true
  }
}

If we need to express that url conflicts with from_env, we need to write in the schema of the provider something like:

Validators: []tfsdk.AttributeValidator{					
  // using an "absolute path"
  schemavalidator.ConflictsWith(path.MatchRoot("proxy").AtName("from_env")),
  // using a "relative path"
  schemavalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("from_env")),
}						},

Both approaches should work, but unfortunately the calls to AtName() (and any other .At* method on a path.Expression) make use .Copy(), and that call inadvertently modifies the expression so that, if internally it contained the flag root: true, by virtue of Golang default values, it gets turned to root: false:

func (e Expression) Copy() Expression {
	return Expression{
		steps: e.Steps().Copy(),
	}
}

Because of this, the provider validation logic triggers an error when using the "absolute path" approach:

Error: Invalid Path Expression for Schema Data
        
          with provider["registry.terraform.io/hashicorp/tls"],
          on terraform_plugin_test.tf line 2, in provider "tls":
           2: 					provider "tls" {
        
        The Terraform Provider unexpectedly matched no paths with the given path
        expression and current schema data. This can happen if the path expression
        does not correctly follow the schema in structure or types. Please report
        this to the provider developers.
        
        Path Expression: proxy.url.proxy.from_env

Expected Behavior

Validation should be express-able via "absolute" as well as "relative" paths.
The choice should be left to the provider developer.

Actual Behavior

Any "absolute" path expression (i.e. created via .MatchRoot(), i.e. that contain internally the root: true flag), when deeper than 1 level, assemble an incorrect expression, where the "root-ness" gets lost.

@detro detro added bug Something isn't working schema Issues and pull requests about the abstraction for specifying schemas. labels Jul 20, 2022
@bflad bflad added this to the v0.10.1 milestone Jul 20, 2022
@bflad bflad modified the milestones: v0.10.1, v0.11.0 Jul 27, 2022
@github-actions
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 Aug 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working schema Issues and pull requests about the abstraction for specifying schemas.
Projects
None yet
2 participants