Terraform: AWS Codepipeline multiple Codecommit sources

Looking into this, I have found that it's not very well documented anywhere which is actually very frustrating. Leveraging hashicorp vague description of the service and AWS multi-input example I was finally able to come up with this for terraform:

 "aws_codepipeline" "foo" {
  name     = "tf-test-pipeline"
  role_arn = "codepipeline service role arn"

  artifact_store {
    location = "s3 bucket name, NOT THE ARN"
    type     = "S3"
  }

  stage {
    name = "Source"

    action {
      name             = "Source"
      category         = "Source"
      owner            = "AWS"
      provider         = "CodeCommit"
      version         = "1"
      output_artifacts = ["src"]

      configuration = {
        RepositoryName = "vpc" //MUST BE the name of the your codecommit repo
        BranchName = "master"
      }

      run_order = "1"
    }

    action {
      name             = "2ndSource" //you can make this any name
      category         = "Source"
      owner            = "AWS"
      provider         = "CodeCommit"
      version         = "1"
      output_artifacts = ["src2"]

      configuration = {
        RepositoryName = "ec2" 
        BranchName = "master"
      }
      run_order = "2"
    }


  }


  stage {
    name = "Build"

    action {
      name            = "Build"
      category        = "Build"
      owner           = "AWS"
      provider        = "CodeBuild"
      input_artifacts = ["src","src2"] //pass through both repositories
      version         = "1"

      configuration = {
        ProjectName = "codebuild_project_name"
        PrimarySource = "Source"
      }
    }
  }
}

The trick here is to add additional sources into one stage, not separate ones. The reference below shows two of them but I have been able to add three with no problem.

Reference Links:

Hashicorp CodePipeline https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/codepipeline#run_order

AWS Multiple Inputs Json Example: https://docs.aws.amazon.com/codebuild/latest/userguide/sample-pipeline-multi-input-output.html

For those of you getting started for the first time, I recommend this link, it's pretty comprehensive and walks you through the entire build process which includes roles and policies: https://medium.com/swlh/intro-to-aws-codecommit-codepipeline-and-codebuild-with-terraform-179f4310fe07