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

Return an error if name and name prefix are specified in node pool #1062

Merged
merged 1 commit into from
Feb 8, 2018

Conversation

rosbo
Copy link
Contributor

@rosbo rosbo commented Feb 8, 2018

Fixes test TestAccContainerCluster_withNodePoolConflictingNameFields .

@@ -307,6 +307,9 @@ func resourceContainerNodePoolStateImporter(d *schema.ResourceData, meta interfa
func expandNodePool(d *schema.ResourceData, prefix string) (*container.NodePool, error) {
var name string
if v, ok := d.GetOk(prefix + "name"); ok {
if _, ok := d.GetOk(prefix + "name_prefix"); ok {
return nil, fmt.Errorf("Cannot specify both name and name_prefix for a node_pool")
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we add this as ConflictsWith on name and name_prefix?

Copy link
Contributor Author

@rosbo rosbo Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConflictsWith doesn't support nested fields. It only works with top-level fields.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to clarify- I'm pretty sure ConflictsWith does work with nested fields, but you have to specify the full path to the field, i.e. node_pool.0.name_prefix, which won't work if there are multiple node pools specified in a cluster (this schema is shared between the node pool and cluster resources)

Copy link
Contributor Author

@rosbo rosbo Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything Dana said is true.

Just to clarify, ConflictsWith works on nested field IFF you know the index of the other field in ConflictsWith. When you have a list of nested objects and you want two fields inside that nested object to be mutually exclusive, it is NOT supported.

For instance, this works:

foo = "aa"
bar  {
  baz = "aa"
}

// Definition
"foo": &schema.Schema{
  ConflictsWith: []string{"bar.0.baz"}
}

But if you want to say, two fields under the same entry should be conflicting, then this is not possible:

{
 foo = "aaa"
 bar {
  name = "a"
  name_prefix = "b"
 }
 bar {
   name = "c"
   name_prefix = "d"
 }
}

For the example above, there is no way to express that name and name_prefix should ConflictsWith each other.

Copy link
Contributor Author

@rosbo rosbo Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be nice if ConflictsWith supported a notation (exact notation TBD) like:

ConflictsWith: []string{"bar.{i}.baz"}

I vaguely remember opening an issue with Terraform core about this. I will try to dig it out or open one if I had not opened one.

Copy link
Contributor Author

@rosbo rosbo Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoooops. Sorry about that. Ignore this comment then. :)

@rosbo rosbo merged commit 842256a into hashicorp:master Feb 8, 2018
@rosbo rosbo deleted the node-pool-name-failure branch February 8, 2018 21:35
modular-magician added a commit to modular-magician/terraform-provider-google that referenced this pull request Sep 27, 2019
@ghost
Copy link

ghost commented Mar 29, 2020

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 [email protected]. Thanks!

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants