Exercise: variables
- Create a root module
- Create a
unique_id
input variable- Give it a sensible default
- Create a local variable
- Create a
message
output variable- Use string interpolation to return a string composed of:
- Your local variable
- The
var.unique_id
class variable - The current terraform workspace
${terraform.workspace}
- Use string interpolation to return a string composed of:
- Run
terraform apply
- Re-run terraform but pass a different value for unique_id
The solution to the ‘variables’ exercise is available as part of our open-source Devops-Workstream.
Exercise: create Azure Resource Groups
Follow the Create Resource group tutorial to create resource groups with dynamic naming.
The solution to the ‘create Resource Group’ exercise is available as part of our open-source Devops-Workstream.
Exercise: create Azure Networks
- Create a root module
- Reuse the standard components (such as
backend.tf
andprovider.tf
from the previous tutorials
- Reuse the standard components (such as
- Create an
azurerm_virtual_network
- for 10.0.0.0/16
- Create an
azurerm_subnet
- for some /24 subnet of that address space
- e.g. 10.0.1.0/24
- Create an
azurerm_network_security_group
- Open port 22 for inbound traffic from the Internet
The solution to the ‘create Azure Network’ exercise is available as part of our open-source Devops-Workstream.
Exercise: Network as a module
- Look at the module examples in DevOps Workstream
- Re-write your previous solution as a module
The solution to the ‘Network as a module’ exercise is available as part of our open-source Devops-Workstream.
Exercise: using the docs
- Research on Terraform.io how to use the AzureRM provider to create a Linux Virtual Machine
- Start with the deprecation notice for the old resource type
- You should aim to re-use your solution to the previous exercise for the network
- Extend your solution to create virtual machines using a module
- Instantiate your virtual machine module twice
- Create two
output
resources that use string interpolation to compose an SSH command- One to SSH to each of your new hosts
The original solution used a now-deprecated resource type.network
The ‘referencing secrets’ exercise solution uses the more up-to-date azurerm_linux_virtual_machine
resource type.
As with all exercises that involve Cloud provisioning, please ensure you terraform destroy
all your Cloud resources after completing the exercise, in order to minimise your Cloud charges from Microsoft.
Further exercises were recently added to this series:
Leave a comment