AgentSkillsCN

az-resource-group

使用 Terraform 创建并管理 Azure 资源组

SKILL.md
--- frontmatter
name: az-resource-group
description: Create and manage Azure Resource Groups with Terraform
license: MIT
compatibility: opencode
metadata:
  workflow: terraform
  provider: azure
  resource: azurerm_resource_group

What I do

Help create and manage Azure Resource Groups:

  • Define resource group configurations
  • Apply proper naming conventions
  • Configure tags and locations
  • Handle resource group dependencies

When to use me

Use this skill when:

  • Creating a new Azure resource group
  • Organizing resources by environment or project
  • Setting up the foundation for other Azure resources

Resource Template

hcl
# Basic Resource Group
resource "azurerm_resource_group" "main" {
  name     = "${var.project_name}-${var.environment}-rg"
  location = var.location

  tags = {
    Environment = var.environment
    Project     = var.project_name
    ManagedBy   = "Terraform"
  }
}

# With lifecycle protection
resource "azurerm_resource_group" "protected" {
  name     = "${var.project_name}-${var.environment}-rg"
  location = var.location
  tags     = local.common_tags

  lifecycle {
    prevent_destroy = true
  }
}

Variables Needed

hcl
variable "location" {
  description = "Azure region"
  type        = string
  default     = "eastus"
}

Outputs

hcl
output "resource_group_name" {
  description = "The name of the resource group"
  value       = azurerm_resource_group.main.name
}

output "resource_group_id" {
  description = "The ID of the resource group"
  value       = azurerm_resource_group.main.id
}

output "resource_group_location" {
  description = "The location of the resource group"
  value       = azurerm_resource_group.main.location
}

Best Practices

  1. Use consistent naming: {project}-{environment}-rg
  2. Always apply tags for cost management
  3. Group related resources together
  4. Consider region for compliance requirements