Course outlines for learning terraform.
expected time | requirements |
---|---|
30 minutes | A computer with Terraform installed, terraform knowledge. |
Goal: See how you can design workspaces in Terraform Cloud.
Terraform Cloud has a concept of “workspaces”. A workspace is a bit like a directory or repository on you local computer, it contains state, variables, etc.
There are unique benefits to these workspaces, one of them is the offering and consumption of data from department to department.
Image a company with these departments:
You can setup workspaces like this:
+--- networking ------------+ +--- compute -------------------+
| azurerm_virtual_network | | azurerm_network_interface |
| azurerm_subnet | -> | subnet_id |
| azurerm_public_ip | -> | public_ip_address_id |
+---------------------------+ | azurerm_linux_virtual_machine |
| network_interface_ids |
+-------------------------------+
In the diagram above, the compute
department needs two details from the networking
department:
subnet_id
public_ip_address_id
This can be done by using a data
object that points to another workspace:
data "terraform_remote_state" "networking" {
backend = "remote"
config = {
organization = "example"
workspaces = {
name = "networking"
}
}
}
You can use object from data.terraform_remote_state.networking
:
resource "azurerm_network_interface" "default" {
name = "my-network-interface"
location = "west europe"
resource_group_name = "my-resource-group"
ip_configuration {
name = "my-ip-configuration"
subnet_id = data.terraform_remote_state.networking.outputs.subnet_id
private_ip_address_allocation = "dynamic"
}
}
As you can see the outputs
key is used, meaning the state referred to should have an output
of subnet_id
.
Take about 10 minutes to:
Let’s see what you came up with and if we can (re-)use a part of your design.
terraform_remote_state
.