DEV Community

Cover image for Terraform code to Create Github Repository
Surya Shankar
Surya Shankar

Posted on • Updated on

Terraform code to Create Github Repository

Create a new manifest called github.tf in the directory, and paste that into there:

Copy the use provider code to create your first block

terraform {
required_providers {
github = {
source = "integrations/github"
version = "4.30.0"
}
}
}

provider "github" {
# Configuration options
}

Image description

Under authenticate in https://registry.terraform.io/providers/integrations/github/latest/docs,
you see that a token is required. Generate a token in your github accoundt under the developer settings within settings . When creating the token, select the operations for repo and
delete_repo.

Image description

- Navigate to github_repository in the documentation and copy the example usage into your VS Code, You can remove the template and description part since they are optional, change the
visibility to public/private and name it as terraform repo

Image description

Run Following Commands
$ terraform init
- Download Providers & Modules

Image description
$ terraform validate
- Validate .tf profile
$ terraform plan
- DRY RUN

Image description

$ terraform apply
- Create a resources &&& store a resonse IN STATE file(json)

Image description

Image description

Now go to your github and you can see your repo

Image description

Latest comments (0)