integrations / terraform-provider-github

Terraform GitHub provider
https://www.terraform.io/docs/providers/github/
MIT License
888 stars 729 forks source link

[BUG]: Error: unexpected status code: 404 Not Found when utilizing a local module #2066

Open otola opened 9 months ago

otola commented 9 months ago

Expected Behavior

The github_repository_file should have been created within the provided organisation repository. Interesrtingly in the debug logs I can see that the organisation name isn't being sent through in the request. The owner field seems to be ignored. When creating a direct github_repository_file resource without utilising a module this works without an issue.

Actual Behavior

Error received. Error: unexpected status code: 404 Not Found

Terraform Version

1.6.6

Affected Resource(s)

Terraform Configuration Files

### Provider Config ###

terraform {
  required_providers {
    github = {
      source  = "integrations/github"
      version = "~> 5.0"
    }
  }
}

provider "github" {
  owner = "orgName"
}

### Module ###

resource "github_repository_file" "main-template" {
  repository          = var.repository
  branch              = var.branch
  file                = var.file
  content             = var.content
  commit_message      = var.commit_message
  commit_author       = var.commit_author
  commit_email        = var.commit_email
  overwrite_on_create = var.overwrite_on_create
}

module "file-to-create" {
  source = "../../../modules/github/github-file-creation"
  repository = "repoName"
  branch = main
  file = "filetocreate.txt"
  content = "test"
}

Steps to Reproduce

terraform plan

Debug Output

2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: ---[ REQUEST ]---------------------------------------
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: GET /repos/otola/repoName/branches/develop HTTP/1.1
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: Host: api.github.com
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: User-Agent: go-github/v55.0.0
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: Accept: application/vnd.github.v3+json,application/vnd.github.stone-crop-preview+json
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: X-Github-Api-Version: 2022-11-28
2023-12-19T17:23:37.612Z [DEBUG] provider.terraform-provider-github_v5.42.0: Accept-Encoding: gzip

Panic Output

No response

Code of Conduct

kfcampbell commented 8 months ago

If you're using separate modules and the org name isn't being sent, you need to follow the directions in our docs here:

You must add a required_providers block to every module that will create resources with this provider. If you do not explicitly require integrations/github in a submodule, your terraform run may break in hard-to-troubleshoot ways.