成员必须有长度 - 使用 terraform 的 AWS Codepipeline 错误

Member must have length- AWS Codepipeline error using terraform

我在 Terraform 中有一个包含两个阶段的 aws_codepipeline 资源。第二个是使用 ECS 的部署:

resource "aws_codepipeline" "codepipeline" {
  name     = "my-codepipeline"
  role_arn = "my_arn"

  artifact_store {
    location = "codepipeline-eu-west-1-xxxx"
    type     = "S3"
  }

  stage {
    name = "Source"

    action {
      name             = "Source"
      category         = "Source"
      owner            = "ThirdParty"
      provider         = "GitHub"
      version          = "1"
      output_artifacts = ["my_artifact"]

      configuration = {
        Owner  = "Myself"
        Repo   = "myRepo"
        Branch = "Master"
        OAuthToken = ""
      }
    }
  }

  stage {
      name = "Deploy"

      action {
        name            = "Deploy"
        category        = "Deploy"
        owner           = "AWS"
        provider        = "ECS"
        input_artifacts = ["my_artifact"]
        version         = "1"
        configuration = {
          ClusterName = "my-cluster"
          ServiceName = "my-service"
        }
      }
    }
}

错误是:

Error: Error creating CodePipeline: ValidationException: 1 validation error detected: Value at 'pipeline.stages.1.member.actions.1.member.configuration' failed to satisfy constraint: Map value must satisfy constraint: [Member must have length less than or equal to 1000, Member must have length greater than or equal to 1]

我认为这个错误与设置的配置有关,但我在 Terraform 文档中找不到,Google 也没有发现任何与此相关的问题。

我遇到了同样的错误,问题是我为提供商定义的配置数据 syntax/format。

在这种情况下,我的提供商是 CodeBuild,它希望在其配置中使用 heredoc 语法获取传入的一些环境变量。最初,我有这个:

      run_order = 1
      role_arn = ""
      category = "Build"
      owner = "AWS"
      provider = "CodeBuild"
      version = "1"
      configuration = {
        ProjectName = var.codebuild_build_release_project_image.name
        EnvironmentVariables = <<JSON
[
  {
    "name": "REPO_CONNECTION",
    "value": "repo_connection",
    "type": "SECRETS_MANAGER"
  },
 (etc etc)

错误原因是什么?我将 Json 配置向右缩进了大约 10 个空格,这样看起来会更好。只是左括号和右括号,以及里面包含的内容。

这样做会导致错误,而撤消它会修复错误。重做它再次导致错误。即使我有其他部分缩进并且工作正常。现在,我只能将其归结为 terraform 和 heredoc 的“敏感性问题”。

所以,虽然我没有遇到与您完全相同的情况,但也许这会有所启发。

我的问题是我的示例秘密 vars 文件不小心被调用了:

"vars.secret.example.auto.tfvars" 值为:

github_token="" 在里面。

因为它最后仍然有“auto.tfvars”,所以它正在读取它并把事情搞砸并覆盖我相信的实际配置值。更改文件名以删除“auto”就可以了。