Terraform now provides new functions, making itself more powerful as a configuration mgmt tool.

Here are some memos:

To make var value join with fixed string: "test-${each.key}"


From Terraform official documents, they have an example as following and explained in none humane language way. So I’ll try to interpret it from a Network Expert perspective.

cidrsubnet(prefix, newbits, netnum)

And an example below:

> cidrsubnet("", 4, 2)
> cidrsubnet("", 4, 15)
> cidrsubnet("fd00:fd12:3456:7890::/56", 16, 162)

As what we can see from above example, although their documents explained with thousands of tech words, this cidrsubnet(prefix=, newbits=4, netnum=15) actually means increase 4 subnets based on prefix subnet, and use subnet number 15.


Official example:

resource "aws_instance" "server" {
  count = 4 # create four similar EC2 instances

  ami           = "ami-a1b2c3d4"
  instance_type = "t2.micro"

  tags {
    Name = "Server ${count.index}"

this will create tags with server name from 0 to 3.


This is newly added on ver12.6. Official example:

resource "azurerm_resource_group" "rg" {
  for_each = {
    a_group = "eastus"
    another_group = "westus2"
  name     = each.key
  location = each.value

this will create

resource "azurerm_resource_group" "rg[a_group]" {
  name     = "a_group"
  location = "eastus"
resource "azurerm_resource_group" "rg[another_group]" {
  name     = "another_group"
  location = "westus2"