1
votes

Using terraform v0.11.11 and aws plugin v2.0.0_x4, I just started to receive an error when trying to create a Codebuild project in AWS.

The terraform section related to Codebuild is as follows:

resource "aws_codebuild_project" "codebuild-bitbucket" {
name          = "validation-SD_REPOSITORY-SD_COUNTRY-SD_ENVIRONMENT"
description   = "Validate Bitbucket Code from PR"
service_role  = "${aws_iam_role.codebuild-role.arn}"

artifacts {
    type = "S3"
    location = "${aws_s3_bucket.artifact-store.bucket}"
    packaging = "NONE"
}

environment {
    compute_type = "BUILD_GENERAL1_SMALL"
    image        = "aws/codebuild/docker:18.09.0"
    type         = "LINUX_CONTAINER"
    privileged_mode = "true"
    environment_variable {
        "name" = "ECRID"
        "value" = "${var.codebuild_docker_ecr_id}"
    }
    environment_variable {
        "name" = "ECRREGION"
        "value" = "${var.region}"
    }
}

source {
    type            = "BITBUCKET"
    buildspec = "configuration/buildspec.yml"
    location = "${var.specific_repo}"
    auth            {
        type = "OAUTH"
    }
    report_build_status = "true"
}
tags = {
  country = "${var.country_tag}"
}
}
resource "aws_codebuild_webhook" "codebuild-webhook-bitbucket" {
    project_name = "${aws_codebuild_project.codebuild-bitbucket.name}"
}

After applying an update to my Codebuild configuration, adding a new environment variable, I'm receiving the following error:

Error: Error applying plan:

1 error(s) occurred:

* aws_codebuild_webhook.codebuild-webhook-bitbucket: 1 error(s) occurred:

* aws_codebuild_webhook.codebuild-webhook-bitbucket: ValidationException: 1 validation error detected: Value '' at 'newProjectVersion.webhook.branches' failed to satisfy constraint: Member must have length greater than or equal to 1
        status code: 400, request id: 55dcfe4b-3ffe-11e9-ae77-a3b085c34d60

Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.


2019/03/06 10:55:22 [DEBUG] plugin: waiting for all plugin processes to complete...
2019-03-06T10:55:22.081Z [DEBUG] plugin.terraform-provider-aws_v2.0.0_x4: 2019/03/06 10:55:22 [ERR] plugin: plugin server: accept unix /tmp/plugin325591570: use of closed network connection
2019-03-06T10:55:22.082Z [DEBUG] plugin: plugin process exited: path=/tmp/working/.terraform/plugins/linux_amd64/terraform-provider-aws_v2.0.0_x4
make: *** [Makefile:6: apply] Error 1

Which is the issue? What can I do to solve it?

Thanks in advance.

2
Did it work previously? On what version of the AWS provider? If you roll back to that version of the AWS provider does it still work? What does the plan show before the error on the apply? - ydaetskcoR
Yes, it worked, it stopped working this week. Doing what @redec says it works. It seems to be an issue with the new branch_filter which is not optional as the documentation says right now. - Carlos Corrales

2 Answers

1
votes

I'm not sure what caused this but I started seeing this recently too, on pinned, known-working provider versions. To get it working again just add branch_filter to your webhook resource like so:

resource "aws_codebuild_webhook" "codebuild-webhook-bitbucket" {
    project_name = "${aws_codebuild_project.codebuild-bitbucket.name}"
    branch_filter = ".*"
}
1
votes

This is a bug. We are reverting the change that introduced it, which should fix this issue. Thanks for bringing it to our attention.