2

I'm trying to use terraform to create a CodePipeline job. I have a working CodeBuild project already. Here's my resource:

resource "aws_codepipeline" "my-project" {
  name     = "my-project"
  role_arn = "${aws_iam_role.my-project-codepipeline.arn}"

  artifact_store {
    location = "${aws_s3_bucket.my-artifacts.bucket}"
    type     = "S3"
  }

  stage {
    name = "Source"

    action {
      name     = "Source"
      category = "Source"
      owner    = "AWS"
      provider = "CodeCommit"
      version  = "1"

      configuration {
        ProjectName = "my-project"
        Branch      = "master"
      }
    }
  }

  stage {
    name = "Build"

    action {
      name     = "Build"
      category = "Build"
      owner    = "AWS"
      provider = "CodeBuild"
      version  = "1"

      configuration {
        ProjectName = "my-project"
      }
    }
  }
}

When I try terraform apply the error I get is Error creating CodePipeline: InvalidActionDeclarationException: Action configuration for action 'Source' contains unknown configuration 'ProjectName'. Where can I find the proper schema for this configuration section? All the docs and examples I have found so far are generic and omit the specific CodeBuild settings/schema I would need here.

2 Answers 2

5

Turns out the settings I need for Source are

RepositoryName = "my-project"
BranchName = "master"
Sign up to request clarification or add additional context in comments.

Comments

0

This may help if you end up needing access to the CodeBuild sts token.

version: 0.2
env:
  variables:
    AWS_DEFAULT_REGION: "us-west-2"
phases:
  install:
    commands:
      - apt-get -y update
      - apt-get -y install jq
  pre_build:
      commands:

      # load acs submodule (since codebuild doesn't pull the .git folder from the repo
      - cd common 
      - git clone https://[email protected]/aws-account-tools/acs.git
      - cd ../

      #install terraform
      - other/install-tf-linux64.sh
      - terraform --version

      #set env variables for terraform provider
      - curl 169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI | jq 'to_entries | [ .[] | select(.key | (contains("Expiration") or contains("RoleArn"))  | not) ] |  map(if .key == "AccessKeyId" then . + {"key":"AWS_ACCESS_KEY_ID"} else . end) | map(if .key == "SecretAccessKey" then . + {"key":"AWS_SECRET_ACCESS_KEY"} else . end) | map(if .key == "Token" then . + {"key":"AWS_SESSION_TOKEN"} else . end) | map("export \(.key)=\(.value)") | .[]' -r > /tmp/cred.txt # work around https://github.com/hashicorp/terraform/issues/8746
      - chmod +x /tmp/cred.txt
      - . /tmp/cred.txt
  build:
    commands:
      - ls
      - cd your/repo's/folder/with/main.tf 
      - terraform init 
      - terraform plan 
      - terraform 

apply

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.