aws / aws-toolkit-azure-devops

AWS Toolkit for Azure DevOps
Other
245 stars 104 forks source link

'Expected params.Parameters to be an Array' When Using CloudFormationCreateOrUpdateStack@1 Task with Template Parameters File #554

Open rchildress87 opened 3 months ago

rchildress87 commented 3 months ago

Describe the bug

I receive the following error when I attempt to create or update a stack using the CloudFormationCreateOrUpdateStack@1 task and specifying a template parameters file:

Loading template parameters file '/home/vsts/work/1/a/CloudFormation/parameters/parameters.dev.json'
##[debug]Attempting parse as json content
##[debug]Successfully parsed template parameters
Successfully loaded template parameters
Setting capability CAPABILITY_IAM for stack
Setting capability CAPABILITY_NAMED_IAM for stack
Adding tag. Key 'key1', Value 'value1'
Adding tag. Key 'key2', Value 'value2'
Adding tag. Key 'application', Value 'pipeline-poc'
Adding tag. Key 'environment', Value 'dev'
##[debug]AWS updateStack request ID: undefined
Stack update request failed with error: 'Expected params.Parameters to be an Array' { InvalidParameterType: Expected params.Parameters to be an Array
##[debug]task result: Failed
    at constructor.fail (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:201)
    at constructor.validateType (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:3508)
##[error]InvalidParameterType: Expected params.Parameters to be an Array
##[debug]Processed: ##vso[task.issue type=error;]InvalidParameterType: Expected params.Parameters to be an Array
    at constructor.validateList (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:975)
    at constructor.validateMember (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:833)
    at constructor.validateStructure (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:595)
    at constructor.validateMember (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:29:785)
    at constructor.validate (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:27:3483)
    at constructor.<anonymous> (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:16:115446)
    at constructor.callListeners (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:16:86263)
    at p (/home/vsts/work/_tasks/CloudFormationCreateOrUpdateStack_7ef7cdfa-aa45-42c5-93c8-d7603643dd99/1.14.0/CloudFormationCreateOrUpdateStack.js:16:86148)
  message: 'Expected params.Parameters to be an Array',
  code: 'InvalidParameterType',
  time: 2024-06-21T19:28:38.573Z }

Here is the task's definition:

- task: CloudFormationCreateOrUpdateStack@1
  inputs:
    awsCredentials: $(awsServiceConnection)
    regionName: "us-east-1"
    stackName: "pipeline-poc-stack"
    templateSource: "s3"
    s3BucketName: "bucket-name"
    s3ObjectKey: "main.template.yaml"
    templateParametersSource: "file"
    templateParametersFile: "$(Build.ArtifactStagingDirectory)/CloudFormation/parameters/parameters.dev.json"
    tags: |
      key1=value1
      key2=value2
      application=pipeline-poc
      environment=dev

Here are the contents of parameters.dev.json, formatted according to the task's documentation:

[
  {
    "ParameterKey": "ClassB",
    "ParameterValue": "123"
  }
]

I have also tried the other two parameter formats that are provided in the AWS CLI documentation:

[
  "ClassB=123"
]
[
  "Parameters": {
    "ClassB": "123"
  }
]

All three formats seem to be supported by the AWS CLI but error out in Azure DevOps.

When I attempt to use the exact same parameters file with the AWS CLI, the deployment is successful and the parameters are applied:

$ aws cloudformation deploy --stack-name pipeline-poc-dev-stack --template-file templates/main.template.yaml --s3-bucket bucket-name --parameter-overrides file://./parameters/parameters.dev.json --no-execute-changeset 

Waiting for changeset to be created..
Changeset created successfully. Run the following command to review changes:
aws cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1:123456789012:changeSet/awscli-cloudformation-package-deploy-8526790111/ba3fa778-df9f-425f-acd9-0ccbca7d1b07

$ aws cloudformation describe-change-set --change-set-name arn:aws:cloudformation:us-east-1:123456789012:changeSet/awscli-cloudformation-package-deploy-8526790111/ba3fa778-df9f-425f-acd9-0ccbca7d1b07

{
    "Changes": [
        {
            "Type": "Resource",
            "ResourceChange": {
                "Action": "Add",
                "LogicalResourceId": "vpcStack",
                "ResourceType": "AWS::CloudFormation::Stack",
                "Scope": [],
                "Details": []
            }
        }
    ],
    "ChangeSetName": "awscli-cloudformation-package-deploy-8526790111",
    "ChangeSetId": "arn:aws:cloudformation:us-east-1:123456789012:changeSet/awscli-cloudformation-package-deploy-8526790111/ba3fa778-df9f-425f-acd9-0ccbca7d1b07",
    "StackId": "arn:aws:cloudformation:us-east-1:123456789012:stack/pipeline-poc-dev-stack/7954f9ef-9334-400f-b7cf-828645105348",
    "StackName": "pipeline-poc-dev-stack",
    "Description": "Created by AWS CLI at 2024-06-21T19:26:53.123725 UTC",
    "Parameters": [
        {
            "ParameterKey": "ClassB",
            "ParameterValue": "123"
        }
    ],
    "CreationTime": "2024-06-21T19:26:54.435000+00:00",
    "ExecutionStatus": "AVAILABLE",
    "Status": "CREATE_COMPLETE",
    "StatusReason": null,
    "NotificationARNs": [],
    "RollbackConfiguration": {},
    "Capabilities": [],
    "Tags": null,
    "ParentChangeSetId": null,
    "IncludeNestedStacks": false,
    "RootChangeSetId": null,
    "OnStackFailure": null,
    "ImportExistingResources": null
}

To reproduce

Steps to reproduce the behavior:

  1. Create a pipeline that uses the CloudFormationCreateOrUpdateStack@1 task.
  2. Specify a template parameters file, in addition to the template file, in the task's inputs.
  3. Execute the task.

Expected behavior

The CloudFormationCreateOrUpdateStack@1 passes along the parameters as defined in the template parameters file and successfully creates or updates the stack.

Your Environment