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

ConflictsWith does not function correctly on fields within a list or set #75

Closed
brandontosch opened this issue Mar 23, 2017 · 2 comments
Labels
enhancement New feature or request

Comments

@brandontosch
Copy link
Contributor

Terraform Version

v0.9.1

Affected Resource(s)

All, this is a core issue. For example though, we'll focus on the postgresql_schema resource since it has ConflictsWith rules in place on a set object (policy).

Terraform Configuration Files

resource "postgresql_schema" "test" {
  name = "test"

  policy = {
    create            = "true"
    create_with_grant = "true"
  }
}

Expected Behavior

In general, resource properties within a list or set should respect the ConflictsWith attribute and the check should be performed within each item in the list/set.

This should work, but does not:
ConflictsWith: []string { "list_property.conflicting_field_name" }

The above terraform config should result in an error when executing a plan command since the create and create_with_grant fields under policy conflict with each other.

Here is the code for the postgresql resource where the conflicts are configured:

schemaPolicyAttr: &schema.Schema{
    Type:     schema.TypeSet,
    Optional: true,
    Computed: true,
    Elem: &schema.Resource{
        Schema: map[string]*schema.Schema{
            schemaPolicyCreateAttr: {
                Type:          schema.TypeBool,
                Optional:      true,
                Default:       false,
                Description:   "If true, allow the specified ROLEs to CREATE new objects within the schema(s)",
            --> ConflictsWith: []string{schemaPolicyAttr + "." + schemaPolicyCreateWithGrantAttr},
            },
            schemaPolicyCreateWithGrantAttr: {
                Type:          schema.TypeBool,
                Optional:      true,
                Default:       false,
                Description:   "If true, allow the specified ROLEs to CREATE new objects within the schema(s) and GRANT the same CREATE privilege to different ROLEs",```
            --> ConflictsWith: []string{schemaPolicyAttr + "." + schemaPolicyCreateAttr},
            },

Actual Behavior

In the terraform config above, the plan command succeeds without error.

ConflictsWith can only work for a list/set if you manually specify the index in the ConflictsWith value and therefore can only really work if there is a single item in the list.

For exmaple:
ConflictsWith: []string { "list_property.0.conflicting_field_name" }

Steps to Reproduce

  1. Using the config above, run terraform plan and just press enter through all the inputs.
  2. Observe that there is no conflict error

References

Discovered while implementing managed disk support for azurerm:

Opened PR for proposed fix:

@hashibot hashibot transferred this issue from hashicorp/terraform Sep 26, 2019
@hashibot hashibot added the enhancement New feature or request label Oct 2, 2019
@radeksimko
Copy link
Member

Hi @brandontosch
Thank you for the report and sorry for the delay.

I'm going to close this issue as a duplicate of #71 so we can keep discussion in one place, but I'm sure that your linked examples to AzureRM issues will come handy when implementing this.

@ghost
Copy link

ghost commented Apr 1, 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 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.

@ghost ghost locked and limited conversation to collaborators Apr 1, 2020
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

No branches or pull requests

3 participants