mongodb / awscdk-resources-mongodbatlas

MongoDB Atlas AWS CDK Resources
Apache License 2.0
33 stars 15 forks source link

[Bug]: Creating Cluster as per L1 Cluster example fails (COMPUTE_AUTO_SCALING_MAX_INSTANCE_SIZE_REQUIRED) #256

Closed alancooper-exizent closed 2 months ago

alancooper-exizent commented 2 months ago

Is there an existing issue for this?

CDK package version

3.3.0

CFN Resource version

MongoDB::Atlas::Cluster v2.0.0

CFN Resource Region

eu-west-2

Current Behavior

When I deploy a cluster using the CfnCluster resource in CDK exactly as https://github.com/mongodb/awscdk-resources-mongodbatlas/blob/main/examples/l1-resources/cluster.ts the stack creation fails on creating the cluster itself with the error:

Resource handler returned message: "https://cloud.mongodb.com/api/atlas/v2/groups/661d67652954641210cbb2d1/clusters POST: HTTP 400 Bad Request (Error code: "COMPUTE_AUTO_SCALING_MAX_INSTANCE_SIZE_REQUIRED") Detail: Compute auto-scaling max instance size required. Reason: Bad Request. Params: []" (RequestToken: 6346e8cb-ec23-788c-b345-f53365eaab9d, HandlerErrorCode: InvalidRequest)

AWS CDK code to reproduce the issue

// This example creates a project and a cluster in Atlas using the L1 resources.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnProject, CfnCluster } from 'awscdk-resources-mongodbatlas';

interface AtlasStackProps {
  readonly orgId: string;
  readonly profile: string;
  readonly projName: string;
  readonly clusterName: string;
  readonly clusterType: string;
  readonly instanceSize: string;
  readonly region: string;
}

export class CdkTestingStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const atlasProps = this.getContextProps();

    const projectRes = new CfnProject(this, 'ProjectResource', {
      name: atlasProps.projName,
      orgId: atlasProps.orgId,
      profile: atlasProps.profile
    });

    const clusterRes = new CfnCluster(this, 'ClusterResource', {
      name: atlasProps.clusterName,
      projectId: projectRes.attrId,
      profile: atlasProps.profile,
      clusterType: atlasProps.clusterType,
      backupEnabled: true,
      pitEnabled: false,
      replicationSpecs: [{
        numShards: 1,
        advancedRegionConfigs: [{
          autoScaling: {
            diskGb: {
              enabled: true,
            },
            compute: {
              enabled: false,
              scaleDownEnabled: false,
            },
          },
          analyticsSpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          electableSpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          readOnlySpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          priority: 7,
          regionName: atlasProps.region,
        }]
      }]
    });

  }

  getContextProps(): AtlasStackProps {
    const orgId = this.node.tryGetContext('orgId');
    if (!orgId){
      throw "No context value specified for orgId. Please specify via the cdk context."
    }
    const projName = this.node.tryGetContext('projName') ?? 'test-proj';
    const profile = this.node.tryGetContext('profile') ?? 'default';
    const clusterName = this.node.tryGetContext('clusterName') ?? 'test-cluster';
    const clusterType = this.node.tryGetContext('clusterType') ?? 'REPLICASET';
    const instanceSize = this.node.tryGetContext('instanceSize') ?? "M10";
    const region = this.node.tryGetContext('region') ?? "US_EAST_1";

    return {
      projName,
      orgId,
      profile,
      clusterName,
      clusterType,
      instanceSize,
      region,
    }
  }
}

Steps To Reproduce

In AWS EU-WEST-2, running as an IAM role with full admin privileges,

cdk deploy ClusterStack --context orgId="myOrgId" --context profile="bitbucket"

Some resources create OK but the cluster always fails with this 400

cdk synth

PS C:\dev\mongodb-atlas\cdk> aws-vault exec sandbox-access -- cdk synth  ClusterStack --context orgId="61ba14795267585ea58d41e4" --context profile="bitbucket"
Resources:
  ProjectResource:
    Type: MongoDB::Atlas::Project
    Properties:
      Name: shared-cluster
      OrgId: 61ba14795267585ea58d41e4
      Profile: bitbucket
    Metadata:
      aws:cdk:path: ClusterStack/ProjectResource
  ClusterResource:
    Type: MongoDB::Atlas::Cluster
    Properties:
      BackupEnabled: false
      ClusterType: REPLICASET
      Profile: bitbucket
      ProjectId:
        Fn::GetAtt:
          - ProjectResource
          - Id
      Name: shared-cluster
      PitEnabled: false
      ReplicationSpecs:
        - NumShards: 1
          AdvancedRegionConfigs:
            - AutoScaling:
                DiskGB:
                  Enabled: true
                Compute:
                  Enabled: true
                  ScaleDownEnabled: false
              RegionName: EU_WEST_2
              AnalyticsSpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
              ElectableSpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
              Priority: 7
              ReadOnlySpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
    Metadata:
      aws:cdk:path: ClusterStack/ClusterResource
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Analytics: v2:deflate64:H4sIAAAAAAAA/zPSMzQ21zNQTCwv1k1OydbNyUzSqw4uSUzO1nFOywtKLc4vLUpOBbGd8/NSMksy8/NqdfLyU1L1sor1y4wM9AwN9QwVs4ozM3WLSvNKMnNT9YIgNAD3XMr5WgAAAA==
    Metadata:
      aws:cdk:path: ClusterStack/CDKMetadata/Default
    Condition: CDKMetadataAvailable
Conditions:
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - af-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - il-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-2
Parameters:
  BootstrapVersion:
    Type: AWS::SSM::Parameter::Value<String>
    Default: /cdk-bootstrap/hnb659fds/version
    Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
Rules:
  CheckBootstrapVersion:
    Assertions:
            - Fn::Contains:
                - - "1"
                  - "2"
                  - "3"
                  - "4"
                  - "5"
                - Ref: BootstrapVersion
        AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.       

PS C:\dev\mongodb-atlas\cdk> aws-vault exec sandbox-access -- cdk synth  ClusterStack --context orgId="61ba14795267585ea58d41e4" --context profile="bitbucket" >cloudformation.yml
                             ^C                                                                                                           
PS C:\dev\mongodb-atlas\cdk> aws-vault exec sandbox-access -- cdk synth  ClusterStack --context orgId="61ba14795267585ea58d41e4" --context profile="bitbucket"                    
Resources:
  ProjectResource:
    Type: MongoDB::Atlas::Project
    Properties:
      Name: shared-cluster
      OrgId: 61ba14795267585ea58d41e4
      Profile: bitbucket
    Metadata:
      aws:cdk:path: ClusterStack/ProjectResource
  ClusterResource:
    Type: MongoDB::Atlas::Cluster
    Properties:
      BackupEnabled: false
      ClusterType: REPLICASET
      Profile: bitbucket
      ProjectId:
        Fn::GetAtt:
          - ProjectResource
          - Id
      Name: shared-cluster
      PitEnabled: false
      ReplicationSpecs:
        - NumShards: 1
          AdvancedRegionConfigs:
            - AutoScaling:
                DiskGB:
                  Enabled: true
                Compute:
                  Enabled: true
                  ScaleDownEnabled: false
              RegionName: EU_WEST_2
              AnalyticsSpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
              ElectableSpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
              Priority: 7
              ReadOnlySpecs:
                EbsVolumeType: STANDARD
                InstanceSize: M10
                NodeCount: 3
    Metadata:
      aws:cdk:path: ClusterStack/ClusterResource
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Analytics: v2:deflate64:H4sIAAAAAAAA/zPSMzQ21zNQTCwv1k1OydbNyUzSqw4uSUzO1nFOywtKLc4vLUpOBbGd8/NSMksy8/NqdfLyU1L1sor1y4wM9AwN9QwVs4ozM3WLSvNKMnNT9YIgNAD3XMr5WgAAAA==
    Metadata:
      aws:cdk:path: ClusterStack/CDKMetadata/Default
    Condition: CDKMetadataAvailable
Conditions:
  CDKMetadataAvailable:
    Fn::Or:
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - af-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-northeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-1
          - Fn::Equals:
              - Ref: AWS::Region
              - ap-southeast-2
          - Fn::Equals:
              - Ref: AWS::Region
              - ca-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - cn-northwest-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-north-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-2
          - Fn::Equals:
              - Ref: AWS::Region
              - eu-west-3
          - Fn::Equals:
              - Ref: AWS::Region
              - il-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-central-1
          - Fn::Equals:
              - Ref: AWS::Region
              - me-south-1
          - Fn::Equals:
              - Ref: AWS::Region
              - sa-east-1
      - Fn::Or:
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-east-2
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-1
          - Fn::Equals:
              - Ref: AWS::Region
              - us-west-2
Parameters:
  BootstrapVersion:
    Type: AWS::SSM::Parameter::Value<String>
    Default: /cdk-bootstrap/hnb659fds/version
    Description: Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip] 
Rules:
  CheckBootstrapVersion:
    Assertions:
      - Assert:
          Fn::Not:
            - Fn::Contains:
                - - "1"
                  - "2"
                  - "3"
                  - "4"
                  - "5"
                - Ref: BootstrapVersion
        AssertDescription: CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.

Code of Conduct

github-actions[bot] commented 2 months ago

Thanks for opening this issue! Please make sure to provide the following information to help us reproduce the issue:

Thanks for opening this issue. The ticket CLOUDP-243501 was created for internal tracking.

marcosuma commented 2 months ago

Hi @alancooper-exizent, sorry to hear that you are running into this issue. I've tried to replicate the issue using the same script and it actually worked with the 2.0.0

This is the command I used:

cdk bootstrap aws://AWS_ACCOUNT_ID/ap-northeast-3

cdk deploy \
--context orgId=ORG_ID \
--context continuousBackupEnabled=false \
--context region=EU_WEST_2 \
--context profile=marcosuma \
--context projName=PROJ_NAME \
--context clusterName=CLUSTER_NAME \
--context clusterType=REPLICASET \
--context instanceSize=M10
Screenshot 2024-04-19 at 15 24 26

One thing that @maastha noticed is that your CDK script doesn't match with the CFN script. in the latter you have auto-scaling enabled which instead is false in the CDK script.

Might be possible there is something different that has been done compared to what you described here?

This is the code I used:

// This example creates a project and a cluster in Atlas using the L1 resources.
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { CfnProject, CfnCluster } from 'awscdk-resources-mongodbatlas';

interface AtlasStackProps {
  readonly orgId: string;
  readonly profile: string;
  readonly projName: string;
  readonly clusterName: string;
  readonly clusterType: string;
  readonly instanceSize: string;
  readonly region: string;
}

export class CdkExamplesStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const atlasProps = this.getContextProps();

    const projectRes = new CfnProject(this, 'ProjectResource', {
      name: atlasProps.projName,
      orgId: atlasProps.orgId,
      profile: atlasProps.profile
    });

    const clusterRes = new CfnCluster(this, 'ClusterResource', {
      name: atlasProps.clusterName,
      projectId: projectRes.attrId,
      profile: atlasProps.profile,
      clusterType: atlasProps.clusterType,
      backupEnabled: true,
      pitEnabled: false,
      replicationSpecs: [{
        numShards: 1,
        advancedRegionConfigs: [{
          autoScaling: {
            diskGb: {
              enabled: true,
            },
            compute: {
              enabled: false,
              scaleDownEnabled: false,
            },
          },
          analyticsSpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          electableSpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          readOnlySpecs: {
            ebsVolumeType: "STANDARD",
            instanceSize: atlasProps.instanceSize,
            nodeCount: 3,
          },
          priority: 7,
          regionName: atlasProps.region,
        }]
      }]
    });

  }

  getContextProps(): AtlasStackProps {
    const orgId = this.node.tryGetContext('orgId');
    if (!orgId){
      throw "No context value specified for orgId. Please specify via the cdk context."
    }
    const projName = this.node.tryGetContext('projName') ?? 'test-proj';
    const profile = this.node.tryGetContext('profile') ?? 'default';
    const clusterName = this.node.tryGetContext('clusterName') ?? 'test-cluster';
    const clusterType = this.node.tryGetContext('clusterType') ?? 'REPLICASET';
    const instanceSize = this.node.tryGetContext('instanceSize') ?? "M10";
    const region = this.node.tryGetContext('region') ?? "US_EAST_1";

    return {
      projName,
      orgId,
      profile,
      clusterName,
      clusterType,
      instanceSize,
      region,
    }
  }
}