【发布时间】:2022-06-13 03:33:51
【问题描述】:
我有一个简单的 Terraform 配置来创建 azure 虚拟网络。当我执行 plan 然后 apply 时,会按预期在资源组内创建一个虚拟网络。但除了这个资源组之外,还有一个名为 NetworkWatcherRG 的资源组,在其中我看到了一个网络观察者。
还有网络观察者。
现在,当我运行 Terraform destroy 命令时,我希望所有东西都被清理干净,所有资源组都被销毁。但是,除了 NetworkWatcherRG 和其中的 Network Watcher 之外的所有内容都被销毁。
看起来 Network Watcher 及其资源组不受 Terraform 管理。我错过了什么?
网络观察者不是很明显。它没有立即陶醉。所以要看到这一点,你需要去simplified view of the resource groups。您需要至少点击刷新按钮 5 次(每次有 2 秒的时间间隔),否则您必须等待很长时间才能点击刷新。
那么这个网络观察者是什么?是 Azure 自己创建它而不是由 Terraform 管理的吗?
我的 Terraform 配置文件如下。
# Terraform settings Block
terraform {
required_version = ">= 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.0"
}
}
}
# Provider Block
provider "azurerm" {
features {}
}
# create virtual network
resource "azurerm_virtual_network" "myvnet" {
name = "vivek-1-vnet"
address_space = ["10.0.0.0/16"] # This is a list, it has []. If it has { }, then its a map.
location = azurerm_resource_group.myrg.location
resource_group_name = azurerm_resource_group.myrg.name
tags = { # This is a map. This is {}
"name" = "vivek-1-vnet"
}
}
# Resource-1: Azure Resource Group
resource "azurerm_resource_group" "myrg" {
name = "vivek-vnet-rg"
location = var.resource_group_location
}
variable "resource_group_location" {
default = "centralindia"
description = "Location of the resource group."
}
最后我使用的命令如下。
terraform fmt
terraform init
terraform validate
terraform plan -out main.tfplan
terraform apply main.tfplan
terraform plan -destroy -out main.destroy.tfplan
terraform apply main.destroy.tfplan
【问题讨论】: