In this lab, we'll practice using Terraform Enterprise and Github
Before you start the lab, make sure that you have met the requirements defined in lab pre-reqs document.
Go to https://github.com (or your company's private git repo) and confirm that you can login and access the organization.
Create a new github repository named tfe_lab_ABC
where ABC are your initials in your company organization
- check Initialize this repository with a README
- select the Terraform .gitignore template
Go to https://app.terraform.io/app (or your company's private TFE install) and confirm that you can login and see your organization
Create a new workspace named tfe_lab_ABC
where ABC are your initials
Workspace > tfe_lab_ABC > Variables > Environment Variables
Set the cloud provider credentials:
Aws requires:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
Execute the following command in the terminal to clone the repository you just created
git clone https://github.com/YOUR_ORG/tfe_lab_YOUR_INITIALS.git
cd tfe_lab_*
-
Download this lab's main_aws.tf example file to your PC, and put it in the
./tfe_lab_YOUR_INITIALS
project directory -
Use the IDE to edit the
my_name
variable in main_aws.tf and set it to your name
git add .
git commit -m "first commit"
git push
Take a look at the run on https://app.terraform.io/app
Click Confirm & Apply to apply the run
verify that the change applied successfully
git checkout -b dev
Edit main_aws.tf to add a new tags to the instance
tags {
Name = "${var.my_name}-${count.index + 1}"
environment = "tfe_lab"
department = "my department"
}
Now commit the branch
git add .
git commit -m "added department tag to vm"
git push --set-upstream origin my_branch
Go to github and confirm that the new tag exists, and submit a pull request
Click on the details link to be taken to the speculative plan
Notice the changes. An notice that this did not trigger a run!
Then Accept the pull request in Github
And confirm that a run started in TFE
Accept the change and apply the new tag
in TFE, Workspaces > tfe_lab_ABC > variables > environment variables > CONFIRM_DESTROY = 1
in TFE, Workspaces > tfe_lab_ABC > Settings > Destruction & Deletion > Queue Destroy Plan > Apply
in TFE, Workspaces > tfe_lab_ABC > Settings > Destruction & Deletion > Delete Workspace
Github Repo > Settings > Delete this repository
cd $HOME
rm -rf tfe_lab_*
- Create a module to deploy an ec2 instance using the same main_aws.tf code used in the workspace above. Then modify your workspace code to use your provate module.
- See Private Module Publishing documentation here
- See Private Module Usage documentation here
- Hints
- Modules (and thier repos) must be named with the prefix: "terraform-PROVIDER_NAME-". example module name is: "terraform-aws-ec2instance". For this lab, since multiple people will be publishing a private module, it is suggested that you name your module terrafom-aws-training-ec2-abc where abc are your initials
- Modules must be tagged with a 3 digit version number. example: v1.0.0. See example here
- You can use the module configuration designer to assist in configuring your workspace. See doc here