hashicorp / terraform-provider-awscc

Terraform AWS Cloud Control provider
https://registry.terraform.io/providers/hashicorp/awscc/latest/docs
Mozilla Public License 2.0
249 stars 113 forks source link

Attempting to change description field in awscc_iotsitewise_asset_model resource throws AWS SDK Go Service Operation Incomplete error #1967

Open gagan1469 opened 3 weeks ago

gagan1469 commented 3 weeks ago

Community Note

Terraform CLI and Terraform AWS Cloud Control Provider Version

Affected Resource(s)

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

The behaviour is worse in awscc_iotsitewise_asset where the drift detection makes it want to mangle the asset configuration. (Will submit a separate issue for it.)

Terraform Configuration Files
Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

# Copy-paste your Terraform configurations here - for large Terraform configs,
# please use a service like Dropbox and share a link to the ZIP file. For
# security, you can also encrypt the files using our GPG public key: https://keybase.io/hashicorp

resource "awscc_iotsitewise_asset_model" "vdc" {
    asset_model_name = "vdc"
    asset_model_description = "Wireless Voltage Sensors for Field Testing"
    asset_model_type = "ASSET_MODEL"
    asset_model_properties = [ 
        {
            name = "id"
            data_type = "STRING"
            logical_id = "id"
            type = {
                type_name = "Attribute"
                attribute = {
                    default_value = "enter value here"
                }
            } 
        },
        {
            name = "voltage"
            data_type = "DOUBLE"
            logical_id = "voltage"
            type = {
                type_name = "Measurement"
            }
            unit = "mV" 
        },
        {
            name = "battery_level"
            data_type = "DOUBLE"
            logical_id = "battery_level"
            type = {
                type_name = "Measurement"
            }
            unit = "V" 
        }
    ]
    tags = var.tags
}

variable "tags" {
    description = "AWS resource tags for AWSCC provider"
    type = set(object({
      key = string
      value = string
    }))
}

Note: tags are read in from a yaml file. The tags are:

tags                    = [
            {
                key   = "addedDate"
                value = "2024-08-20T00:00:00Z"
            },
            {
                key   = "solution"
                value = "field solution"
            },
          + {
              + key   = "addedBy"
              + value = "Automation Terraform AzDO"
            },
          + {
              + key   = "environment"
              + value = "dev"
            },
        ]

Debug Output

Panic Output

Expected Behavior

Terraform plan detects that the asset_model_description has changed from "Wireless Voltage Sensors" to "Wireless Voltage Sensors for Field Testing", and should make the change. The change should be visible in the console.

Actual Behavior

Terraform apply returns error and the job fails to run to completion. The error message is:

module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Modifying... [id=b3c53c89-7e42-44ce-8b7c-28e0d81ca5c0]
╷
│ Error: AWS SDK Go Service Operation Incomplete
│ 
│   with module.iot_sitewise.awscc_iotsitewise_asset_model.vdc,
│   on iot_sitewise/main.tf line 11, in resource "awscc_iotsitewise_asset_model" "vdc":
│   11: resource "awscc_iotsitewise_asset_model" "vdc" {
│ 
│ Waiting for Cloud Control API service UpdateResource operation completion
│ returned: waiter state transitioned to FAILED. StatusMessage: Invalid
│ request provided: The actual ID of a resource cannot be set. To uniquely
│ identify the property use ExternalId or LogicalId.. ErrorCode:
│ InvalidRequest
╵

The error was reproduced 3 different times.

Steps to Reproduce

  1. terraform apply

Important Factoids

References

quixoticmonk commented 3 weeks ago

Thanks for opening the issue @gagan1469 . I can reproduce this both on the Terraform configuration and via cloud control api. Opening an internal service ticket to review this.

gagan1469 commented 3 weeks ago

Thanks for opening the issue @gagan1469 . I can reproduce this both on the Terraform configuration and via cloud control api. Opening an internal service ticket to review this.

Thank you @quixoticmonk. This touches other attributes and possibly all. I could not edit tags (after I reordered them to correctly identify drift). I think you can reproduce it for changing a model property (using simple alphabetical names you used in #1965).

And you should also see this issue in the editing of an awscc_iotsitewise_asset resource as well.

gagan1469 commented 3 weeks ago

@quixoticmonk I setup a simple asset model with a single asset model property to avoid the sequencing issue reported in #1965. Also, created an asset using the simple asset model. The code is included below, if you want to use in your testing. Making a single change, and running terraform apply, I can confirm that changing the following attributes in awscc_iotsitewise_asset resource result in the "AWS SDK Go Service Operation Incomplete" error:

Did you want to open a separate issue for awscc_iotsitewise_asset? Resource code follows:

# temporary - simple model with one property to test awscc bug
resource "awscc_iotsitewise_asset_model" "iot-pressure" {
    asset_model_name = "iot-pressure"
    asset_model_description = "Single property asset model for awscc update testing"
    asset_model_type = "ASSET_MODEL"
    asset_model_properties = [ 
        {
            name = "pressure"
            data_type = "DOUBLE"
            logical_id = "pressure"
            type = {
                type_name = "Measurement"
            } 
            unit = "psi"
        }
    ]

    tags = var.tags

    # not using asset_model_composite_models and asset_model_hierarchies 
    # but add them to the ignore changes list
    lifecycle {
      ignore_changes = [tags, 
                        asset_model_composite_models, 
                        asset_model_hierarchies
                        ]
    }
}

resource "awscc_iotsitewise_asset" "hou-pressure" {
    asset_model_id = awscc_iotsitewise_asset_model.iot-pressure.id
    asset_name = "hou-pressure"
    asset_description = "Single property asset for awscc update testing"
    asset_properties = [ 
        {
            alias = "/iot/houston/pressure"
            notification_state = "DISABLED"
            logical_id = "pressure"
            unit = "psi"
        }
    ]
    tags = var.tags

    lifecycle {
      ignore_changes = [tags,
                        asset_hierarchies
                        ]
    }

}
quixoticmonk commented 3 weeks ago

Thanks @gagan1469 . I can include the reference of awscc_iotsitewise_asset into the same ticket specifying the issue exists there as well.

gagan1469 commented 1 week ago

Hi @quixoticmonk, would you be able to provide an update on this issue? Do you know when we can expect an update in the cloud control api / updated awscc provider? Out of curiosity, does this issue exist in CloudFormation as well?

quixoticmonk commented 1 week ago

The ticket is still being reviewed for the changes required from the handlers which review the Id being used in update operations. I haven't had a chance to test this with CloudFormation yet.