使用 AWS 提供商的 Terraform 无法创建 CodeBuild
Terraform with AWS provider unable to create CodeBuild
我正在尝试使用 Terraform 创建 AWS CodeBuild。
resource "aws_codebuild_project" "cicd_codebuild" {
name = "cicd-${var.profile}-build"
description = "cicd ${var.profile} CodeBuild"
service_role = "${aws_iam_role.cicd_role.arn}"
source {
type = "GITHUB_ENTERPRISE"
location = "https://git.xxx.com/yyy/zzz.git"
git_clone_depth = 0
buildspec = "NO_SOURCE"
}
environment {
compute_type = "BUILD_GENERAL1_MEDIUM"
image = "aws/codebuild/windows-base:2019-1.0"
type = "WINDOWS_SERVER_2019_CONTAINER"
image_pull_credentials_type = "CODEBUILD"
}
artifacts {
type = "NO_ARTIFACTS"
}
}
terraform apply
我得到错误:
Error: aws_codebuild_project.cicd_codebuild: expected environment.0.type to be one of [LINUX_CONTAINER LINUX_GPU_CONTAINER WINDOWS_CONTAINER ARM_CONTAINER], got WINDOWS_SERVER_2019_CONTAINER
当我更改 environment.0.type = "WINDOWS_CONTAINER"
的值时,出现以下错误:
Error: Error applying plan:
1 error occurred:
* aws_codebuild_project.cicd_codebuild: 1 error occurred:
* aws_codebuild_project.cicd_codebuild: Error creating CodeBuild project: InvalidInputException: The environment type WINDOWS_CONTAINER is deprecated for new projects or existing project environment updates. Please consider using Windows Server 2019 instead.
我在 GitHub 上发现 this 问题已在下一版本中得到解决。所以,我知道升级提供程序版本可以解决这个问题,但是我们有没有任何解决方法可以在相同版本的 Terraform 和提供程序中解决这个问题。
谢谢。
Terraform 对许多资源参数进行了计划时间验证,允许在您尝试应用它之前捕获您传递无效参数的位置。
通常这是有益的,但如果您无法与提供者版本保持同步,则意味着允许值列表可能会与提供者正在谈论的支持服务实际允许的值过时到.
在此特定情况下 a pull request added the WINDOWS_SERVER_2019_CONTAINER
as a plan time validation option after AWS added that functionality in July 2020。
很遗憾,这项工作已合并并作为 v3.20.0 release of the AWS provider and the v3 releases only support Terraform 0.12 and up 的一部分发布:
BREAKING CHANGES
- provider: New versions of the provider can only be automatically installed on Terraform 0.12 and later (#14143)
如果您希望能够在 CodeBuild 中使用 Windows 容器,您需要升级到更新版本的 Terraform 和 AWS 提供商,或者您需要使用不同的工具来创建 CodeBuild 项目.
此处可能的解决方法是使用 CloudFormation to create the CodeBuild project which you could run via Terraform using the aws_cloudformation_stack
resource.
我正在尝试使用 Terraform 创建 AWS CodeBuild。
resource "aws_codebuild_project" "cicd_codebuild" {
name = "cicd-${var.profile}-build"
description = "cicd ${var.profile} CodeBuild"
service_role = "${aws_iam_role.cicd_role.arn}"
source {
type = "GITHUB_ENTERPRISE"
location = "https://git.xxx.com/yyy/zzz.git"
git_clone_depth = 0
buildspec = "NO_SOURCE"
}
environment {
compute_type = "BUILD_GENERAL1_MEDIUM"
image = "aws/codebuild/windows-base:2019-1.0"
type = "WINDOWS_SERVER_2019_CONTAINER"
image_pull_credentials_type = "CODEBUILD"
}
artifacts {
type = "NO_ARTIFACTS"
}
}
terraform apply
我得到错误:
Error: aws_codebuild_project.cicd_codebuild: expected environment.0.type to be one of [LINUX_CONTAINER LINUX_GPU_CONTAINER WINDOWS_CONTAINER ARM_CONTAINER], got WINDOWS_SERVER_2019_CONTAINER
当我更改 environment.0.type = "WINDOWS_CONTAINER"
的值时,出现以下错误:
Error: Error applying plan:
1 error occurred:
* aws_codebuild_project.cicd_codebuild: 1 error occurred:
* aws_codebuild_project.cicd_codebuild: Error creating CodeBuild project: InvalidInputException: The environment type WINDOWS_CONTAINER is deprecated for new projects or existing project environment updates. Please consider using Windows Server 2019 instead.
我在 GitHub 上发现 this 问题已在下一版本中得到解决。所以,我知道升级提供程序版本可以解决这个问题,但是我们有没有任何解决方法可以在相同版本的 Terraform 和提供程序中解决这个问题。
谢谢。
Terraform 对许多资源参数进行了计划时间验证,允许在您尝试应用它之前捕获您传递无效参数的位置。
通常这是有益的,但如果您无法与提供者版本保持同步,则意味着允许值列表可能会与提供者正在谈论的支持服务实际允许的值过时到.
在此特定情况下 a pull request added the WINDOWS_SERVER_2019_CONTAINER
as a plan time validation option after AWS added that functionality in July 2020。
很遗憾,这项工作已合并并作为 v3.20.0 release of the AWS provider and the v3 releases only support Terraform 0.12 and up 的一部分发布:
BREAKING CHANGES
- provider: New versions of the provider can only be automatically installed on Terraform 0.12 and later (#14143)
如果您希望能够在 CodeBuild 中使用 Windows 容器,您需要升级到更新版本的 Terraform 和 AWS 提供商,或者您需要使用不同的工具来创建 CodeBuild 项目.
此处可能的解决方法是使用 CloudFormation to create the CodeBuild project which you could run via Terraform using the aws_cloudformation_stack
resource.