You are on page 1of 4

4/13/22, 12:08 PM amazon web services - Terraform resource github_repository_webhook requires GitHub organization to be set on the provider - …

Terraform resource github_repository_webhook requires GitHub


organization to be set on the provider
Asked
1 year, 11 months ago Modified
1 year, 11 months ago Viewed
1k times

I am Making a CI/CD pipeline with terraform AWS. This pipeline works 100 percent perfect if I
don't configure webhooks rather than goes with default option i.e AWS CodePipeline which
1 periodically checks for changes in github.

When I configure webhooks for my pipeline to make it start automatically on every push. I am
getting below error which is at the end after the code. I understand one solution that is "if I make
1 an organization and set individual=false in my providers settings" it will work.

But I don't want to make an organization rather wants to work with individual = true. Is there any
way by which I can solve this problem?

P.S: I added only those files in this question which are related to my problem. If you want me to
add my whole code please request revision

Filename: Provider.tf

provider "aws" {

region = var.aws_region

version = "2.55"

provider "github" {

token = var.github_token

individual = true

terraform {

backend "s3" {

key = "ecs_fargate/infrastructure.tfstate"

bucket = "umartahir-terraform-buckettestus-east-1"

region = "us-east-1"

Filename: Codepipeline.tf

#Code Pipeline

resource "aws_codepipeline" "codepipeline" {

name = var.pipeline_name

role_arn
Join Stack Overflow= to
aws_iam_role.codepipeline_role.arn

find the best answer to your technical question, help others


Sign up
answer theirs.
artifact_store {

https://stackoverflow.com/questions/61214656/terraform-resource-github-repository-webhook-requires-github-organization-to-be 1/4
4/13/22, 12:08 PM amazon web services - Terraform resource github_repository_webhook requires GitHub organization to be set on the provider - …
location = var.bucket_for_codepipeline

type = var.artifact_store_type

stage {

name = "Source"

action {

name = "Source"

category = "Source"

owner = var.source_stage_owner

provider = var.source_stage_provider

version = "1"

output_artifacts = var.source_stage_output_artifact_name

configuration = {

PollForSourceChanges = false

OAuthToken = var.github_token

Owner = var.git_hub_owner

Repo = var.repo_name

Branch = var.branch_name

stage {

name = "Build"

action {

name = "Build"

category = "Build"

owner = "AWS"

provider = "CodeBuild"

input_artifacts = var.source_stage_output_artifact_name

output_artifacts = ["build_output"]

version = "1"

configuration = {

ProjectName = aws_codebuild_project.code_build_stage_pipeline.name

# See this in detail later

# A shared secret between GitHub and AWS that allows AWS

# CodePipeline to authenticate the request came from GitHub.

# Would probably be better to pull this from the environment

# or something like SSM Parameter Store.

locals {

webhook_secret = "super-secret"

resource "aws_codepipeline_webhook" "github_hook" {

name = var.github_hook_name

authentication = "GITHUB_HMAC"

target_action = "Source"

target_pipeline = aws_codepipeline.codepipeline.name

Join Stack Overflow to find the best answer to your technical question, help others
Sign up
answer theirs.

https://stackoverflow.com/questions/61214656/terraform-resource-github-repository-webhook-requires-github-organization-to-be 2/4
4/13/22, 12:08 PM amazon web services - Terraform resource github_repository_webhook requires GitHub organization to be set on the provider - …
authentication_configuration {

secret_token = "${local.webhook_secret}"

filter {

json_path = "$.ref"

match_equals = "refs/heads/{Branch}" #see this later

# # See this in detail later

# # Wire the CodePipeline webhook into a GitHub repository.

resource "github_repository_webhook" "web_hook_github" {

repository = var.repo_name

configuration {

url = aws_codepipeline_webhook.github_hook.url

content_type = "json"

insecure_ssl = true

secret = local.webhook_secret

events = ["push"]

Logs:

aws_iam_role.example: Creating...

aws_iam_role.codepipeline_role: Creating...

aws_iam_role.codepipeline_role: Creation complete after 3s [id=test-role]

aws_iam_role_policy.codepipeline_policy: Creating...

aws_iam_role.example: Creation complete after 3s [id=example]

aws_iam_role_policy.example: Creating...

aws_codebuild_project.code_build_stage_pipeline: Creating...

aws_iam_role_policy.example: Creation complete after 4s [id=example:terraform-


20200414180138343300000001]

aws_iam_role_policy.codepipeline_policy: Creation complete after 4s [id=test-


role:codepipeline_policy]

aws_codebuild_project.code_build_stage_pipeline: Creation complete after 9s


[id=arn:aws:codebuild:us-east-1:359761372359:project/umartahir-terraform-codebuild]

aws_codepipeline.codepipeline: Creating...

aws_codepipeline.codepipeline: Creation complete after 7s [id=umar-tahir-terraform-


codepipeline]

aws_codepipeline_webhook.github_hook: Creating...

aws_codepipeline_webhook.github_hook: Creation complete after 4s


[id=arn:aws:codepipeline:us-east-1:359761372359:webhook:webhook-github-codepipeline]

github_repository_webhook.web_hook_github: Creating...

Error: This resource requires GitHub organization to be set on the provider.

on codepipeline.tf line 87, in resource "github_repository_webhook"


"web_hook_github":

87: resource "github_repository_webhook" "web_hook_github"

amazon-web-services terraform webhooks terraform-provider-aws iaas

ShareOverflow
Join Stack Follow to find the best answer toedited
yourApr 14, 2020question,
technical at 18:44 help others
asked Apr 14, 2020 at 18:26
Sign up
answer theirs. Umar Tahir

https://stackoverflow.com/questions/61214656/terraform-resource-github-repository-webhook-requires-github-organization-to-be 3/4
4/13/22, 12:08 PM amazon web services - Terraform resource github_repository_webhook requires GitHub organization to be set on the provider - …

536 4 19

Sorted by:
1 Answer
Highest score (default)

seems to be an existing issue.


Here is a link to the thread - https://github.com/terraform-
providers/terraform-provider-github/issues/45
1
Share Follow answered Apr 20, 2020 at 16:16
Ritesh Kumar Reddy
Kuchukulla
194 10

Join Stack Overflow to find the best answer to your technical question, help others
Sign up
answer theirs.

https://stackoverflow.com/questions/61214656/terraform-resource-github-repository-webhook-requires-github-organization-to-be 4/4

You might also like