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

awscc_iotsitewise_asset_model resource detects drift on unchanged config in subsequent run and never completes #1965

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)

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"
    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

There is no change in the resource and there should be no modification.

Actual Behavior

Terraform detects drift and tries to make the modification but is stuck in a never ending. Eventually, the job has to be cancelled. Terraform apply output contains:

module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Modifying... [id=b3c53c89-7e42-44ce-8b7c-28e0d81ca5c0]
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [10s elapsed]
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [20s elapsed]
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [30s elapsed]
:
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [4m40s elapsed]
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [4m50s elapsed]
module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Still modifying... [5m0s elapsed]

This has run on for over an hour and not completed. The job had to be cancelled. The workaround has been to use lifecycle ignore_changes to ensure other resources will be updated and Terraform apply exits cleanly. But this means we can create the resource but never update it. Deleting the resource and recreating it is not an option in a production environment because field data has been associated to the asset model and assets. Deleting the asset model / assets will irrevocably delete historical data.

    lifecycle {
      ignore_changes = [tags, asset_model_properties]
    }

Steps to Reproduce

  1. terraform apply

Important Factoids

References

quixoticmonk commented 3 weeks ago

Thank you for opening the issue @gagan1469 . I am able to reproduce on this my end with the same configuration. Adding some additional debug logs here.

From the debug logs

2024-08-22T17:08:49.854-0400 [WARN]  Provider "registry.terraform.io/hashicorp/awscc" produced an unexpected new value for awscc_iotsitewise_asset_model.vdc during refresh.
      - .asset_model_properties[0].type.attribute: was cty.ObjectVal(map[string]cty.Value{"default_value":cty.StringVal("enter value here")}), but now null
      - .asset_model_properties[0].type.type_name: was cty.StringVal("Attribute"), but now cty.StringVal("Measurement")
      - .asset_model_properties[0].data_type: was cty.StringVal("STRING"), but now cty.StringVal("DOUBLE")
      - .asset_model_properties[0].logical_id: was cty.StringVal("id"), but now cty.StringVal("battery_level")
      - .asset_model_properties[0].name: was cty.StringVal("id"), but now cty.StringVal("battery_level")
      - .asset_model_properties[1].logical_id: was cty.StringVal("voltage"), but now cty.StringVal("id")
      - .asset_model_properties[1].name: was cty.StringVal("voltage"), but now cty.StringVal("id")
      - .asset_model_properties[1].type.type_name: was cty.StringVal("Measurement"), but now cty.StringVal("Attribute")
      - .asset_model_properties[1].unit: was cty.StringVal("mV"), but now null
      - .asset_model_properties[1].data_type: was cty.StringVal("DOUBLE"), but now cty.StringVal("STRING")
      - .asset_model_properties[2].logical_id: was cty.StringVal("battery_level"), but now cty.StringVal("voltage")
      - .asset_model_properties[2].name: was cty.StringVal("battery_level"), but now cty.StringVal("voltage")
      - .asset_model_properties[2].unit: was cty.StringVal("V"), but now cty.StringVal("mV")
2024-08-22T17:08:49.855-0400 [DEBUG] skipping FixUpBlockAttrs
2024-08-22T17:08:49.886-0400 [DEBUG] provider.terraform-provider-awscc_v1.10.0_x5: 
Detected value change between proposed new state and prior state: 
@caller=github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/fwserver/server_planresourcechange.go:208 
@module=sdk.framework tf_provider_addr=registry.terraform.io/hashicorp/awscc tf_resource_type=awscc_iotsitewise_asset_model
 tf_attribute_path=asset_model_properties tf_req_id=5c9097ad-f6e7-4541-4d5d-b32fde244c52 tf_rpc=PlanResourceChange timestamp=2024-08-22T17:08:49.886-0400

PlanResourceChange_Request_ProposedNewState.msgpack
{
  "asset_model_arn": "arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_composite_models": null,
  "asset_model_description": "Wireless Voltage Sensors",
  "asset_model_external_id": null,
  "asset_model_hierarchies": null,
  "asset_model_id": "91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_name": "vdc",
  "asset_model_properties": [
    {
      "data_type": "STRING",
      "data_type_spec": null,
      "external_id": null,
      "id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2",
      "logical_id": "id",
      "name": "id",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Attribute"
      },
      "unit": "V"
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "8ad2f90b-f9f5-408d-b52d-c2972e217762",
      "logical_id": "voltage",
      "name": "voltage",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "mV"
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "788a31ef-e6d7-4ac0-9490-0bd4c6506dee",
      "logical_id": "battery_level",
      "name": "battery_level",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "V"
    }
  ],
  "asset_model_type": "ASSET_MODEL",
  "id": "91cde520-971b-469a-920b-96885e2c7130",
  "tags": [
    {
      "key": "Modified By",
      "value": "AWSCC"
    }
  ]
}
PlanResourceChange_Request_PriorState.msgpack
{
  "asset_model_arn": "arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_composite_models": null,
  "asset_model_description": "Wireless Voltage Sensors",
  "asset_model_external_id": null,
  "asset_model_hierarchies": null,
  "asset_model_id": "91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_name": "vdc",
  "asset_model_properties": [
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2",
      "logical_id": "battery_level",
      "name": "battery_level",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "V"
    },
    {
      "data_type": "STRING",
      "data_type_spec": null,
      "external_id": null,
      "id": "8ad2f90b-f9f5-408d-b52d-c2972e217762",
      "logical_id": "id",
      "name": "id",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Attribute"
      },
      "unit": null
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "788a31ef-e6d7-4ac0-9490-0bd4c6506dee",
      "logical_id": "voltage",
      "name": "voltage",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "mV"
    }
  ],
  "asset_model_type": "ASSET_MODEL",
  "id": "91cde520-971b-469a-920b-96885e2c7130",
  "tags": [
    {
      "key": "Modified By",
      "value": "AWSCC"
    }
  ]
}
aws cloudcontrol get-resource --type-name AWS::IoTSiteWise::AssetModel --identifier 91cde520-971b-469a-920b-96885e2c7130 | jq .ResourceDescription.Properties

"{\"AssetModelDescription\":\"Wireless Voltage Sensors\",
\"AssetModelCompositeModels\":[],
\"AssetModelId\":\"91cde520-971b-469a-920b-96885e2c7130\",
\"AssetModelType\":\"ASSET_MODEL\",
\"AssetModelName\":\"vdc\",
\"AssetModelArn\":\"arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130\",
\"AssetModelProperties\":[{\"Type\":{\"TypeName\":\"Measurement\"},\"LogicalId\":\"battery_level\",\"DataType\":\"DOUBLE\",\"Id\":\"d7d63398-eb77-44e2-a9bf-a951e7551fd2\",\"Unit\":\"V\",\"Name\":\"battery_level\"},{\"Type\":{\"TypeName\":\"Attribute\",\"Attribute\":{\"DefaultValue\":\"enter value here\"}},\"LogicalId\":\"id\",\"DataType\":\"STRING\",\"Id\":\"8ad2f90b-f9f5-408d-b52d-c2972e217762\",\"Name\":\"id\"},{\"Type\":{\"TypeName\":\"Measurement\"},\"LogicalId\":\"voltage\",
\"DataType\":\"DOUBLE\",\"Id\":\"788a31ef-e6d7-4ac0-9490-0bd4c6506dee\",\"Unit\":\"mV\",\"Name\":\"voltage\"}],
\"Tags\":[{\"Value\":\"AWSCC\",\"Key\":\"Modified By\"}]}"
gagan1469 commented 3 weeks ago

@quixoticmonk Maybe this is helpful. Attaching a partial example of how the false drift is detected. It seems to be in the ordering of the properties in the asset_model_properties. The properties in the code are in one order and the list retrieved orders the properties differently. Sequence in the code is [id, voltage, battery_level]. Sequence in the data retrieved (it seems) is [battery_level, id, voltage]. Hope this is helpful.

module.iot_sitewise.awscc_iotsitewise_asset_model.vdc: Drift detected (update) 

Terraform used the selected providers to generate the following execution 
plan. Resource actions are indicated with the following symbols: 
~ update in-place 

Terraform will perform the following actions: 

# module.iot_sitewise.awscc_iotsitewise_asset_model.vdc will be updated in-place 
~ resource "awscc_iotsitewise_asset_model" "vdc" { 
+ asset_model_composite_models = (known after apply) 
+ asset_model_hierarchies = (known after apply) 
~ asset_model_properties = [ 
~ { 
~ data_type = "DOUBLE" -> "STRING" 
+ data_type_spec = (known after apply) 
+ external_id = (known after apply) 
id = "198a47c3-ad10-4b08-a915-2db66eadd1f8" 
~ logical_id = "battery_level" -> "id" 
~ name = "battery_level" -> "id" 
~ type = { 
+ attribute = { 
+ default_value = "enter value here" 
} 
+ metric = (known after apply) 
+ transform = (known after apply) 
~ type_name = "Measurement" -> "Attribute" 
} 
# (1 unchanged attribute hidden) 
}, 
 ~ { 
~ data_type = "STRING" -> "DOUBLE" 
+ data_type_spec = (known after apply) 
+ external_id = (known after apply) 
id = "b554ec2d-ddf6-4fff-b11b-badfeeff57c0" 
~ logical_id = "id" -> "voltage" 
~ name = "id" -> "voltage" 
~ type = { 
+ metric = (known after apply) 
+ transform = (known after apply) 
~ type_name = "Attribute" -> "Measurement" 
# (1 unchanged attribute hidden) 
} 
+ unit = (known after apply) 
}, 
.
.
.
quixoticmonk commented 3 weeks ago

That is true, but the schema on the resource doesn't require ordering. On top of it, the id associated with the attributes and measurement do not match in prior state and proposed. "id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2"

The cloudcontrol get resource call does map the ids to the correct data_types though.

{
    "AssetModelDescription": "Wireless Voltage Sensors",
    "AssetModelCompositeModels": [],
    "AssetModelId": "91cde520-971b-469a-920b-96885e2c7130",
    "AssetModelType": "ASSET_MODEL",
    "AssetModelName": "vdc",
    "AssetModelArn": "arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130",
    "AssetModelProperties": [
        {
            "Type": {
                "TypeName": "Measurement"
            },
            "LogicalId": "battery_level",
            "DataType": "DOUBLE",
            "Id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2",
            "Unit": "V",
            "Name": "battery_level"
        },
        {
            "Type": {
                "TypeName": "Attribute",
                "Attribute": {
                    "DefaultValue": "enter value here"
                }
            },
            "LogicalId": "id",
            "DataType": "STRING",
            "Id": "8ad2f90b-f9f5-408d-b52d-c2972e217762",
            "Name": "id"
        },
        {
            "Type": {
                "TypeName": "Measurement"
            },
            "LogicalId": "voltage",
            "DataType": "DOUBLE",
            "Id": "788a31ef-e6d7-4ac0-9490-0bd4c6506dee",
            "Unit": "mV",
            "Name": "voltage"
        }
    ],
    "Tags": [
        {
            "Value": "AWSCC",
            "Key": "Modified By"
        }
    ]
}
gagan1469 commented 3 weeks ago

Thank you for opening the issue @gagan1469 . I am able to reproduce on this my end with the same configuration. Adding some additional debug logs here.

From the debug logs

2024-08-22T17:08:49.854-0400 [WARN]  Provider "registry.terraform.io/hashicorp/awscc" produced an unexpected new value for awscc_iotsitewise_asset_model.vdc during refresh.
      - .asset_model_properties[0].type.attribute: was cty.ObjectVal(map[string]cty.Value{"default_value":cty.StringVal("enter value here")}), but now null
      - .asset_model_properties[0].type.type_name: was cty.StringVal("Attribute"), but now cty.StringVal("Measurement")
      - .asset_model_properties[0].data_type: was cty.StringVal("STRING"), but now cty.StringVal("DOUBLE")
      - .asset_model_properties[0].logical_id: was cty.StringVal("id"), but now cty.StringVal("battery_level")
      - .asset_model_properties[0].name: was cty.StringVal("id"), but now cty.StringVal("battery_level")
      - .asset_model_properties[1].logical_id: was cty.StringVal("voltage"), but now cty.StringVal("id")
      - .asset_model_properties[1].name: was cty.StringVal("voltage"), but now cty.StringVal("id")
      - .asset_model_properties[1].type.type_name: was cty.StringVal("Measurement"), but now cty.StringVal("Attribute")
      - .asset_model_properties[1].unit: was cty.StringVal("mV"), but now null
      - .asset_model_properties[1].data_type: was cty.StringVal("DOUBLE"), but now cty.StringVal("STRING")
      - .asset_model_properties[2].logical_id: was cty.StringVal("battery_level"), but now cty.StringVal("voltage")
      - .asset_model_properties[2].name: was cty.StringVal("battery_level"), but now cty.StringVal("voltage")
      - .asset_model_properties[2].unit: was cty.StringVal("V"), but now cty.StringVal("mV")
2024-08-22T17:08:49.855-0400 [DEBUG] skipping FixUpBlockAttrs
2024-08-22T17:08:49.886-0400 [DEBUG] provider.terraform-provider-awscc_v1.10.0_x5: Detected value change between proposed new state and prior state: @caller=github.com/hashicorp/terraform-plugin-framework@v1.11.0/internal/fwserver/server_planresourcechange.go:208 @module=sdk.framework tf_provider_addr=registry.terraform.io/hashicorp/awscc tf_resource_type=awscc_iotsitewise_asset_model tf_attribute_path=asset_model_properties tf_req_id=5c9097ad-f6e7-4541-4d5d-b32fde244c52 tf_rpc=PlanResourceChange timestamp=2024-08-22T17:08:49.886-0400

PlanResourceChange_Request_ProposedNewState.msgpack
{
  "asset_model_arn": "arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_composite_models": null,
  "asset_model_description": "Wireless Voltage Sensors",
  "asset_model_external_id": null,
  "asset_model_hierarchies": null,
  "asset_model_id": "91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_name": "vdc",
  "asset_model_properties": [
    {
      "data_type": "STRING",
      "data_type_spec": null,
      "external_id": null,
      "id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2",
      "logical_id": "id",
      "name": "id",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Attribute"
      },
      "unit": "V"
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "8ad2f90b-f9f5-408d-b52d-c2972e217762",
      "logical_id": "voltage",
      "name": "voltage",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "mV"
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "788a31ef-e6d7-4ac0-9490-0bd4c6506dee",
      "logical_id": "battery_level",
      "name": "battery_level",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "V"
    }
  ],
  "asset_model_type": "ASSET_MODEL",
  "id": "91cde520-971b-469a-920b-96885e2c7130",
  "tags": [
    {
      "key": "Modified By",
      "value": "AWSCC"
    }
  ]
}
PlanResourceChange_Request_PriorState.msgpack
{
  "asset_model_arn": "arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_composite_models": null,
  "asset_model_description": "Wireless Voltage Sensors",
  "asset_model_external_id": null,
  "asset_model_hierarchies": null,
  "asset_model_id": "91cde520-971b-469a-920b-96885e2c7130",
  "asset_model_name": "vdc",
  "asset_model_properties": [
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "d7d63398-eb77-44e2-a9bf-a951e7551fd2",
      "logical_id": "battery_level",
      "name": "battery_level",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "V"
    },
    {
      "data_type": "STRING",
      "data_type_spec": null,
      "external_id": null,
      "id": "8ad2f90b-f9f5-408d-b52d-c2972e217762",
      "logical_id": "id",
      "name": "id",
      "type": {
        "attribute": {
          "default_value": "enter value here"
        },
        "metric": null,
        "transform": null,
        "type_name": "Attribute"
      },
      "unit": null
    },
    {
      "data_type": "DOUBLE",
      "data_type_spec": null,
      "external_id": null,
      "id": "788a31ef-e6d7-4ac0-9490-0bd4c6506dee",
      "logical_id": "voltage",
      "name": "voltage",
      "type": {
        "attribute": null,
        "metric": null,
        "transform": null,
        "type_name": "Measurement"
      },
      "unit": "mV"
    }
  ],
  "asset_model_type": "ASSET_MODEL",
  "id": "91cde520-971b-469a-920b-96885e2c7130",
  "tags": [
    {
      "key": "Modified By",
      "value": "AWSCC"
    }
  ]
}
aws cloudcontrol get-resource --type-name AWS::IoTSiteWise::AssetModel --identifier 91cde520-971b-469a-920b-96885e2c7130 | jq .ResourceDescription.Properties

"{\"AssetModelDescription\":\"Wireless Voltage Sensors\",\"AssetModelCompositeModels\":[],\"AssetModelId\":\"91cde520-971b-469a-920b-96885e2c7130\",\"AssetModelType\":\"ASSET_MODEL\",\"AssetModelName\":\"vdc\",\"AssetModelArn\":\"arn:aws:iotsitewise:us-east-1:############:asset-model/91cde520-971b-469a-920b-96885e2c7130\",\"AssetModelProperties\":[{\"Type\":{\"TypeName\":\"Measurement\"},\"LogicalId\":\"battery_level\",\"DataType\":\"DOUBLE\",\"Id\":\"d7d63398-eb77-44e2-a9bf-a951e7551fd2\",\"Unit\":\"V\",\"Name\":\"battery_level\"},{\"Type\":{\"TypeName\":\"Attribute\",\"Attribute\":{\"DefaultValue\":\"enter value here\"}},\"LogicalId\":\"id\",\"DataType\":\"STRING\",\"Id\":\"8ad2f90b-f9f5-408d-b52d-c2972e217762\",\"Name\":\"id\"},{\"Type\":{\"TypeName\":\"Measurement\"},\"LogicalId\":\"voltage\",\"DataType\":\"DOUBLE\",\"Id\":\"788a31ef-e6d7-4ac0-9490-0bd4c6506dee\",\"Unit\":\"mV\",\"Name\":\"voltage\"}],\"Tags\":[{\"Value\":\"AWSCC\",\"Key\":\"Modified By\"}]}"

Thank you @quixoticmonk for looking into this. Glad you could reproduce it. I have also added the Terraform plan output that corroborates what you see in the debug logs. As you fix this, please keep in mind that the same issue likely exists with other resource attributes that are a list (or set) of maps (I think dicts). These are:

And also very important, this impacts the awscc_iotsitewise_asset resource in the same way.

quixoticmonk commented 3 weeks ago

So there is definitely ordering happening based on the name. The example below doesn't introduce a drift.

resource "awscc_iotsitewise_asset_model" "vdc" {
  asset_model_name        = "vdc"
  asset_model_description = "Wireless Voltage Sensors"
  asset_model_type        = "ASSET_MODEL"
  asset_model_properties = [
    {

      data_type  = "STRING"
      logical_id = "id"
      name       = "a"
      type = {
        type_name = "Attribute"
        attribute = {
          default_value = "enter value here"
        }
      }
    },
    {

      data_type  = "DOUBLE"
      logical_id = "voltage"
      name       = "b"
      type = {
        type_name = "Measurement"
      }
      unit = "mV"
    },
    {

      data_type  = "DOUBLE"
      logical_id = "battery_level"
      name       = "c"
      type = {
        type_name = "Measurement"
      }
      unit = "V"
    }
  ]

  tags = [{
    key   = "Modified By"
    value = "AWSCC"
  }]
}
gagan1469 commented 3 weeks ago

So there is definitely ordering happening based on the name. The example below doesn't introduce a drift.

resource "awscc_iotsitewise_asset_model" "vdc" {
  asset_model_name        = "vdc"
  asset_model_description = "Wireless Voltage Sensors"
  asset_model_type        = "ASSET_MODEL"
  asset_model_properties = [
    {

      data_type  = "STRING"
      logical_id = "id"
      name       = "a"
      type = {
        type_name = "Attribute"
        attribute = {
          default_value = "enter value here"
        }
      }
    },
    {

      data_type  = "DOUBLE"
      logical_id = "voltage"
      name       = "b"
      type = {
        type_name = "Measurement"
      }
      unit = "mV"
    },
    {

      data_type  = "DOUBLE"
      logical_id = "battery_level"
      name       = "c"
      type = {
        type_name = "Measurement"
      }
      unit = "V"
    }
  ]

  tags = [{
    key   = "Modified By"
    value = "AWSCC"
  }]
}

You are right. In the case of asset_model_properties it does sort by name. I tested against tags, and the ordering was not in alphabetical order of key name. I think you will agree that we cannot expect the user to list the model properties in alphabetical order. What happens when a property is added or removed? Besides, "name" is the value displayed in the console (and elsewhere) and has to be meaningful for the data consumer.

quixoticmonk commented 3 weeks ago

Researching this behavior as the id attributes stays in order similar to state.