-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Conversation
@@ -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") | |||
} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two issues are already tracking this:
https://github.com/hashicorp/terraform/issues/13016
https://github.com/hashicorp/terraform/issues/11101
There was a problem hiding this comment.
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. :)
Signed-off-by: Modular Magician <[email protected]>
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! |
Fixes test
TestAccContainerCluster_withNodePoolConflictingNameFields
.