Hi all. I need a help with using the modules. I have the following structure:
main.tf
providers.tf
terraform.tfvars
---- modules
---------cosmosdb
--------------main.tf
--------------variables.tf
--------------providers.tf
---------sqlserver
--------------main.tf
--------------variables.tf
--------------providers.tf
Problem is when i call the terraform plan on main.tf in root that is calling the modules, it returns the error that he doesnt see any variables… What might be a problem? Thank you.
This is the main.tf for cosmosdb
resource "azurerm_resource_group" "cosmosdb_rg" {
name = var.cosmosdb_resource_group_name
location = var.cosmosdb_resource_group_location
}
resource "azurerm_cosmosdb_account" "cosmosdb" {
name = var.cosmosdb_account_name
location = azurerm_resource_group.cosmosdb_rg.location
resource_group_name = azurerm_resource_group.cosmosdb_rg.name
offer_type = var.cosmosdb_offer_type
kind = var.cosmosdb_kind
consistency_policy {
consistency_level = var.cosmosdb_consistency_level
max_interval_in_seconds = var.cosmosdb_consistency_max_interval
max_staleness_prefix = var.cosmosdb_consistency_max_staleness
}
geo_location {
location = var.cosmosdb_geo_location[0].location
failover_priority = var.cosmosdb_geo_location[0].failover_priority
}
tags = var.tags
}
resource "azurerm_cosmosdb_sql_database" "cosmosdb_database" {
name = var.cosmosdb_database_name
resource_group_name = azurerm_resource_group.cosmosdb_rg.name
account_name = azurerm_cosmosdb_account.cosmosdb.name
throughput = var.cosmosdb_database_throughput
}
Variables.tf
variable "cosmosdb_resource_group_name" {
description = "Name of the resource group in which to create the Cosmos DB account."
type = string
}
variable "cosmosdb_resource_group_location" {
description = "Location for the resource group."
type = string
}
variable "cosmosdb_account_name" {
description = "Name of the Cosmos DB account."
type = string
}
variable "cosmosdb_offer_type" {
description = "Offer type for the Cosmos DB account."
type = string
}
variable "cosmosdb_kind" {
description = "Kind for the Cosmos DB account."
type = string
}
variable "cosmosdb_consistency_level" {
description = "Consistency level for the Cosmos DB account."
type = string
}
variable "cosmosdb_consistency_max_interval" {
description = "Max interval in seconds for consistency."
type = number
}
variable "cosmosdb_consistency_max_staleness" {
description = "Max staleness prefix for consistency."
type = number
}
variable "cosmosdb_geo_location" {
description = "Geo location for the Cosmos DB account."
type = list(object({
location = string
failover_priority = number
}))
}
variable "cosmosdb_database_name" {
description = "Name of the Cosmos DB database."
type = string
}
variable "cosmosdb_database_throughput" {
description = "Throughput for the Cosmos DB database."
type = number
}
variable "tags" {
description = "Tags to be assigned to the Cosmos DB account."
type = map(string)
}
Main.tf that is calling the modules:
module "cosmosdb" {
source = "./modules/azure-cosmosdb"
cosmosdb_resource_group_name = var.cosmosdb_resource_group_name
cosmosdb_resource_group_location = var.cosmosdb_resource_group_location
cosmosdb_account_name = var.cosmosdb_account_name
cosmosdb_kind = var.cosmosdb_kind
cosmosdb_database_name = var.cosmosdb_database_name
cosmosdb_database_throughput = var.cosmosdb_database_throughput
cosmosdb_offer_type = var.cosmosdb_offer_type
cosmosdb_consistency_level = var.cosmosdb_consistency_level
cosmosdb_consistency_max_interval = var.cosmosdb_consistency_max_interval
cosmosdb_consistency_max_staleness = var.cosmosdb_consistency_max_staleness
cosmosdb_geo_location = var.cosmosdb_geo_location
tags = var.tags
}