Terraform for AWS Code Build problem - can't figure out how to configure Github Token

I’m having trouble getting terraform to properly generate an AWS CodeBuild project using github enterprise with a github token.

Here is my terraform:

resource "aws_codebuild_source_credential" "ghe_token" {
  auth_type = "PERSONAL_ACCESS_TOKEN"
  server_type = "GITHUB_ENTERPRISE"
  token = "mytokengoeshere"
}

resource "aws_codebuild_project" "ami-project" {
  name = "packer-ami-factory"
  description = "automation for building AMIs"
  service_role = "blahblah/service-role/codebuild-base--service-role"
  artifacts {
    type = "NO_ARTIFACTS"
  }

  environment {
    compute_type = "BUILD_GENERAL1_SMALL"
    image = "myecrimage/ami-build:0.1"
    type = "LINUX_CONTAINER"
    image_pull_credentials_type = "CODEBUILD"
  }

  logs_config {
    cloudwatch_logs {
      group_name = "ami-factory-base-codebuild"
      stream_name = "logs"
    }
  }

  source {
    type = "GITHUB_ENTERPRISE"
    location = "https://myenterprisegithub/Cloud-Services/cc-packer"
    git_clone_depth = 1
  }

  vpc_config {
    vpc_id = "vpc-blahblah"
    subnets = [
      "subnet-blahblah"
    ]
    security_group_ids = [
      "sg-blahblah"
    ]
  }
}

I get this error

CLIENT_ERROR: Get https://myenterprisegithub/IS-Cloud-Services/cc-packer/info/refs?service=git-upload-pack: dial tcp: lookup github.myco.net on 10.14.3.2:53: no such host for primary source and source version automation

The doc is on codebuild credential is here: https://www.terraform.io/docs/providers/aws/r/codebuild_source_credential.html

It doesn’t have a full example so I’m unclear on if the above is correct or how to reference the github token from source

Any help would be appreciated.

Thanks!

1 Like