Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid double slash in Github repo URL?

I'm trying to create AWS Codepipeline webhook with tag filter and plug it to existing repository webhook via terraform in accordance with Terraform docs

Code which I've used:

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"]
}

EDIT 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)
        }
    }

EDIT with gh_url output from terraform: I'm getting payload url which is in Github. Seems I do not have to create Github webhook, since one is in place already, but don't know if creating filter only will allow me trigger pipeline from tags only

Unfortunately I'm getting error:

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

No idea why I'm getting // in above URL. Is there any one who knows how to make that work?

like image 920
Maciej Avatar asked Sep 11 '25 09:09

Maciej


1 Answers

You're missing configuring github provider

provider "github" {
  token = "secret"
  owner = "owner"
}

Also for the repository, you just have to specify the project

resource "github_repository_webhook" "github_hook" {
  repository = "repo_name"
...
}
like image 127
Juan Vanegas Avatar answered Sep 12 '25 23:09

Juan Vanegas