FlexibleEngineCloud / terraform-flexibleengine-vpc

Terraform module which creates VPC resources on Flexible Engine
Apache License 2.0
3 stars 7 forks source link

Issue when creating a VPC without NAT GW #5

Closed pierrecarre closed 2 years ago

pierrecarre commented 3 years ago

Hello,

I got the following error when I tried to create a VPC without a NAT GW.

$ terragrunt plan

Error: Invalid index

  on main.tf line 72, in resource "flexibleengine_nat_snat_rule_v2" "snat":
  72:   nat_gateway_id = flexibleengine_nat_gateway_v2.nat_gateway[0].id
    |----------------
    | flexibleengine_nat_gateway_v2.nat_gateway is empty tuple

The given key does not identify an element in this collection value.

ERRO[0002] Hit multiple errors:
Hit multiple errors:
exit status 1 

I try to create the VPC like the following:

terraform {
  source = "git::https://github.com/FlexibleEngineCloud/terraform-flexibleengine-vpc.git//?ref=v2.1.0"
}

include {
  path = find_in_parent_folders()
}

locals {
  common_vars = yamldecode(file(find_in_parent_folders("common_vars.yaml")))
}

inputs = {
  vpc_name = "${local.common_vars.env}-dmz-vpc"
  vpc_cidr = "10.100.1.0/24"
  vpc_subnets = [
    {
      subnet_name       = local.common_vars.dmz_vpc_subnet_name
      subnet_cidr       = "10.100.1.0/29"
      subnet_gateway_ip = "10.100.1.1"
    }
  ]
  vpc_snat_subnets = [
    local.common_vars.dmz_vpc_subnet_name
  ]
  enable_nat_gateway = false
  new_eip            = false
}

I dont need any gateway because I will have only one VM in this VPC, with its own EIP.

I guess the error is linked to the SNAT rules block

resource "flexibleengine_nat_snat_rule_v2" "snat" {
  # Create SNAT Rules
  for_each = local.vpc_subnets_snat_cidr_map

  nat_gateway_id = flexibleengine_nat_gateway_v2.nat_gateway[0].id
  network_id     = flexibleengine_vpc_subnet_v1.vpc_subnets[each.value].id
  floating_ip_id = var.new_eip ? flexibleengine_vpc_eip_v1.new_eip[0].id : var.existing_eip_id
}

but as I don't need NAT GW, this block should not be evaluated.

Pierre