【问题标题】:Cannot get source from artifact AWS CodeBuild in Terraform无法从 Terraform 中的工件 AWS CodeBuild 获取源代码
【发布时间】:2018-09-08 08:56:18
【问题描述】:

我需要使用 terraform 创建一个带有构建步骤的管道。我需要从工件中获取源代码,但 Terraform 文档不是很清楚。到目前为止,这是我的代码:

resource "aws_codebuild_project" "authorization" {
  name         = "authorization"
  description  = "BuildProject for authrorization service"
  build_timeout      = "5"
  service_role = "${aws_iam_role.codebuild_role.arn}"

  artifacts {
    type = "CODEPIPELINE"
  }

  environment {
    compute_type = "BUILD_GENERAL1_SMALL"
    image        = "aws/codebuild/docker:17.09.0"
    type         = "LINUX_CONTAINER"
    privileged_mode = true

    environment_variable {
      "name"  = "SOME_KEY1"
      "value" = "SOME_VALUE1"
    }

    environment_variable {
      "name"  = "SOME_KEY2"
      "value" = "SOME_VALUE2"
    }
  }


  source {
    type = "CODEPIPELINE"
    buildspec = "buildspecs.yml"
  }

  tags {
    "Environment" = "alpha"
  }
}

问题是在该步骤的管道执行期间指向文件会导致我出现此错误:

DOWNLOAD_SOURCE Failed 
[Container] 2018/03/29 11:15:31 Waiting for agent ping 
[Container] 2018/03/29 11:15:31 Waiting for DOWNLOAD_SOURCE
Message: Access Denied

这是我的管道的样子:

resource "aws_codepipeline" "foo" {
  name     = "tf-test-pipeline"
  role_arn = "${aws_iam_role.codepipeline_role.arn}"

  artifact_store {
    location = "${aws_s3_bucket.foo.bucket}"
    type     = "S3"
    encryption_key {
      id   = "${aws_kms_key.a.arn}"
      type = "KMS"
    }
  }

  stage {
    name = "Source"

    action {
      name             = "Source"
      category         = "Source"
      owner            = "AWS"
      provider         = "CodeCommit"
      version         = "1"
      output_artifacts = ["src"]

      configuration {
        RepositoryName = "authorization"
        BranchName = "master"
      }
    }
  }

  stage {
    name = "Build"

    action {
      name            = "Build"
      category        = "Build"
      owner           = "AWS"
      provider        = "CodeBuild"
      input_artifacts = ["src"]
      version         = "1"

      configuration {
        ProjectName = "${aws_codebuild_project.authorization.name}"
      }
    }
  }
}

我想我做错了什么,但我似乎无法在某处找到描述我的案例。 Source 需要从 CodePipeline 中的 Source 步骤接收,这一步是可以的。我知道管道是如何工作的,但是 terraform 的实现非常混乱。 编辑:我已经检查了 S3 存储桶,并且可以确认 Source 步骤已成功将工件上传到那里。所以问题仍然存在,当我在第二步时,我无法访问源代码。角色是允许对所有资源的所有访问。管道的控制台版本看起来很正常,没有任何内容未填充。角色很好。

【问题讨论】:

    标签: amazon-web-services terraform aws-codepipeline aws-codebuild terraform-provider-aws


    【解决方案1】:

    当您已经拥有 CodeBuild 项目并将其集成到 CodePipeline 项目时,通常会发生这种情况。 Codebuild 现在不会从 CodeCommit/Github 存储库下载源代码。相反,它将尝试下载在 S3 的 codepipeline 存储桶中创建的源工件。因此,您需要向 CodeBuild 角色提供访问 S3 中的 codepipline 存储桶的权限。

    【讨论】:

    • CodeBuild 和 CodeCommit 角色具有完全的管理员访问权限。还是一样的错误。
    • 构建和管道都是使用相同的脚本创建的,我需要它来从 s3 获取工件。
    • 我也有同样的问题。你有没有得到解决方案@Nephilimrising?谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 2018-07-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多