如何对现有策略使用azurerm_subscription_policy_remediation

2lpgd968  于 2023-06-24  发布在  其他
关注(0)|答案(1)|浏览(104)

我无法将策略作为数据块读入以修复策略。
scope_id出错。我使用了azurerm_resouce_group. id,但它显示“策略分配名称:"Test-Inherit-RequiredTag-IheritedTag" was not found "我正在尝试使用订阅ID,然后它说它需要"/subscributions/",所以我添加了这个。现在是“畸形或无效”
我也试过
scope_id ="/subscription/0000000 - 0000 - 0000 - 0000 - 0000000000000000000000000000000000000000000000000000000000000000000000000000000000 - 0000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 00000 - 000000000000000000000000000000/providers/providers/provider/microsoft.
scope_id应该是什么?

data "azurerm_policy_assignment" "policy_assignment1" {
  name     = "Test-Inherit-RequiredTag-InheritedTag"
  scope_id = "/subscriptions/${var.subscription_id}"
}

resource "azurerm_subscription_policy_remediation" "remediation1" {
  name                 = "remediation1-inherit-tag"
  subscription_id      = var.subscription_id
  policy_assignment_id = data.azurerm_policy_assignment.policy_assignment1.id
}
voase2hg

voase2hg1#

我尝试在现有策略中使用azurerm_subscription_policy_remediation,并成功执行了terrafrom_planterraform_apply命令。
我引用了official Terraform exemption documentofficial Terraform remediation document(https://registry.terraform.io/providers/hashicorp/azurerm/3.59.0/docs/resources/subscription_policy_remediation)的代码,并相应地修改了它。
问题中提到的模块。

data "azurerm_policy_assignment" "policy_assignment1" {
  name     = "Test-Inherit-RequiredTag-InheritedTag"
  scope_id = "/subscriptions/${var.subscription_id}"
}

它对我来说也不起作用,所以我最终根据需求修改了模块,并能够产生您正在寻找的输出。

terraform {

required_providers {

azurerm  =  {

source  =  "hashicorp/azurerm"

version  =  "=3.59.0"

}

}

}

  

provider  "azurerm" {

features {}

}

  

data  "azurerm_subscription"  "example" {}

  

data  "azurerm_policy_set_definition"  "example" {

display_name  =  "Audit machines with insecure password security settings"

}

  

resource  "azurerm_subscription_policy_assignment"  "example" {

name  =  "exampleAssignment"

subscription_id  =  data.azurerm_subscription.example.id

policy_definition_id  =  data.azurerm_policy_set_definition.example.id

location  =  "westus"

  

identity {

type  =  "SystemAssigned"

}

}

  

resource  "azurerm_subscription_policy_remediation"  "example" {

name  =  "example"

subscription_id  =  data.azurerm_subscription.example.id

policy_assignment_id  =  azurerm_subscription_policy_assignment.example.id

}
    • 输出:**

执行terrafrom_plan
https://i.imgur.com/ZO6iWFg.png
执行terraform_apply
https://i.imgur.com/2JYor6I.png
通过使用脚本,我成功地执行了所有的terraform步骤和所需的输出。

相关问题