aws-samples / aws-codepipeline-terraform-cicd-samples

MIT No Attribution
95 stars 102 forks source link

run_order is not working with codepipeline #16

Open HarshitSF opened 4 months ago

HarshitSF commented 4 months ago

Problem Statement:: I am using the code-pipeline module to create a pipeline and setting run_order value to run parallel action In codepipeline but all the actions in pipelines are getting created sequentially.

I have created my module of pipeline with some little changes in the module mentioned in this repository. here is my terraform files of the module.

  1. main.tf
    
    terraform {
    required_version = "~> 1.4"
    required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "5.4.0"
    }
    }
    }

resource "aws_codepipeline" "deployment_pipeline" { name = var.name role_arn = var.role_arn

artifact_store { location = var.s3_bucket_name type = "S3" }

stage { name = "Source"

action {
  name             = "Source"
  category         = "Source"
  owner            = "AWS"
  version          = "1"
  provider         = "CodeStarSourceConnection"
  output_artifacts = ["source_output"]

  configuration = {
    FullRepositoryId = var.source_repo_name
    BranchName       = var.source_repo_branch
    ConnectionArn    = var.ConnectionArn
  }
}

}

dynamic "stage" { for_each = var.stages

content {
  name = "Stage-${stage.value["name"]}"
  action {
    category         = stage.value["category"]
    name             = "Action-${stage.value["name"]}"
    owner            = stage.value["owner"]
    provider         = stage.value["provider"]
    input_artifacts  = [stage.value["input_artifacts"]]
    output_artifacts = [stage.value["output_artifacts"]]
    version          = "1"
    run_order        = stage.value["run_order"]

    configuration = {
      ProjectName = stage.value["project_name"]
    }
  }
}

} tags = var.tags }

2. variables.tf 

variable "name" { description = "Unique name for this project" type = string }

variable "source_repo_name" { description = "Source repo name of the CodeCommit repository" type = string }

variable "source_repo_branch" { description = "Default branch in the Source repo for which CodePipeline needs to be configured" type = string }

variable "ConnectionArn" { description = "Github Connection ARN" type = string }

variable "s3_bucket_name" { description = "S3 bucket name to be used for storing the artifacts" type = string }

variable "role_arn" { description = "ARN of the codepipeline IAM role" type = string }

variable "tags" { description = "Tags to be attached to the CodePipeline" type = map(any) }

variable "stages" { description = "List of Map containing information about the stages of the CodePipeline" type = list(map(any)) }

Here I am passing _**run_order**_  not as a static value but will pass through the parent module.

Now I am referencing this module in my other terraform file which is described here - 

module "deployment_pipeline" { source = "../../modules/codepipeline"

name = "${var.namespace}-${var.environment}-terraform-pipeline" role_arn = module.codepipeline_role.arn s3_bucket_name = data.aws_ssm_parameter.artifact_bucket.value

ConnectionArn = data.aws_codestarconnections_connection.existing_github_connection.arn source_repo_name = var.github_FullRepositoryId source_repo_branch = var.github_BranchName stages = [ { name = "Bootstrap", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 2, project_name = "${module.initial_bootstrap.name}" }, { name = "Networking", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 3, project_name = "${module.networking_module_build_step_codebuild_project.name}" }, { name = "Database", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 4, project_name = "${aws_codebuild_project.rds_module_build_step_codebuild_project.name}" }, { name = "Elasticache", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 4, project_name = "${module.elasticache_module_build_step_codebuild_project.name}" }, { name = "Opensearch", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 4, project_name = "${module.opensearch_module_build_step_codebuild_project.name}" }, { name = "ClientVPN", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 4, project_name = "${module.vpn_module_build_step_codebuild_project.name}" }, { name = "IAMRole", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 5, project_name = "${module.iam_role_module_build_step_codebuild_project.name}" }, { name = "EKS", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 6, project_name = "${module.eks_module_build_step_codebuild_project.name}" }, { name = "EKS-Auth", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 7, project_name = "${module.eks_auth_module_build_step_codebuild_project.name}" }, { name = "EKS-Istio", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 7, project_name = "${module.istio_module_build_step_codebuild_project.name}" }, { name = "Observability", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 7, project_name = "${module.eks_observability_module_build_step_codebuild_project.name}" }, { name = "Opensearch-Ops", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 7, project_name = "${aws_codebuild_project.os_ops_module_build_step_codebuild_project.name}" }, { name = "Cognito", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 8, project_name = "${module.cognito_module_build_step_codebuild_project.name}" }, { name = "ControlPlaneApplication", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 8, project_name = "${module.control_plane_module_build_step_codebuild_project.name}" }, { name = "TenantCodebuilds", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 8, project_name = "${module.tenant_codebuild_module_build_step_codebuild_project.name}" }, { name = "Billing", category = "Build", owner = "AWS", provider = "CodeBuild", input_artifacts = "source_output", output_artifacts = "", run_order = 8, project_name = "${module.billing_module_build_step_codebuild_project.name}" } ] tags = module.tags.tags }


Here I am providing **_run_order_** value the same for some actions (like Database & Elasticache) so it should create parallel actions in the code pipeline but it is creating sequential actions. 

![image](https://github.com/aws-samples/aws-codepipeline-terraform-cicd-samples/assets/69293204/9d28294a-cc0d-4446-bb50-f82782ad382d)

P.S. The Module is not giving any errors. It is creating a pipeline with all the above actions as mentioned.

For any other information, please let me know. 
HarshitSF commented 1 month ago

Any update on this ?