How to create repository in GitHub through Terraform?

Before Terraform steps first we have to create access in GitHub . Access in github can be granted through Personal Access Token.

How to create Personal Access Token in GitHub?

Login into Your github account.

Click settings

Click Developer Settings

Click Personal Access token – Click Generate new Token if already not created .

Enable repo in the scopes

Now save the token.

Lets create Terraform steps.

You can refer the github provider blocks in terraform site .


Click Use Provider option to copy the code. From version 0.13+ required_providers option needs to be use if its not maintained by HasiCorp.

Code structure , mandatory and optional parameters

Create github.tf file in desired folder, replace the saved token

Here used F:/demo/

terraform {
  required_providers {
    github = {
      source = "integrations/github"
      version = "4.6.0"
provider "github" {
token ="53csdfsdfsigidjgadf090i08990d0"
resource "github_repository" "example" {
  name = "terraform-mygit-repo"
  visibility = "private"
#terraform init

Before apply you can check with terraform plan

We can see here what will be the repo name and visibility status private and more.

#terraform apply

Now repo is created , you can login into github and check .

Files created within the dir


Leave a Reply

Your email address will not be published. Required fields are marked *