skip to Main Content

modules/tf-sqlserver-module/main.tf:

resource "azurerm_mssql_server" "sqlserver" {
  administrator_login = var.admin_username
  administrator_login_password = var.admin_pw
  name                = local.sql_full_name
  resource_group_name = var.rg_sql_name
  location            = var.location
  version             = "12.0"  # Choose the desired SQL Server version
  azuread_administrator {
    login_username    = var.azure_ad_admin_user
    object_id         = var.azure_ad_object_id
  }
  tags = {
    project           = "${var.project_tag}"
    environment       = "${var.environment_tag}"
  }
  identity {
    type = "SystemAssigned"
  }
}

modules/tf-sqlserver-module/outputs.tf:

output "sql_server_id" {
  description = "ID of the created Azure SQL Server"
  value       = azurerm_mssql_server.sqlserver.id
}

output "sql_server_fqdn" {
  description = "Fully qualified domain name (FQDN) of the SQL Server"
  value       = azurerm_mssql_server.sqlserver.fully_qualified_domain_name
}

output "azure_ad_admin_user" {
  description = "Azure AD Admin User Principal Name"
  value       = var.azure_ad_admin_user
}

modules/tf-sqlserver-module/variables.tf containing all variables needed.

in sqldb-dev/terragrunt.hcl

...
dependency "sql_srv" {
  config_path = "../sqlserver-dev"
  mock_outputs = {
    sql_server_id = "tempid"
  }
}

inputs = {
  db_prefix = local.db_prefix
  location = local.location
  collation = local.collation
  project_tag = local.project
  environment_tag = local.environment
  sql_server_id = dependency.sql_srv.outputs.sql_server_id
  branch = "dev"
}

sqlserver-dev/terragrunt.hcl:

I get this error for the database
Unsupported attribute; This object does not have an attribute named "sql_server_id".

I am tryeing to create a environment interragrunt. The expected output should be that the sqldb gets teh outout from the module.

2

Answers


  1. Chosen as BEST ANSWER

    I solved this problem by adding a data block to the variables.tf file:

    data "azurerm_mssql_server" "sqlserver" {
      resource_group_name = var.rg_sql_name
      name = local.sql_full_name
    }
    

    The outputs.tf will have get the data by :

    output "server_id" {
      description = "ID of the created Azure SQL Server"
      value       = data.azurerm_mssql_server.sqlserver.id
    }
    

  2. Your config_path should be ../modules/tf-sqlserver-module.

    ...
    dependency "sql_srv" {
      config_path = "../modules/tf-sqlserver-module"
      mock_outputs = {
        sql_server_id = "tempid"
      }
    }
    
    inputs = {
      db_prefix = local.db_prefix
      location = local.location
      collation = local.collation
      project_tag = local.project
      environment_tag = local.environment
      sql_server_id = dependency.sql_srv.outputs.sql_server_id
      branch = "dev"
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search