Skip to content

Error in creating CodedeployDeploymentGroup with targetGroupPairInfo #26719

@Samith88

Description

@Samith88

I need create an aws codedeploy deployment group for Blue/Green deployments with EC2 using cdktf. My code for codedeploy deployment group as follows,

new CodedeployDeploymentGroup(
  this,
  `${APP_ENV}-codedeploy-deploymentGroup`,
  {
    appName: codedeployApp.name,
    deploymentGroupName: props.environment,
    serviceRoleArn: new DataAwsIamRole(this, `${APP_ENV}-codedeploy-role`, {
      name: `${APP_ENV}-codedeploy-role`,
    }).arn,
    autoscalingGroups: [asgBlue.name,asgGreen.name],
    autoRollbackConfiguration: {
      enabled: true,
      events: ["DEPLOYMENT_FAILURE"], // "DEPLOYMENT_STOP_ON_ALARM"],
    },
    blueGreenDeploymentConfig: {
      deploymentReadyOption: {
        actionOnTimeout: "CONTINUE_DEPLOYMENT",
      },
      greenFleetProvisioningOption: {
        action: "DISCOVER_EXISTING",
      },
      terminateBlueInstancesOnDeploymentSuccess: {
        action: "TERMINATE",
        terminationWaitTimeInMinutes: 300,
      },
    },
    deploymentStyle: {
      deploymentOption: "WITH_TRAFFIC_CONTROL",
      deploymentType: "BLUE_GREEN",
    },
    loadBalancerInfo: {
      targetGroupPairInfo: {
        prodTrafficRoute: {
          listenerArns: [activeListener]
        },
        targetGroup: [
          {
            name: `${APP_ENV}-green`,
          },
          {
            name: `${APP_ENV}-blue`,
          },
        ],
        testTrafficRoute: {
          listenerArns: [inactiveListener]
        }
      },
    },
  }
);

But when I'm trying to deploy this, I'm getting following error,

[2022-09-06T10:12:44.199] [ERROR] default - ╷ │ Error: Error creating CodeDeploy deployment group: InvalidLoadBalancerInfoException: The specification for load balancing in the deployment group is invalid. The deploymentOption value is set to WITH_TRAFFIC_CONTROL, but either no load balancer was specified in elbInfoList or no target group was specified in targetGroupInfoList. │ │ with aws_codedeploy_deployment_group.sre4-testapp-dev-codedeploy-deploymentGroup, │ on cdk.tf.json line 400, in resource.aws_codedeploy_deployment_group.sre4-testapp-dev-codedeploy-deploymentGroup: │ 400: }

But as per my code, I'm passing target groups for create this object.

Also, noticed that in aws docs we have loadBalancerInfo -> targetGroupPairInfo -> targetGroups which is not available in cdktf package(CodedeployDeploymentGroupConfig).

Ref: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codedeploy-deploymentgroup-targetgrouppairinfo.html

I Have ran cdktf by enabling trace logs, so the response and request I got as follows,

Request for codedeploy,

---[ REQUEST POST-SIGN ]-----------------------------
POST / HTTP/1.1
Host: codedeploy.us-east-1.amazonaws.com
User-Agent: APN/1.0 HashiCorp/1.0 Terraform/1.2.7 (+https://www.terraform.io) terraform-provider-aws/3.75.1 (+https://registry.terraform.io/providers/hashicorp/aws) aws-sdk-go/1.43.17 (go1.16; linux; amd64) cdktf/0.12.1 (+https://github.com/hashicorp/terraform-cdk)
Content-Length: 1213
Content-Type: application/x-amz-json-1.1
X-Amz-Date: 20220908T023139Z
X-Amz-Target: CodeDeploy_20141006.CreateDeploymentGroup
Accept-Encoding: gzip

{"applicationName":"sre4-testapp-dev","autoRollbackConfiguration":{"enabled":true,"events":["DEPLOYMENT_FAILURE"]},"autoScalingGroups":["sre4-testapp-dev-green","sre4-testapp-dev-blue"],"blueGreenDeploymentConfiguration":{"deploymentReadyOption":{"actionOnTimeout":"CONTINUE_DEPLOYMENT","waitTimeInMinutes":0},"greenFleetProvisioningOption":{"action":"DISCOVER_EXISTING"},"terminateBlueInstancesOnDeploymentSuccess":{"action":"TERMINATE","terminationWaitTimeInMinutes":300}},"deploymentConfigName":"CodeDeployDefault.OneAtATime","deploymentGroupName":"dev","deploymentStyle":{"deploymentOption":"WITH_TRAFFIC_CONTROL","deploymentType":"BLUE_GREEN"},"loadBalancerInfo":{"targetGroupPairInfoList":[{"prodTrafficRoute":{"listenerArns":["arn:aws:elasticloadbalancing:us-east-1:177807608173:listener/app/sre4-testapp-dev-alb-dev-alb/ac37cd4a1279bd68/516cf17af4109db2"]},"targetGroups":[{"name":"sre4-testapp-dev-green"},{"name":"sre4-testapp-dev-blue"}],"testTrafficRoute":{"listenerArns":["arn:aws:elasticloadbalancing:us-east-1:177807608173:listener/app/sre4-testapp-dev-alb-dev-alb/ac37cd4a1279bd68/75083704af3281c5"]}}]},"serviceRoleArn":"arn:aws:iam::177807608173:role/sre4-testapp-dev-codedeploy-role","tags":[]}
-----------------------------------------------------: timestamp=2022-09-08T08:01:39.283+0530

Response for codedeploy,

CreateDeploymentGroup Details:
---[ RESPONSE ]--------------------------------------
HTTP/1.1 400 Bad Request
Connection: close
Content-Length: 303
Content-Type: application/x-amz-json-1.1
Date: Thu, 08 Sep 2022 02:31:41 GMT
X-Amzn-Requestid: 6bd28e9f-44e0-4edb-ba3e-fde8ec262fc0


-----------------------------------------------------: timestamp=2022-09-08T08:01:42.047+0530
2022-09-08T08:01:42.047+0530 [INFO]  provider.terraform-provider-aws_v3.75.1_x5: 2022/09/08 08:01:42 [DEBUG] [aws-sdk-go] {"__type":"InvalidLoadBalancerInfoException","message":"The specification for load balancing in the deployment group is invalid. The deploymentOption value is set to WITH_TRAFFIC_CONTROL, but either no load balancer was specified in elbInfoList or no target group was specified in targetGroupInfoList."}: timestamp=2022-09-08T08:01:42.047+0530
2022-09-08T08:01:42.047+0530 [INFO]  provider.terraform-provider-aws_v3.75.1_x5: 2022/09/08 08:01:42 [DEBUG] [aws-sdk-go] DEBUG: Validate Response codedeploy/CreateDeploymentGroup failed, attempt 0/25, error InvalidLoadBalancerInfoException: The specification for load balancing in the deployment group is invalid. The deploymentOption value is set to WITH_TRAFFIC_CONTROL, but either no load balancer was specified in elbInfoList or no target group was specified in targetGroupInfoList.: timestamp=2022-09-08T08:01:42.047+0530

Some environment details,

terraformProviders (aws)= 3.75.1

$ cdktf --version
0.12.2

$ node -v
v16.13.0

$ npm -v
8.19.1

For further information you can refer this issue which I was created in terraform-cdk repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    service/deployIssues and PRs that pertain to the deploy service.staleOld or inactive issues managed by automation, if no further action taken these will get closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions