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_greengrassv2_deployment always reset the components configuration #1689

Open obiSerra opened 4 months ago

obiSerra commented 4 months ago

Community Note

Terraform CLI and Terraform AWS Cloud Control Provider Version

Terraform v1.8.2 provider registry.terraform.io/hashicorp/awscc v0.76.0

Affected Resource(s)

awscc_greengrassv2_deployment

Terraform Configuration Files

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

resource "awscc_greengrassv2_deployment" "setup_deployment" {

  deployment_name = "setup-deployment"

  target_arn = "XXXX"

  deployment_policies = {
    configuration_validation_policy = {
      timeout_in_seconds = 60
    }
    component_update_policy = {
      timeout_in_seconds = 55
    }
    failure_handling_policy = "ROLLBACK"
  }

  components = {
    "aws.greengrass.Nucleus" = {
      component_version = "2.12.4"
      configuration_update = {
        Reset = [""]
        Merge = jsonencode(
          {
            "spooler" : {
              "storageType" : "Disk"
              "maxSizeInBytes" : "2048"
            }
          }
        )
      }
    },
    "aws.greengrass.Cli" = {
      component_version = "2.12.5"
    },
    "aws.greengrass.LogManager" = {
      component_version = "2.3.7"
      configuration_update = {
        Reset = [""]
        Merge = jsonencode(
          {
            "logsUploaderConfiguration" : {
              "systemLogsConfiguration" : {
                "uploadToCloudWatch" : "true",
                "minimumLogLevel" : "INFO",
                "diskSpaceLimit" : "10",
                "diskSpaceLimitUnit" : "MB",
                "deleteLogFileAfterCloudUpload" : "false"
              },
              "componentLogsConfigurationMap" : {
                "aws.greengrass.SystemsManagerAgent" : {
                  "minimumLogLevel" : "INFO",
                  "diskSpaceLimit" : "20",
                  "diskSpaceLimitUnit" : "MB",
                  "deleteLogFileAfterCloudUpload" : "false"
                }
              }
            },
            "periodicUploadIntervalSec" : "300",
            "deprecatedVersionSupport" : "false"
          }
        )
      }
    }
  }
}

Debug Output

Full debug output https://gist.github.com/obiSerra/2e00c9a2399fdc00c75ba712df2781c2

Expected Behavior

The components configuration should be the one defined inside the components.configuration_update.

Actual Behavior

The components configuration is always empty:

{
  "reset": [],
  "merge": {}
}

Steps to Reproduce

  1. Create a deployment using awscc_greengrassv2_deployment with any module that accepts a configuration (see above)
  2. terraform plan
  3. terraform apply

Important Factoids

While debugging I noticed that terraform generate this warning both during plan and during apply:

2024-05-07T17:43:05.998+0200 [WARN]  Provider "registry.terraform.io/hashicorp/awscc" produced an unexpected new value for awscc_greengrassv2_deployment.setup_deployment during refresh.
      - .components["aws.greengrass.LogManager"].configuration_update: was cty.ObjectVal(map[string]cty.Value{"merge":cty.NullVal(cty.String), "reset":cty.NullVal(cty.List(cty.String))}), but now null
      - .components["aws.greengrass.Nucleus"].configuration_update: was cty.ObjectVal(map[string]cty.Value{"merge":cty.NullVal(cty.String), "reset":cty.NullVal(cty.List(cty.String))}), but now null
      - .components["aws.greengrass.SystemsManagerAgent"].configuration_update: was cty.ObjectVal(map[string]cty.Value{"merge":cty.NullVal(cty.String), "reset":cty.NullVal(cty.List(cty.String))}), but now null
wellsiau-aws commented 4 months ago

I noticed on the debug log, AWSCC provider received the GetResponse from CCAPI after CreateResource: https://gist.github.com/obiSerra/2e00c9a2399fdc00c75ba712df2781c2#file-terraform-apply-txt-L433-L436

Diving deeper to the response body:

{
  "ResourceDescription": {
    "Identifier": "3ab52525-8625-447a-8513-7fc6d3aa75a4",
    "Properties": "{\"Components\":{\"aws.greengrass.SystemsManagerAgent\":{\"ComponentVersion\":\"1.2.4\"},\"aws.greengrass.LogManager\":{\"ComponentVersion\":\"2.3.7\"},\"aws.greengrass.Nucleus\":{\"ComponentVersion\":\"2.12.4\"}},\"DeploymentName\":\"setup-deployment\",\"DeploymentId\":\"3ab52525-8625-447a-8513-7fc6d3aa75a4\",\"TargetArn\":\"arn:aws:iot:eu-west-1:767397968620:thinggroup/test-device-group\",\"Tags\":{}}"
  },
  "TypeName": "AWS::GreengrassV2::Deployment"
}

and then decoding the Properties value:

{
  "Components": {
    "aws.greengrass.SystemsManagerAgent": {
      "ComponentVersion": "1.2.4"
    },
    "aws.greengrass.LogManager": {
      "ComponentVersion": "2.3.7"
    },
    "aws.greengrass.Nucleus": {
      "ComponentVersion": "2.12.4"
    }
  },
  "DeploymentName": "setup-deployment",
  "DeploymentId": "3ab52525-8625-447a-8513-7fc6d3aa75a4",
  "TargetArn": "arn:aws:iot:eu-west-1: 767397968620:thinggroup/test-device-group",
  "Tags": {}
}

I noticed that the Components attributes value are incomplete compared to what is declared in HCL.

wellsiau-aws commented 4 months ago

I think this is an upstream issue, GetResource should return the full ComponentDeploymentSpecification including the ComponentVersion, ConfigurationUpdate, and RunWith.

wellsiau-aws commented 4 months ago

Thanks for reporting this issue, I have escalated this to the service team at AWS.

obiSerra commented 4 months ago

thank for your quick answer

quixoticmonk commented 1 day ago

@wellsiau-aws @obiSerra The configuration_update has merge and reset capitalized in the example above.

resource "awscc_greengrassv2_deployment" "setup_deployment" {

  deployment_name = "setup-deployment"

  target_arn = awscc_iot_thing.example.arn

  deployment_policies = {
    configuration_validation_policy = {
      timeout_in_seconds = 60
    }
    component_update_policy = {
      timeout_in_seconds = 55
    }
    failure_handling_policy = "ROLLBACK"
  }

  components = {
    "aws.greengrass.Nucleus" = {
      component_version = "2.12.4"
      configuration_update = {
        reset = [""]
        merge = jsonencode(
          {
            "spooler" : {
              "storageType" : "Disk"
              "maxSizeInBytes" : "2048"
            }
          }
        )
      }
    },
    "aws.greengrass.Cli" = {
      component_version = "2.12.5"
    },
    "aws.greengrass.LogManager" = {
      component_version = "2.3.7"
      configuration_update = {
        reset = [""]
        merge = jsonencode(
          {
            "logsUploaderConfiguration" : {
              "systemLogsConfiguration" : {
                "uploadToCloudWatch" : "true",
                "minimumLogLevel" : "INFO",
                "diskSpaceLimit" : "10",
                "diskSpaceLimitUnit" : "MB",
                "deleteLogFileAfterCloudUpload" : "false"
              },
              "componentLogsConfigurationMap" : {
                "aws.greengrass.SystemsManagerAgent" : {
                  "minimumLogLevel" : "INFO",
                  "diskSpaceLimit" : "20",
                  "diskSpaceLimitUnit" : "MB",
                  "deleteLogFileAfterCloudUpload" : "false"
                }
              }
            },
            "periodicUploadIntervalSec" : "300",
            "deprecatedVersionSupport" : "false"
          }
        )
      }
    }
  }
}

@obiSerra Can you try the config with the lower case input params ?