Terraform registry AWS module

Reading Time: 2 minutes

I am starting to transition from TF .11 to TF .12, recently I started to work on AWS terraform registry module and start to run into the following issue.

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  version = "2.29.0"

  # insert the 12 required variables here
  name = "my-vpc"
  cidr = "10.0.0.0/16"
   azs             = ["us-east-1a", "us-east-1b", "us-east-1c"]
  private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
  public_subnets  = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]

  enable_nat_gateway = true
  enable_vpn_gateway = true

  tags = {
    Terraform = "true"
    Environment = "dev"
  }
}

(dev-tools) ➜  sandbox-vpc  terraform plan       

Error: Call to unknown function

  on .terraform/modules/vpc/main.tf line 288, in resource "aws_subnet" "public":
 288:   availability_zone               = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) > 0 ? element(var.azs, count.index) : null

There is no function named "regexall".


Error: Call to unknown function

  on .terraform/modules/vpc/main.tf line 289, in resource "aws_subnet" "public":
 289:   availability_zone_id            = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) == 0 ? element(var.azs, count.index) : null

There is no function named "regexall".


Error: Call to unknown function

  on .terraform/modules/vpc/main.tf line 316, in resource "aws_subnet" "private":
 316:   availability_zone               = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) > 0 ? element(var.azs, count.index) : null

There is no function named "regexall".


Error: Call to unknown function

  on .terraform/modules/vpc/main.tf line 317, in resource "aws_subnet" "private":
 317:   availability_zone_id            = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) == 0 ? element(var.azs, count.index) : null

There is no function named "regexall".


Error: Call to unknown function

  on .terraform/modules/vpc/main.tf line 343, in resource "aws_subnet" "database":
 343:   availability_zone               = length(regexall("^[a-z]{2}-", element(var.azs, count.index))) > 0 ? element(var.azs, count.index) : null

There is no function named "regexall".

Turns out this is an issue with TF version .12.06

(dev-tools) ➜  sandbox-vpc  terraform --version
Terraform v0.12.6
+ provider.aws v2.55.0

Fix

Upgrade TF to .12.24

(dev-tools) ➜  sandbox-vpc  brew upgrade terraform
Updating Homebrew...
==> Auto-updated Homebrew!
Updated Homebrew from 8d3aa49ae to c1708ff6b.
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
openssl@1.1 ✔
==> Updated Casks
loginputmac                                 openttd                                     wacom-inkspace

==> Upgrading 1 outdated package:
terraform 0.12.6 -> 0.12.24
==> Upgrading terraform 0.12.6 -> 0.12.24 
==> Downloading https://homebrew.bintray.com/bottles/terraform-0.12.24.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/2a/2a21a77589673b2064c9fa7587a79a0375d69a8e02f824e5dc22dc960bf2d78b?__gda__=exp=1585
######################################################################## 100.0%
==> Pouring terraform-0.12.24.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/terraform/0.12.24: 6 files, 51.2MB
==> `brew cleanup` has not been run in 30 days, running now...
/usr/local/share/ghostscript/9.19/Resource/CIDFSubst/ipaexg.ttf
(dev-tools) ➜  sandbox-vpc  terraform --version   
Terraform v0.12.24
+ provider.aws v2.55.0
(dev-tools) ➜  sandbox-vpc  terraform plan        
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.


------------------------------------------------------------------------

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # module.vpc.aws_eip.nat[0] will be created
  + resource "aws_eip" "nat" {
      + allocation_id     = (known after apply)
      + association_id    = (known after apply)
      + domain            = (known after apply)
      + id                = (known after apply)
      + instance          = (known after apply)
      + network_interface = (known after apply)
      + private_dns       = (known after apply)
      + private_ip        = (known after apply)
      + public_dns        = (known after apply)
      + public_ip         = (known after apply)
      + public_ipv4_pool  = (known after apply)
      + tags              = {
          + "Environment" = "dev"
          + "Name"        = "my-vpc-us-east-1a"
          + "Terraform"   = "true"
        }
      + vpc               = true
    }

Leave a Reply

Your email address will not be published. Required fields are marked *