This is the third post in a multipart post that walks through using Terraform with a GitHub Action and OAuth2 to authenticate to Azure.
So far, I have been working without source control. That’s not too much of a problem because I only have two files in my project. But, this is supposed to be a walkthrough involving GitHub Actions, so it’s time to create the repository.
Before we initialize the repository, we need a .gitignore file. This is important because we don’t want any Terraform module binaries checked into source control.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Local .terraform directories **/.terraform/* # .tfstate files *.tfstate *.tfstate.* # Crash log files crash.log crash.*.log # Exclude all .tfvars files, which are likely to contain sensitive data, such as # password, private keys, and other secrets. These should not be part of version # control as they are data points which are potentially sensitive and subject # to change depending on the environment. *.tfvars *.tfvars.json # Ignore override files as they are usually used to override resources locally and so # are not checked in override.tf override.tf.json *_override.tf *_override.tf.json # Ignore transient lock info files created by terraform apply .terraform.tfstate.lock.info # Include override files you do wish to add to version control using negated pattern # !example_override.tf # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan # example: *tfplan* # Ignore CLI configuration files .terraformrc terraform.rc |
I copied the .gitignore from here. Use VS Code to add a file named .gitignore to the unicorn project folder and paste the contents from above into it.
Next using a terminal open to the unicorn project directory, run git init to initialize a local repository.
1 2 3 4 |
git init git add *.* git status git commit -m "Initial commit" |
Next I used a browser to login to my GitHub account and on the Repositories tab, clicked the big green “New” button.
On the Create a new repository page, I left Repository template set to no template, set the owner to me and the Repository name to unicorn. I did not add a README file, a .gitignore or a license file because I want the repository to be completely empty. This is because the unicorn project already has a commit history. If you allow GitHub to add files to the new repository, it will have a different commit history and give you an error when you try to push your local commits to GitHub. While it is possible to instruct git to merge the commit histories, it’s easier to just add README.md and license file later.
After you create the repository, back in the terminal, run the following commands.
1 2 3 |
git remote add origin https://github.com/<github-account-name>/unicorn.git git branch -M main git push -u origin main |
Back in GitHub, confirm the files were pushed to the upstream repository.
In this post, we created the local git repository, the remote GitHub repository and pushed the code to GitHub. In the next post I’m going to create the Microsoft Entra Security Principal the GitHub Action will use to authenticate to Azure and create resources.