1

Need some help from the community. I think I almost have it but I can't find documentation showing me how to configure Codebuild project with AWS Codecommit. Looking for someone to give me a few links that can help or some assistance with my code.

resource "aws_codebuild_project" "cb_test_project" {
    name            = var.cb_name
    description     = var.description
    build_timeout   = var.build_timeout
    service_role    = var.cb_service_role
    source_version  = var.branch_name //set to main by default

    artifacts {
        type = "NO_ARTIFACTS"
    }

    environment {
        compute_type                = var.compute_type
        image                       = var.image
        type                        = var.environment_type
        image_pull_credentials_type = "CODEBUILD"
        privileged_mode             = var.privileged_mode

    }


    source {
        
        type      = "CODECOMMIT"
        location  = "my_codecommit_repo"
        buildspec = var.buildspec

    }
    
}

My issue is it fails every time I run the build. Terraform Plan passes all the checks but the apply just errors out. I have no insight into what may be wrong with the syntax but I am hoping i am just missing something simple that will pass the build.

2
  • My best guess is that the service role is missing permissions. CodeBuild should also have GitPull permission even though it is not strictly related to AWS. Commented Mar 7, 2022 at 7:14
  • Could you add the error to the question above as well? Commented Mar 7, 2022 at 7:24

1 Answer 1

1

I am providing the current updated configurations that were used to address this issue.

resource "aws_codebuild_project" "cb_test_project" {
    name            = var.cb_name
    description     = var.description
    build_timeout   = var.build_timeout
    service_role    = var.cb_service_role


    artifacts {
        type = "NO_ARTIFACTS"
    }

    environment {
        compute_type                = var.compute_type
        image                       = var.image
        type                        = var.environment_type
        image_pull_credentials_type = "CODEBUILD"
        privileged_mode             = var.privileged_mode

    }


    source {
        
        type            = "CODECOMMIT"
        buildspec       = var.buildspec
        location        = "https://git-codecommit.us-east-1.amazonaws.com/v1/repos/[repo_name]" #MUST BE THE HTTPS URL!!
        git_clone_depth = 0


    }
    
}

As you can see, I had misconfigured the resource and misused other variables. Please visit GitHub to see a filled-out sample of this.

  1. Note you need a Service Role with extensive permissions for this to work
  2. Source Location MUST BE the Codecommit HTTPS URL the ssh URL will not work for this. Also, please remove the brackets from the URL they are just there as a placeholder for your repo name.
  3. Review the properties so you can understand the values for each one.
Sign up to request clarification or add additional context in comments.

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.