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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions google/resource_container_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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. :)

name = v.(string)
} else if v, ok := d.GetOk(prefix + "name_prefix"); ok {
name = resource.PrefixedUniqueId(v.(string))
Expand Down