github - 如何避免 Github repo URL 中的双斜杠?

标签 github terraform terraform-provider-aws

我正在尝试使用标签过滤器创建 AWS Codepipeline webhook,并根据 Terraform docs 通过 terraform 将其插入现有存储库 webhook
我使用过的代码:

resource "aws_codepipeline_webhook" "pprod_webhook" {
  name            = "${var.client_code}-${var.environment}-pprod-hook"
  authentication  = "GITHUB_HMAC"
  target_action   = "Source"
  target_pipeline = aws_codepipeline.cd.name

  authentication_configuration {
    secret_token = data.aws_ssm_parameter.github_token.value
  }

  filter {
    json_path    = "$.ref_type"
    match_equals = "tag"
  }
}

resource "github_repository_webhook" "github_hook" {
  repository = "org_name/repo_name"

  configuration {
    url          = aws_codepipeline_webhook.pprod_webhook.url
    content_type = "json"
    insecure_ssl = false
    secret       = data.aws_ssm_parameter.webhook_secret.value
  }

  active = true
  events = ["create"]
}
编辑 terraform plan :
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place

Terraform will perform the following actions:

 # module.codepipeline.github_repository_webhook.github_hook will be created
  + resource "github_repository_webhook" "github_hook" {
      + active     = true
      + etag       = (known after apply)
      + events     = [
          + "create",
        ]
      + id         = (known after apply)
      + repository = "org_name/repo_name"
      + url        = (known after apply)

      + configuration {
          + content_type = "json"
          + insecure_ssl = false
          + secret       = (sensitive value)
          + url          = (sensitive value)
        }
    }
编辑 gh_url terraform 的输出:我得到了 Github 中的有效载荷 url。似乎我不必创建 Github webhook,因为一个已经到位,但不知道是否仅创建过滤器将允许我仅从标签触发管道
不幸的是我收到错误:

Error: POST https://api.github.com/repos//org_name/repo_name/hooks: 404 Not Found []


不知道为什么我会收到 //在上面的网址中。有没有人知道如何使这项工作?

最佳答案

您缺少配置 github 提供程序

provider "github" {
  token = "secret"
  owner = "owner"
}
同样对于存储库,您只需指定项目
resource "github_repository_webhook" "github_hook" {
  repository = "repo_name"
...
}

关于github - 如何避免 Github repo URL 中的双斜杠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65147393/

相关文章:

github - 我无法从计算机访问我的要点,而我可以从我的 Android 手机应用程序访问

git - 如何使用 Github Actions 查看最新提交?

git - 将 GitHub 与 MATLAB R2014b 结合使用

amazon-web-services - 如何使用 local_file 资源将由 Terraform 中的 tls_private_key 资源创建的 pem 文件保存到磁盘?

terraform 将输出保存到文件

git - 重复 `ssh-agent` 和 `ssh-add` 访问私有(private)存储库

terraform - 无服务器框架 CORS 无法部署到 AWS CloudFormation

amazon-web-services - 生成非 Terraform 创建的资源列表的最佳方法

amazon-web-services - 如何在 Terraform 子文件夹中声明托管资源

amazon-web-services - 使用 terraform 创建 IAM 角色并将其附加到 EC2