From the course: Introduction to Terraform on Azure

Configure and clone your DevOps project

From the course: Introduction to Terraform on Azure

Configure and clone your DevOps project

- [Instructor] Now that you understand the value of CICD for Terraform, let's get hands-on and build your first automated pipeline. We will take the infrastructure models you've created and set up an Azure DevOps pipeline that automatically deploys them when you push code changes. At the end, you'll have a working pipeline that eliminates the manual Terraform commands and provides a consistent deployment workflow. First, we need to create an Azure DevOps project. To do that, navigate to dev.azure.com. And if this is your first time using Azure DevOps, you will need to sign off for free and create an organization. Simply follow the prompts on the site to create an organization and ensure to use a unique name. After creating an organization, you should see the screen. Click on the new project button at the top right, the project name will be "terraform-project" and you can add a description if you want. I'll give mine infrastructure automation with Terraform. You can click on the advanced. I would leave my visibility as private and leave other settings as default. Ensure that version control is Git and then click on create. The project page opens after it's created, and now we need to set up the repository. So let's expand the left menu. Click on the last button down here, and then go to repos and click repos. You'll see an empty repository with set up instructions. So let's initialize the main branch with Terraform Git Ignore. So down here where you have initialized main branch, click on the dropdown and then search for Terraform. Select Terraform and then click initialize. This will also add a read me file. Now at the top right, let's click on the clone button and let's copy the repository link. Next we need to add this repository to our local project and then push to this remote repository. So to do that, let's head over to our IDs terminal. And at the top I would click on terminal and select new terminal. The first thing we need to do is to initialize Git in this local directory. Make sure to have installed Git in your system before you run this command. Git in it. And this has initialized an empty Git repository in my project directory. The next step is to add the Azure DevOps remote repository we just copied from the repo screen. So to do that you type git remote add origin, and then paste the URL you copied, and enter. Now let's pull the Readme and .gitignore file from the remote main branch so that we don't have to manually create a .gitignore file here. To do that, you run git pull origin main and then enter. Now in your explorer view, you should see the .gitignore file. This is where you can add files that should not be pushed to your remote repo, like your .tif files with secrets or models with sensitive strings such as passwords, connection strings, et cetera. I'll scroll to the end and just add .DS_Store. If you don't have this in your VS code, then you don't need to add that. I'll save this. And we need to remove the default database password in our root variable file. So let's go to the root variables and then scroll down to password and we can delete this, then save the file. Once you're done updating your .gitignore and I've removed the default database password from the variables file, let's run git add . in our terminal. And now let's commit changes to the repo. So you run git commit -m and in quotes you add the comment "add Terraform code to remote branch". Then press enter. Awesome. Now it's time to push the code to the Azure DevOps repo. So you type git push origin main, and enter. Great. Let's go to our Azure DevOps portal and then just click on the refresh button at the top left. Now our configuration files are now in the remote repo. If you were trying to clone and you have issues with username and password being requested, when you click on the clone at the top right click generate Git credentials, and then copy this password and place where you're prompted to provide a password.

Contents