GitHub Terraform

GitHub Terraform

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.
Profile Settings
Profile Settings
  • Under Account settings click on Developer settings.
Account Settings
Account Settings

 

Developer Settings
Developer Settings
  • Under Developer Settings, click on Personal access tokens.
Personal Access Tokens
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
Personal Access Token Settings
Personal Access Token Settings

 

Generate Token button
Generate Token button

Kindly copy the generated token and store it in a secured place (for example, Hashicorp Vault).

Generated Token
Generated Token

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.

GitHub Repository
GitHub Repository

Leave a Reply

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