Error creating Resource Group using Terraform

To put it into context, I created a module and placed it in a repo on Azure and this module contains the creation of a UAI, SQL Server, Database and a schedule job. I am creating the Resource Group using the application code that will use the module, so I can use tfvars and work with various environments.

Here’s my problem, when leaving the complete code containing backend, provider, creation of the resource group and the module, it doesn’t create the resource group, it goes straight to the module and shows the error “A managed resource “azurerm_resource_group” “rg” has not been declared in module.job.” When I comment the module line it interprets the creation of the resource group normally. Make sure the module and application code are in the same branch.

terraform {
  backend "azurerm" {
    storage_account_name = ""
    resource_group_name  = ""
    container_name       = ""
    key                  = ""
  }
  required_providers {
    azurerm = {
      version = ""
    }
    azuread = {
      version = ""
    }
    null = {
      version = ""
    }
  }
}

provider "azurerm" {
  subscription_id = var.subscription
  features {}
}

resource "azurerm_resource_group" "rg" {
  name     = "Rg-${var.environment}-${var.region_name}-Schedule-Job"
  location = var.region_code
}

### JOB ###

 module "job" {
   source                       = ""
   environment                  = var.environment
   region_code                  = var.region_code
   region_name                  = var.region_name
   subscription                 = var.subscription
   administrator_login          = var.administrator_login
   administrator_login_password = var.administrator_login_password
 }

I tried to use depends_on

 module "job" {
   source                       = "git::/home/vsts/work/r1/a/tf-modules/.git//azure/tf-mssql-schedule-job-agent"
   environment                  = var.environment
   region_code                  = var.region_code
   region_name                  = var.region_name
   subscription                 = var.subscription
   administrator_login          = var.administrator_login
   administrator_login_password = var.administrator_login_password
   depends_on = [ azurerm_resource_group.rg. ]
 }

I tried to use output e input

resource "azurerm_resource_group" "rg" {
  name     = "Rg-${var.environment}-${var.region_name}-Schedule-Job"
  location = var.region_code
}

output "resource_group_name" {
  value = azurerm_resource_group.rg.name
}

output "resource_group_location" {
  value = azurerm_resource_group.rg.location
}

New contributor

samucabrave is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

3

creating Resource Group using Terraform while provisioning the sheduled job

From the error description you can observe that the declaration of resoruce group under job module configuration is missing its seems to be the error

Since youre using the module configuration and creating the rg in root configuration so we need to refer the rg info into the job module so we need to declare the rg info under module configuration.

Demo configuration:

resource "azurerm_resource_group" "rg" {
  name     = "Rg-${var.environment}-${var.region_name}-Schedule-Job"
  location = var.region_code
}


module "job" {
  source                       = "./job"
  environment                  = var.environment
  region_code                  = var.region_code
  region_name                  = var.region_name
  administrator_login          = var.administrator_login
  administrator_login_password = var.administrator_login_password
  resource_group_name          = azurerm_resource_group.rg.name
  resource_group_location      = azurerm_resource_group.rg.location

  depends_on = [ azurerm_resource_group.rg ]
}

Deployment:

Refer:

https://developer.hashicorp.com/terraform/tutorials/modules/module

https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_job_schedule

Recognized by Microsoft Azure Collective

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật