terraform plan doesn't produce diff if ReadContext emits Warnings

Created on 7 Dec 2020  路  6Comments  路  Source: hashicorp/terraform

SDK version

v2.3.0

Relevant provider source code

func resourceChannelTestingRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
    var diags diag.Diagnostics

    // Read API DATA into `current`

    diags = append(diags, diag.Diagnostic{
        Severity: diag.Warning,
        Summary: "Debug dumping",
        Detail: fmt.Sprintf("%+v", current),
    })

    // Set some properties

    return diags
}

Terraform Configuration Files

resource "fpp_channel_testing" "main" {
    enabled = false
    mode = "foo"
}

Debug Output

Expected Behavior

Diff such as the following should be produced.

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
2020/12/07 22:05:03 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
  ~ update in-place

2020/12/07 22:05:03 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
Terraform will perform the following actions:

  # fpp_channel_testing.main will be updated in-place
  ~ resource "fpp_channel_testing" "main" {
      ~ enabled = true -> false
        id      = "static"
      ~ mode    = "RGBChase" -> "foo"
    }

Plan: 0 to add, 1 to change, 0 to destroy.

Actual Behavior

Warning was produced but no diff identified.

2020/12/07 22:04:31 [TRACE] statemgr.Filesystem: removing lock metadata file .terraform.tfstate.lock.info
No changes. Infrastructure is up-to-date.

2020/12/07 22:04:31 [TRACE] statemgr.Filesystem: unlocking terraform.tfstate using fcntl flock
This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, no
actions need to be performed.

Warning: Debug dumping

{Mode:RGBChase SubMode:RGBChase-RGB CycleMS:1000
ColorPattern:FF000000FF000000FF Color1:<nil> Color2:<nil> Color3:<nil>
Enabled:1 ChannelSet:1-8 ChannelSetType:channelRange}

Steps to Reproduce

  1. Create a resource where the ReadContext implementation produces a warning
  2. terraform plan

References

Discussion

This _might_ be intentional behaviour, if it is it should be clearly documented somewhere and I don't see it. The issue from my point of view is that if the ReadContext implementation produces a Warning (something I consider non-fatal) then no diff is identified even if there were changes. The output from plan clearly states "Terraform did not detect any differences between your
configuration and real physical resources that exist" when there were changes identified, it feels wrong to hide this information just because there was a warning.

Most helpful comment

I'm going to move this to the hashicorp/terraform repo, as this is Terraform core's functionality. Sorry for the confusion there. :(

All 6 comments

I'm also open for the fact that this could be an issue in terraform and not in the plugin-sdk but I thought I would start here as that's where the Diagnostics and ReadContext apis/types reside.

I may be getting hit by this too. My current workaround is to avoid emiting the warning. But it seems like warnings should be informational only and not prevent resource state synchronization.

Did some testing changing the terraform-cli version.

I've been able to reproduce this with 0.14.0 and 0.14.2. But not with the current main branch version (3268a7ea).

May I assume this will be fixed in 0.14.3?

Update: still reproduces in 0.14.3

I'm going to move this to the hashicorp/terraform repo, as this is Terraform core's functionality. Sorry for the confusion there. :(

Closing since this is confirmed as fixed in master.

Thanks!

Was this page helpful?
0 / 5 - 0 ratings