Skip to content

Multiple computed BoolAttributes with defaults in SetNestedAttribute cause flip-flopping plan on every applyΒ #867

@henryrecker-pingidentity

Description

Module version

1.4.2

Relevant provider source code

func (r *setNestedExampleResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
	resp.Schema = schema.Schema{
		Attributes: map[string]schema.Attribute{
			"set": schema.SetNestedAttribute{
				Required: true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"name": schema.StringAttribute{
							Required: true,
						},
						"bool_one": schema.BoolAttribute{
							Optional: true,
							Computed: true,
							Default:  booldefault.StaticBool(false),
						},
						"bool_two": schema.BoolAttribute{
							Optional: true,
							Computed: true,
							Default:  booldefault.StaticBool(false),
						},
					},
				},
			},
		},
	}
}

func (r *setNestedExampleResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
	resp.State.Raw = req.Plan.Raw
}

func (r *setNestedExampleResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
	resp.State.Raw = req.State.Raw
}

func (r *setNestedExampleResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) {
	resp.State.Raw = req.Plan.Raw
}

Terraform Configuration Files

resource "example_set_nested_example" "myExample" {
  set = [
    {
      name = "test2"
      bool_two = true
    }
  ]
}

Debug Output

Expected Behavior

The provider would not produce any plan after the first apply.

Actual Behavior

The first apply succeeds, and everything looks right in the state. On every subsequent apply, the generated plan flips the bool_two value to its opposite value.

First plan for example:

# example_set_nested_example.myExample will be created
  + resource "example_set_nested_example" "myExample" {
      + set = [
          + {
              + bool_one = false
              + bool_two = true
              + name     = "test2"
            },
        ]
    }

Second plan with no changes to HCL:

# example_set_nested_example.myExample will be updated in-place
  ~ resource "example_set_nested_example" "myExample" {
      ~ set = [
          - {
              - bool_one = false -> null
              - bool_two = true -> null
              - name     = "test2" -> null
            },
          + {
              + bool_one = false
              + bool_two = false
              + name     = "test2"
            },
        ]
    }

Third plan:

# example_set_nested_example.myExample will be updated in-place
  ~ resource "example_set_nested_example" "myExample" {
      ~ set = [
          - {
              - bool_one = false -> null
              - bool_two = false -> null
              - name     = "test2" -> null
            },
          + {
              + bool_one = false
              + bool_two = true
              + name     = "test2"
            },
        ]
    }

The plans will continue to cycle between setting bool_two to true and to false.

Steps to Reproduce

Apply the provided HCL multiple times

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions