terraform-aws-modules / terraform-aws-vpc

Terraform module to create AWS VPC resources πŸ‡ΊπŸ‡¦
https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws
Apache License 2.0
2.99k stars 4.44k forks source link

Error: expected cidr_block to contain a valid Value, got: with err: invalid CIDR address: #976

Closed vsomwanshi closed 1 year ago

vsomwanshi commented 1 year ago

Reference code for deployment of VPC:

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

  name = var.cluster_name
  **cidr = var.machine_cidr_block**

  azs             = var.availability_zones
  private_subnets = var.private_subnet_cidrs
  public_subnets  = var.public_subnet_cidrs

  enable_nat_gateway = true
  enable_dns_hostnames = true
  enable_dns_support = true
}

Reference code for deployment of ROSA cluster depends_on rosa-vpc :

resource "rhcs_cluster_rosa_classic" "rosa" {
  name = var.cluster_name

  cloud_region   = var.aws_region
  aws_account_id = data.aws_caller_identity.current.account_id
  tags           = local.tags

  replicas             = var.replicas
  availability_zones   = var.availability_zones
  aws_private_link     = var.enable_private_link
  aws_subnet_ids       = var.enable_private_link ? module.rosa-vpc.private_subnets : concat(module.rosa-vpc.private_subnets, module.rosa-vpc.public_subnets)
  compute_machine_type = var.compute_node_instance_type
  multi_az             = length(module.rosa-vpc.private_subnets) == 3 ? true : false
  version              = var.rosa_version
  machine_cidr         = module.rosa-vpc.vpc_cidr_block
  properties           = { rosa_creator_arn = data.aws_caller_identity.current.arn }
  sts                  = var.enable_sts ? local.sts_roles : null
  depends_on           = [module.rosa-vpc]
}

We are passing the cidr value from one of the variable file, and when i am trying to deploy the VPC getting below error :

Error: expected cidr_block to contain a valid Value, got:  with err: invalid CIDR address: 
β”‚ 
β”‚   with module.rosa_cluster_1.module.rosa-vpc.aws_vpc.this[0],
β”‚   on .terraform/modules/rosa_cluster_1.rosa-vpc/main.tf line 30, in resource "aws_vpc" "this":
β”‚   30:   cidr_block          = var.use_ipam_pool ? null : var.cidr
vsomwanshi commented 1 year ago

Just for an update and information, this issue is fixed after adding below attribute.

Defined rosa-vpc module under rosa-cluster module for the deployment of ROSA cluster

Folder structure is like this :

β”œβ”€β”€ backend.tf
β”œβ”€β”€ datacenter
β”‚Β Β  └── aws_account
β”‚Β Β      β”œβ”€β”€ dev
β”‚Β Β      β”‚Β Β  └── oh.tf
β”œβ”€β”€ main.tf
β”œβ”€β”€ modules
β”‚Β Β  └── rosa-cluster
β”‚Β Β      β”œβ”€β”€ main.tf
β”‚Β Β      β”œβ”€β”€ rosa-vpc.tf
β”‚Β Β      β”œβ”€β”€ rosa_with_new_vpc.tf
β”‚Β Β      └── vars.tf
β”œβ”€β”€ output.tf
β”œβ”€β”€ readme.md
β”œβ”€β”€ terraform.tfstate
β”œβ”€β”€ terraform.tfstate.d
β”‚Β Β  β”œβ”€β”€ dev
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ terraform.tfstate
└── vars.tf

Defined few of the variables in main.tf under root directory and which fixed the issue

module "rosa-cluster-1" {
  source = "./modules/rosa-cluster"
  cluster_name           = var.cluster_name
  ocm_environment        = var.ocm_environment
  machine_cidr_block     = var.machine_cidr_block
  replicas               = var.replicas
  availability_zones     = var.availability_zones
  private_subnet_cidrs   = var.private_subnet_cidrs
  public_subnet_cidrs    = var.public_subnet_cidrs
}
github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.