Creating a GitHub repository using Terraform involves several steps. Before you begin, make sure you have the following


  1. GitHub Account: You must have a GitHub account.
  2. GitHub Personal Access Token: Create a personal access token on GitHub. This token is used by Terraform to authenticate with GitHub.
  3. Terraform: You must have Terraform installed on your local machine.

After you have the above prerequisites, follow the steps below:

1. Setup Terraform Configuration File:
Create a file named and add the following content to it.

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

# Configure the GitHub Provider
provider "github" {
        Token = "Please place your token here"

resource "github_repository" "rushi123" {
  name        = "Git"
  description = "My awesome codebase"

  visibility = "public"


In this configuration file, we define a github provider and a github_repository resource. We use variables for the GitHub personal access token, organization name, repository name, description.

2. Create Variables File:
Create a file named terraform.tfvars and add the following content to it. github_token = “your_github_token” organization = “your_organization_name” repository_name = “your_repository_name” description = “your_repository_description” private = false Replace the placeholders with your actual values.

3. Initialize Terraform:
Run the following command to initialize your Terraform configuration.

terraform init

4. Create GitHub Repository:
Run the following command to create the GitHub repository. "terraform apply” Terraform will display the changes to be made and prompt you for confirmation. Type yes to proceed.

5. Verify GitHub Repository:
After the terraform apply command completes, you should see the URL of the created repository in the output. Visit this URL to verify that the repository was created successfully.

Here is the repository which you created through terraform.

That’s it! You have created a GitHub repository using Terraform.

Note: To destroy the created resources, you can run terraform destroy and type yes at the confirmation prompt.

Successfully, you have destroyed the repository.

Similar Posts

Leave a Reply

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