In this post, we are going to see about the steps achieve GitHub as a Code using Terraform CLI and Terraform Cloud.
We are going to use GitHub provider in Terraform Registry to create a GitHub repository.
Using Terraform CLI:
Step 1 : Write the code
Kindly create a file with using any of the file editor (say vi, nano gedit, etc.,) and enter the below contents and save the file with a name (In our case, provider.tf & github_repo.tf)
Step 2 : Create Personal Access Token (PAT) in GitHub Settings
- Kindly click on the profile photo in the upper-right corner of GitHub page. Then click on Settings.
- Under Account settings click on Developer settings.
- Under Developer Settings, click on Personal access tokens.
- Kindly click on Generate new token to create a new token. New personal access token screen will appear.
- Kindly enter the below details & then click on Generate Token button
- Note: tf-githubasacode
- Expiration: 30 days
- Select Scopes: Select the repo checkbox
Kindly copy the generated token and store it in a secured place (for example, Hashicorp Vault).
Step 3: Terraform Execution
Kindly execute the below command to save the Personal Access Token as environment variable as a security best practice.
Now Kindly execute the below commands to create a repository in GitHub.