cdk-stacksets icon indicating copy to clipboard operation
cdk-stacksets copied to clipboard

Error: Parameters: must have values

Open schnipseljagd opened this issue 1 year ago • 3 comments

When using StackSetTarget.fromAccounts with parameterOverrides the CDK synth works fine but when trying to deploy it the deployment fails:

TestStack failed: Error: The stack named TestStack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Parameters: [DevopsAccountId] must have values (Service: CloudFormation, Status Code: 400, Request ID: xxx)"
class TeamWorkloadAccountStackSet extends StackSetStack {
  constructor(scope: Construct, id: string) {
    super(scope, id)

    const devopsAccountIdParameter = new CfnParameter(this, 'DevopsAccountId', {
      type: 'String',
      description: 'The account ID of the associated devops account',
    })

    const role = new iam.Role(this, 'DevopsCrossAccountRole:', {
      roleName: 'devops-cross-account-role',
      managedPolicies: [
        iam.ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'),
      ],
      assumedBy: new iam.AccountPrincipal(
        devopsAccountIdParameter
      ),
    })
    Tags.of(role).add('Pulumi', 'DevopsCrossAccountRole')
  }
}

 const teamWorkloadAccountStackSetStack = new TeamWorkloadAccountStackSet(
      this,
      'TeamWorkloadAccountStackSetStack',
    )
 const stackSet = new StackSet(this, 'TeamWorkloadAccountStackSet', {
      capabilities: [Capability.NAMED_IAM],
      template: StackSetTemplate.fromStackSetStack(
        teamWorkloadAccountStackSetStack,
      ),
      deploymentType: DeploymentType.selfManaged({
        adminRole: this.selfManagedStackSetAdministratorRole,
        executionRoleName: 'AWSCloudFormationStackSetExecutionRole',
      }),
      target: StackSetTarget.fromAccounts({
        regions: ['eu-central-1'],
        accounts: ['xxx'],
        parameterOverrides: {
          DevopsAccountId: 'xxx',
        },
      })
    })

A workaround is to fix the parameters via Cloudformation:

// this fixes a bug with the parameters in the cdk-stacksets library
    const cfnStackSet = stackSet.node.defaultChild as CfnStackSet
    cfnStackSet.addOverride('Properties.Parameters', [{
      'ParameterKey': 'DevopsAccountId',
      'ParameterValue': ''
    }])

schnipseljagd avatar May 17 '23 09:05 schnipseljagd