gpt4 book ai didi

terraform - 如何在 Terraform 中使用代码管道设置代码构建?

转载 作者:行者123 更新时间:2023-12-02 16:48:13 28 4
gpt4 key购买 nike

我正在尝试设置代码构建以使用 Terraform 从代码管道接收工件。 terraform 文件中 codebuild 资源的相关部分如下所示:

  source {
type = "CODEPIPELINE"
git_clone_depth = 1
}

运行 terraform apply 时出现错误错误是:

Error: Error creating CodeBuild project: InvalidInputException: Invalid input: when using CodePipeline both sourceType, and artifactType must be set to: CODEPIPELINE status code: 400, request id: 2c32335e-d3c1-4abd-823b-83e26b947c77

terraform 文档中没有关于 sourceType 和 arifactType 的任何内容...如何构建一个设置代码以使用 terraform 从代码管道接收工件?谢谢!

最佳答案

此错误与构建输出工件定义相关:[1]

要解决此问题,请为 TF 资源上的“源”和“工件”属性定义 type = 'CODEPIPELINE':aws_codebuild_project:

来自 https://www.terraform.io/docs/providers/aws/r/codebuild_project.html#artifacts :

source supports the following:

type - (Required) The type of repository that contains the source code to be built. Valid values for this parameter are: CODECOMMIT, CODEPIPELINE, GITHUB, GITHUB_ENTERPRISE, BITBUCKET, S3 or NO_SOURCE.

artifacts supports the following:

type - (Required) The build output artifact's type. Valid values for this parameter are: CODEPIPELINE, NO_ARTIFACTS or S3.

如果您仍然遇到问题,请分享您的 TF 模板。

引用:

[1] https://docs.aws.amazon.com/codebuild/latest/APIReference/API_ProjectArtifacts.html

编辑 1:

我复制了您的模板并应用了它,它运行起来没有任何问题。唯一改变的是存储桶名称和项目名称:

resource "aws_s3_bucket" "example" {
bucket = "shariqexampletestingterrastartup" # <======

resource "aws_codebuild_project" "example" {
name = "terraform-cb-project" #var.DOMAIN_NAME # <======

Terraform 应用的响应:

Plan: 5 to add, 0 to change, 0 to destroy.

Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.

Enter a value: yes

aws_iam_role.example: Creating...
aws_iam_policy.policy: Creating...
aws_s3_bucket.example: Creating...
aws_iam_role.example: Creation complete after 2s [id=example]
aws_iam_policy.policy: Creation complete after 3s [id=arn:aws:iam::123456789012:policy/test-policy]
aws_iam_role_policy_attachment.test-attach: Creating...
aws_iam_role_policy_attachment.test-attach: Creation complete after 2s [id=example-20200113052522878300000001]
aws_s3_bucket.example: Still creating... [10s elapsed]
aws_s3_bucket.example: Creation complete after 15s [id=shariqexampletestingterrastartup]
aws_codebuild_project.example: Creating...
aws_codebuild_project.example: Creation complete after 3s [id=arn:aws:codebuild:us-east-1:123456789012:project/terraform-cb-project]

供引用,我的TF版本如下:

terraform --version
Terraform v0.12.10
+ provider.aws v2.44.0

Your version of Terraform is out of date! The latest version
is 0.12.19. You can update by downloading from www.terraform.io/downloads.html

关于terraform - 如何在 Terraform 中使用代码管道设置代码构建?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59700078/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com