Terraform: aws_codebuild_project with Github OAuth EOF error

Created on 27 Feb 2017  ยท  14Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.8.7

Affected Resource

aws_codebuild_project

Terraform Configuration Files

resource "aws_codebuild_project" "my_codebuild_project" {
  name         = "my_codebuild_project"
  description  = "my_codebuild_project"
  timeout      = "5"
  service_role = "${aws_iam_role.codebuild_role.arn}"
  # encryption_key =

  source {
    type     = "GITHUB"
    location = "https://github.com/myorg/myurl"

    auth { # HERE IS THE BLOCK IN QUESTION
      type = "OAUTH"
      resource = "AWS CodeBuild" # This line is confusing, see issue #2 mentioned at the bottom. I've tried removing this line and various other strings
    }
  }

  environment {
    compute_type = "BUILD_GENERAL1_SMALL"
    image        = "aws/codebuild/python:3.5.2"
    type         = "LINUX_CONTAINER"
  }

  artifacts {
    type = "S3"
    location = "someplace"
    namespace_type = "BUILD_ID"
    packaging = "NONE"
  }
}

Panic Output

```Error applying plan:

1 error(s) occurred:

  • aws_codebuild_project.my_codebuild_project: unexpected EOF

### Expected Behavior
Successfully create aws_codebuild_project resource with Github OAuth connection and no errors.

### Actual Behavior
When applying a "aws_codebuild_project" resource with a Github source, I'm able to successfully create a codebuild project if I do NOT include the "auth" block within the "source" block.

However, when attempting to "Start build" in AWS; the project is unable to pull from github. It seems that the "auth" block is required for a codebuild > Github connection.

I added the "auth" block to the "source" block and then received this error when attempting to apply:
```Error applying plan:

1 error(s) occurred:

* aws_codebuild_project.my_codebuild_project: unexpected EOF

Terraform creates the codebuild project in AWS but fails with the error above. However, the codebuild project created DOES run a completely successful build and pull from Github. Because of the error, terraform does not recognize the project's existence in AWS and tries to create it again at the next terraform apply: "+ aws_codebuild_project.my_codebuild_project". Of course, then I receive an error that a duplicate resource exist.

Steps to Reproduce

  1. terraform apply

Important Factoids

Please note that I have already setup the Github OAuth connection and am able to use it if I edit the existing project resource in the UI.

I have two issues here:

  1. I cannot figure out why I receive an "unexpected EOF" error when enabling the "auth" block within the "source" block.
    IF this has to do with the "resource" being required in terraform, I should receive an error stating that; not an EOF error.
  2. I cannot find any documentation that gives an example of what the aws_codebuild_project > source > auth > resource variable should be. All I can find is: "(Required) The resource value that applies to the specified authorization type." This is extremely vague, and I haven't been able to find any examples or AWS documentation other than this one phrase. AWS documentation says that "resource" is (optional), but terraform documentation says it's (required).
bug provideaws

Most helpful comment

I'm having this same issue. Was this ever fixed?

All 14 comments

  1. I think this is the same problem I fixed in #11741 , so it should work of the 0-8-stable branch or the next release.
  1. I managed to get it to work (after the above fix) with having manually connected aws with github previously (via the web ui) and after that applying with
auth {
      type = "OAUTH"
}

I have not been able to dive deeper in to this, but I do not consider this solution neat.

@comebackoneyear you think this is solved in 0.8.8?

The crash is fixed, not sure if there is any changes in the documentation clarifying the second question.

@comebackoneyear you think it's worth just linking to the AWS documentation for that specific answer?

@stack72 For now. They aren't precisely clear on this either (from what I remember). But I can update the docs once I understand it better.

k let's close this out for now then :) Thanks for getting back to me so fast

I'm having this same issue. Was this ever fixed?

The EOF error was fixed but the resource still doesn't seem to support authenticating with Github via a token like aws_codepipeline does and thus breaks automation. It looks like AWS don't support this via API as CLI page says

Also, you must connect your AWS account to your GitHub account. To do this, use the AWS CodeBuild console to begin creating a build project
http://docs.aws.amazon.com/cli/latest/reference/codebuild/create-project.html

@comebackoneyear @jurajseffer What version was this fixed in? I'm running TF 0.11.2 and AWS provider 1.8.0 and I'm hitting this error even with my account already authorized via github.

Trying to create a new codebuild resource, If I create it with NO auth block it will work. With an Auth block it will blow up. If I then go into the codedeploy resource manually and connect it to my github repo, it will crash terraform again.

@brianbianco I don't know about the version but I found what you did - have to have no auth block when creating new CodeBuild, then manually connect Github and put the block in when updating it. What I meant was that the error it shows when one uses auth block is different from what I remember, not EOF.

@jurajseffer So I did this an it still blows up for me. Maybe I have the ordering slightly wrong. I think if inbetween adding the auth block and making the manual changes you run terraform it will crash, and basically be hosed forever.

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

c4milo picture c4milo  ยท  3Comments

thebenwaters picture thebenwaters  ยท  3Comments

pawelsawicz picture pawelsawicz  ยท  3Comments

rjinski picture rjinski  ยท  3Comments

franklinwise picture franklinwise  ยท  3Comments