generate-modern-terraform-code-for-azure — правило для GitHub Copilot
Правило задаёт рекомендации для Terraform-конфигураций Azure: выбор провайдера, структура файлов, модули и проверка изменений. Помогает направлять Copilot при работе с файлами .tf.
.github/instructions/generate-modern-terraform-code-for-azure.instructions.mdЧто делает generate-modern-terraform-code-for-azure
Правило применяется к файлам **/*.tf. Оно задаёт структуру конфигурации с main.tf, variables.tf и outputs.tf, предлагает выносить повторно используемую инфраструктуру в модули и описывать входные параметры и выходы. Для большинства сценариев рекомендуется azurerm, а azapi — для новых функций Azure или ресурсов, которых ещё нет в azurerm.
Также правило требует учитывать версии Terraform и провайдеров, не добавлять зависимости без согласования и писать конфигурации идемпотентно. Перед применением изменений нужно запускать terraform validate и проверять terraform plan; второй запуск terraform apply должен завершаться без изменений. Для состояния предлагается удалённый backend, например Azure Storage с блокировкой, а файлы состояния нельзя коммитить в систему контроля версий. Без проверки terraform plan можно пропустить нежелательные изменения инфраструктуры.
Какие задачи решает
- разложить Terraform-конфигурацию по основным файлам
- вынести повторно используемые ресурсы Azure в модуль
- выбрать между провайдерами
azurermиazapi - проверить план Terraform перед применением
- хранить состояние Terraform в удалённом backend
Примеры запросов агенту
- Создай Terraform-конфигурацию Azure с файлами
main.tf,variables.tfиoutputs.tf. - Вынеси повторно используемые ресурсы Azure в модуль и объясни выбор провайдера.
- Проверь конфигурацию Terraform: запусти
terraform validateи разберись с выводомterraform plan.
Как установить generate-modern-terraform-code-for-azure
Вручную: положить файлы
.github/instructions/generate-modern-terraform-code-for-azure.instructions.mdПоле applyTo задаёт, к каким файлам применять
Вручную: положить файлы
.claude/rules/generate-modern-terraform-code-for-azure.mdПоле paths во frontmatter ограничивает файлы: applyTo из источника → paths
AGENTS.md
Codex читает AGENTS.md: вставьте текст правила туда
Вручную: положить файлы
.cursor/rules/generate-modern-terraform-code-for-azure.mdcВо frontmatter: description, globs, alwaysApply. applyTo из источника → globs, иначе правило само не подключится
Вручную: положить файлы
.devin/rules/generate-modern-terraform-code-for-azure.mdВручную: положить файлы
.clinerules/generate-modern-terraform-code-for-azure.mdПо шагам, с командами для каждой платформы: AGENTS.md и CLAUDE.md: что это, кто читает и какой выбрать
Вопросы о generate-modern-terraform-code-for-azure
Как установить generate-modern-terraform-code-for-azure в GitHub Copilot?
Добавьте файл .github/instructions/generate-modern-terraform-code-for-azure.instructions.md в проект. Правило применяется к файлам **/*.tf.
Что делает generate-modern-terraform-code-for-azure?
Правило направляет генерацию Terraform-кода для Azure: описывает организацию файлов и модулей, выбор провайдера, работу с состоянием и проверки перед применением.
Когда использовать azapi вместо azurerm?
azapi предлагается для новых функций Azure или ресурсов, которые пока не поддерживает azurerm. В остальных случаях правило рекомендует выбирать azurerm.
Исходный текст
generate-modern-terraform-code-for-azure.instructions.md · MIT
--- description: 'Guidelines for generating modern Terraform code for Azure' applyTo: '**/*.tf' --- ## 1. Use Latest Terraform and Providers Always target the latest stable Terraform version and Azure providers. In code, specify the required Terraform and provider versions to enforce this. Keep provider versions updated to get new features and fixes. ## 2. Organize Code Cleanly Structure Terraform configurations with logical file separation: - Use `main.tf` for resources - Use `variables.tf` for inputs - Use `outputs.tf` for outputs - Follow consistent naming conventions and formatting (`terraform fmt`) This makes the code easy to navigate and maintain. ## 3. Encapsulate in Modules Use Terraform modules to group reusable infrastructure components. For any resource set that will be used in multiple contexts: - Create a module with its own variables/outputs - Reference it rather than duplicating code - This promotes reuse and consistency ## 4. Leverage Variables and Outputs - **Parameterize** all configurable values using variables with types and descriptions - **Provide default values** where appropriate for optional variables - **Use outputs** to expose key resource attributes for other modules or user reference - **Mark sensitive values** accordingly to protect secrets ## 5. Provider Selection (AzureRM vs AzAPI) - **Use `azurerm` provider** for most scenarios – it offers high stability and covers the majority of Azure services - **Use `azapi` provider** only for cases where you need: - The very latest Azure features - A resource not yet supported in `azurerm` - **Document the choice** in code comments - Both providers can be used together if needed, but prefer `azurerm` when in doubt ## 6. Minimal Dependencies - **Do not introduce** additional providers or modules beyond the project's scope without confirmation - If a special provider (e.g., `random`, `tls`) or external module is needed: - Add a comment to explain - Ensure the user approves it - Keep the infrastructure stack lean and avoid unnecessary complexity ## 7. Ensure Idempotency - Write configurations that can be applied repeatedly with the same outcome - **Avoid non-idempotent actions**: - Scripts that run on every apply - Resources that might conflict if created twice - **Test by doing multiple `terraform apply` runs** and ensure the second run results in zero changes - Use resource lifecycle settings or conditional expressions to handle drift or external changes gracefully ## 8. State Management - **Use a remote backend** (like Azure Storage with state locking) to store Terraform state securely - Enable team collaboration - **Never commit state files** to source control - This prevents conflicts and keeps the infrastructure state consistent ## 9. Document and Diagram - **Maintain up-to-date documentation** - **Update README.md** with any new variables, outputs, or usage instructions whenever the code changes - Consider using tools like `terraform-docs` for automation - **Update architecture diagrams** to reflect infrastructure changes after each significant update - Well-documented code and diagrams ensure the whole team understands the infrastructure ## 10. Validate and Test Changes - **Run `terraform validate`** and review the `terraform plan` output before applying changes - Catch errors or unintended modifications early - **Consider implementing automated checks**: - CI pipeline - Pre-commit hooks - Enforce formatting, linting, and basic validation
© github · MIT · github/awesome-copilot