/azurerm/internal/services/policy/tests/policy_remediation_resource_test.go

https://github.com/terraform-providers/terraform-provider-azurerm · Go · 727 lines · 693 code · 34 blank · 0 comment · 14 complexity · cae9819875f3922357d7d1690e604a0d MD5 · raw file

  1. package tests
  2. import (
  3. "fmt"
  4. "testing"
  5. "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
  6. "github.com/hashicorp/terraform-plugin-sdk/terraform"
  7. "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
  8. "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
  9. "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy"
  10. "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/policy/parse"
  11. "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
  12. )
  13. func TestAccAzureRMPolicyRemediation_atSubscription(t *testing.T) {
  14. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  15. resource.ParallelTest(t, resource.TestCase{
  16. PreCheck: func() { acceptance.PreCheck(t) },
  17. Providers: acceptance.SupportedProviders,
  18. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  19. Steps: []resource.TestStep{
  20. {
  21. Config: testAccAzureRMPolicyRemediation_atSubscription(data),
  22. Check: resource.ComposeTestCheckFunc(
  23. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  24. resource.TestCheckResourceAttrSet(data.ResourceName, "scope"),
  25. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_assignment_id"),
  26. ),
  27. },
  28. data.ImportStep(),
  29. },
  30. })
  31. }
  32. func TestAccAzureRMPolicyRemediation_atSubscriptionWithDefinitionSet(t *testing.T) {
  33. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  34. resource.ParallelTest(t, resource.TestCase{
  35. PreCheck: func() { acceptance.PreCheck(t) },
  36. Providers: acceptance.SupportedProviders,
  37. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  38. Steps: []resource.TestStep{
  39. {
  40. Config: testAccAzureRMPolicyRemediation_atSubscriptionWithDefinitionSet(data),
  41. Check: resource.ComposeTestCheckFunc(
  42. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  43. resource.TestCheckResourceAttrSet(data.ResourceName, "scope"),
  44. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_assignment_id"),
  45. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_definition_reference_id"),
  46. ),
  47. },
  48. data.ImportStep(),
  49. },
  50. })
  51. }
  52. func TestAccAzureRMPolicyRemediation_atResourceGroup(t *testing.T) {
  53. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  54. resource.ParallelTest(t, resource.TestCase{
  55. PreCheck: func() { acceptance.PreCheck(t) },
  56. Providers: acceptance.SupportedProviders,
  57. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  58. Steps: []resource.TestStep{
  59. {
  60. Config: testAccAzureRMPolicyRemediation_atResourceGroup(data),
  61. Check: resource.ComposeTestCheckFunc(
  62. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  63. resource.TestCheckResourceAttrSet(data.ResourceName, "scope"),
  64. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_assignment_id"),
  65. ),
  66. },
  67. data.ImportStep(),
  68. },
  69. })
  70. }
  71. func TestAccAzureRMPolicyRemediation_atManagementGroup(t *testing.T) {
  72. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  73. resource.ParallelTest(t, resource.TestCase{
  74. PreCheck: func() { acceptance.PreCheck(t) },
  75. Providers: acceptance.SupportedProviders,
  76. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  77. Steps: []resource.TestStep{
  78. {
  79. Config: testAccAzureRMPolicyRemediation_atManagementGroup(data),
  80. Check: resource.ComposeTestCheckFunc(
  81. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  82. resource.TestCheckResourceAttrSet(data.ResourceName, "scope"),
  83. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_assignment_id"),
  84. ),
  85. },
  86. data.ImportStep(),
  87. },
  88. })
  89. }
  90. func TestAccAzureRMPolicyRemediation_atResource(t *testing.T) {
  91. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  92. resource.ParallelTest(t, resource.TestCase{
  93. PreCheck: func() { acceptance.PreCheck(t) },
  94. Providers: acceptance.SupportedProviders,
  95. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  96. Steps: []resource.TestStep{
  97. {
  98. Config: testAccAzureRMPolicyRemediation_atResource(data),
  99. Check: resource.ComposeTestCheckFunc(
  100. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  101. resource.TestCheckResourceAttrSet(data.ResourceName, "scope"),
  102. resource.TestCheckResourceAttrSet(data.ResourceName, "policy_assignment_id"),
  103. ),
  104. },
  105. data.ImportStep(),
  106. },
  107. })
  108. }
  109. func TestAccAzureRMPolicyRemediation_updateLocation(t *testing.T) {
  110. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  111. resource.ParallelTest(t, resource.TestCase{
  112. PreCheck: func() { acceptance.PreCheck(t) },
  113. Providers: acceptance.SupportedProviders,
  114. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  115. Steps: []resource.TestStep{
  116. {
  117. Config: testAccAzureRMPolicyRemediation_atResourceGroup(data),
  118. Check: resource.ComposeTestCheckFunc(
  119. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  120. resource.TestCheckResourceAttr(data.ResourceName, "location_filters.#", "0"),
  121. ),
  122. },
  123. {
  124. Config: testAccAzureRMPolicyRemediation_updateLocation(data),
  125. Check: resource.ComposeTestCheckFunc(
  126. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  127. resource.TestCheckResourceAttr(data.ResourceName, "location_filters.#", "1"),
  128. ),
  129. },
  130. data.ImportStep(),
  131. },
  132. })
  133. }
  134. func TestAccAzureRMPolicyRemediation_requiresImport(t *testing.T) {
  135. data := acceptance.BuildTestData(t, "azurerm_policy_remediation", "test")
  136. resource.ParallelTest(t, resource.TestCase{
  137. PreCheck: func() { acceptance.PreCheck(t) },
  138. Providers: acceptance.SupportedProviders,
  139. CheckDestroy: testCheckAzureRMPolicyRemediationDestroy,
  140. Steps: []resource.TestStep{
  141. {
  142. Config: testAccAzureRMPolicyRemediation_atResourceGroup(data),
  143. Check: resource.ComposeTestCheckFunc(
  144. testCheckAzureRMPolicyRemediationExists(data.ResourceName),
  145. ),
  146. },
  147. data.RequiresImportErrorStep(testAccAzureRMPolicyRemediation_requiresImport),
  148. },
  149. })
  150. }
  151. func testCheckAzureRMPolicyRemediationExists(resourceName string) resource.TestCheckFunc {
  152. return func(s *terraform.State) error {
  153. client := acceptance.AzureProvider.Meta().(*clients.Client).Policy.RemediationsClient
  154. ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
  155. rs, ok := s.RootModule().Resources[resourceName]
  156. if !ok {
  157. return fmt.Errorf("Policy Insights Remediation not found: %s", resourceName)
  158. }
  159. id, err := parse.PolicyRemediationID(rs.Primary.ID)
  160. if err != nil {
  161. return err
  162. }
  163. if resp, err := policy.RemediationGetAtScope(ctx, client, id.Name, id.PolicyScopeId); err != nil {
  164. if utils.ResponseWasNotFound(resp.Response) {
  165. return fmt.Errorf("Bad: Policy Insights Remediation %q (Scope %q) does not exist", id.Name, id.ScopeId())
  166. }
  167. return fmt.Errorf("Bad: Get on PolicyInsights.RemediationsClient: %+v", err)
  168. }
  169. return nil
  170. }
  171. }
  172. func testCheckAzureRMPolicyRemediationDestroy(s *terraform.State) error {
  173. client := acceptance.AzureProvider.Meta().(*clients.Client).Policy.RemediationsClient
  174. ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext
  175. for _, rs := range s.RootModule().Resources {
  176. if rs.Type != "azurerm_policy_remediation" {
  177. continue
  178. }
  179. id, err := parse.PolicyRemediationID(rs.Primary.ID)
  180. if err != nil {
  181. return err
  182. }
  183. if resp, err := policy.RemediationGetAtScope(ctx, client, id.Name, id.PolicyScopeId); err != nil {
  184. if !utils.ResponseWasNotFound(resp.Response) {
  185. return fmt.Errorf("Bad: Get on Policy.RemediationsClient: %+v", err)
  186. }
  187. }
  188. return nil
  189. }
  190. return nil
  191. }
  192. func testAccAzureRMPolicyRemediation_atSubscription(data acceptance.TestData) string {
  193. return fmt.Sprintf(`
  194. provider "azurerm" {
  195. features {}
  196. }
  197. data "azurerm_subscription" "current" {}
  198. resource "azurerm_policy_definition" "test" {
  199. name = "acctestDef-%[1]s"
  200. policy_type = "Custom"
  201. mode = "All"
  202. display_name = "my-policy-definition"
  203. policy_rule = <<POLICY_RULE
  204. {
  205. "if": {
  206. "not": {
  207. "field": "location",
  208. "in": "[parameters('allowedLocations')]"
  209. }
  210. },
  211. "then": {
  212. "effect": "audit"
  213. }
  214. }
  215. POLICY_RULE
  216. parameters = <<PARAMETERS
  217. {
  218. "allowedLocations": {
  219. "type": "Array",
  220. "metadata": {
  221. "description": "The list of allowed locations for resources.",
  222. "displayName": "Allowed locations",
  223. "strongType": "location"
  224. }
  225. }
  226. }
  227. PARAMETERS
  228. }
  229. resource "azurerm_policy_assignment" "test" {
  230. name = "acctestAssign-%[1]s"
  231. scope = data.azurerm_subscription.current.id
  232. policy_definition_id = azurerm_policy_definition.test.id
  233. description = "Policy Assignment created via an Acceptance Test"
  234. display_name = "My Example Policy Assignment"
  235. parameters = <<PARAMETERS
  236. {
  237. "allowedLocations": {
  238. "value": [ "West Europe" ]
  239. }
  240. }
  241. PARAMETERS
  242. }
  243. resource "azurerm_policy_remediation" "test" {
  244. name = "acctestremediation-%[1]s"
  245. scope = azurerm_policy_assignment.test.scope
  246. policy_assignment_id = azurerm_policy_assignment.test.id
  247. }
  248. `, data.RandomString)
  249. }
  250. func testAccAzureRMPolicyRemediation_atSubscriptionWithDefinitionSet(data acceptance.TestData) string {
  251. return fmt.Sprintf(`
  252. provider "azurerm" {
  253. features {}
  254. }
  255. data "azurerm_subscription" "current" {}
  256. resource "azurerm_policy_set_definition" "test" {
  257. name = "testPolicySet-%[1]s"
  258. policy_type = "Custom"
  259. display_name = "testPolicySet-%[1]s"
  260. parameters = <<PARAMETERS
  261. {
  262. "allowedLocations": {
  263. "type": "Array",
  264. "metadata": {
  265. "description": "The list of allowed locations for resources.",
  266. "displayName": "Allowed locations",
  267. "strongType": "location"
  268. }
  269. }
  270. }
  271. PARAMETERS
  272. policy_definitions = <<POLICY_DEFINITIONS
  273. [
  274. {
  275. "parameters": {
  276. "listOfAllowedLocations": {
  277. "value": "[parameters('allowedLocations')]"
  278. }
  279. },
  280. "policyDefinitionId": "/providers/Microsoft.Authorization/policyDefinitions/e765b5de-1225-4ba3-bd56-1ac6695af988"
  281. }
  282. ]
  283. POLICY_DEFINITIONS
  284. }
  285. resource "azurerm_policy_definition" "test" {
  286. name = "acctestDef-%[1]s"
  287. policy_type = "Custom"
  288. mode = "All"
  289. display_name = "acctestDef-%[1]s"
  290. policy_rule = <<POLICY_RULE
  291. {
  292. "if": {
  293. "not": {
  294. "field": "location",
  295. "in": "[parameters('allowedLocations')]"
  296. }
  297. },
  298. "then": {
  299. "effect": "audit"
  300. }
  301. }
  302. POLICY_RULE
  303. parameters = <<PARAMETERS
  304. {
  305. "allowedLocations": {
  306. "type": "Array",
  307. "metadata": {
  308. "description": "The list of allowed locations for resources.",
  309. "displayName": "Allowed locations",
  310. "strongType": "location"
  311. }
  312. }
  313. }
  314. PARAMETERS
  315. }
  316. resource "azurerm_policy_assignment" "test" {
  317. name = "acctestAssign-%[1]s"
  318. scope = data.azurerm_subscription.current.id
  319. policy_definition_id = azurerm_policy_set_definition.test.id
  320. description = "Policy Assignment created via an Acceptance Test"
  321. display_name = "acctestAssign-%[1]s"
  322. parameters = <<PARAMETERS
  323. {
  324. "allowedLocations": {
  325. "value": [ "West Europe" ]
  326. }
  327. }
  328. PARAMETERS
  329. }
  330. resource "azurerm_policy_remediation" "test" {
  331. name = "acctestremediation-%[1]s"
  332. scope = azurerm_policy_assignment.test.scope
  333. policy_assignment_id = azurerm_policy_assignment.test.id
  334. policy_definition_reference_id = azurerm_policy_definition.test.id
  335. }
  336. `, data.RandomString)
  337. }
  338. func testAccAzureRMPolicyRemediation_atResourceGroup(data acceptance.TestData) string {
  339. return fmt.Sprintf(`
  340. provider "azurerm" {
  341. features {}
  342. }
  343. resource "azurerm_resource_group" "test" {
  344. name = "acctestRG-policy-%[1]s"
  345. location = "%[2]s"
  346. }
  347. resource "azurerm_policy_definition" "test" {
  348. name = "acctestDef-%[1]s"
  349. policy_type = "Custom"
  350. mode = "All"
  351. display_name = "my-policy-definition"
  352. policy_rule = <<POLICY_RULE
  353. {
  354. "if": {
  355. "not": {
  356. "field": "location",
  357. "in": "[parameters('allowedLocations')]"
  358. }
  359. },
  360. "then": {
  361. "effect": "audit"
  362. }
  363. }
  364. POLICY_RULE
  365. parameters = <<PARAMETERS
  366. {
  367. "allowedLocations": {
  368. "type": "Array",
  369. "metadata": {
  370. "description": "The list of allowed locations for resources.",
  371. "displayName": "Allowed locations",
  372. "strongType": "location"
  373. }
  374. }
  375. }
  376. PARAMETERS
  377. }
  378. resource "azurerm_policy_assignment" "test" {
  379. name = "acctestAssign-%[1]s"
  380. scope = azurerm_resource_group.test.id
  381. policy_definition_id = azurerm_policy_definition.test.id
  382. description = "Policy Assignment created via an Acceptance Test"
  383. display_name = "acctestAssign-%[1]s"
  384. parameters = <<PARAMETERS
  385. {
  386. "allowedLocations": {
  387. "value": [ "West Europe" ]
  388. }
  389. }
  390. PARAMETERS
  391. }
  392. resource "azurerm_policy_remediation" "test" {
  393. name = "acctestremediation-%[1]s"
  394. scope = azurerm_policy_assignment.test.scope
  395. policy_assignment_id = azurerm_policy_assignment.test.id
  396. }
  397. `, data.RandomString, data.Locations.Primary)
  398. }
  399. func testAccAzureRMPolicyRemediation_updateLocation(data acceptance.TestData) string {
  400. return fmt.Sprintf(`
  401. provider "azurerm" {
  402. features {}
  403. }
  404. resource "azurerm_resource_group" "test" {
  405. name = "acctestRG-policy-%[1]s"
  406. location = "%[2]s"
  407. }
  408. resource "azurerm_policy_definition" "test" {
  409. name = "acctestDef-%[1]s"
  410. policy_type = "Custom"
  411. mode = "All"
  412. display_name = "my-policy-definition"
  413. policy_rule = <<POLICY_RULE
  414. {
  415. "if": {
  416. "not": {
  417. "field": "location",
  418. "in": "[parameters('allowedLocations')]"
  419. }
  420. },
  421. "then": {
  422. "effect": "audit"
  423. }
  424. }
  425. POLICY_RULE
  426. parameters = <<PARAMETERS
  427. {
  428. "allowedLocations": {
  429. "type": "Array",
  430. "metadata": {
  431. "description": "The list of allowed locations for resources.",
  432. "displayName": "Allowed locations",
  433. "strongType": "location"
  434. }
  435. }
  436. }
  437. PARAMETERS
  438. }
  439. resource "azurerm_policy_assignment" "test" {
  440. name = "acctestAssign-%[1]s"
  441. scope = azurerm_resource_group.test.id
  442. policy_definition_id = azurerm_policy_definition.test.id
  443. description = "Policy Assignment created via an Acceptance Test"
  444. display_name = "My Example Policy Assignment"
  445. parameters = <<PARAMETERS
  446. {
  447. "allowedLocations": {
  448. "value": [ "West Europe" ]
  449. }
  450. }
  451. PARAMETERS
  452. }
  453. resource "azurerm_policy_remediation" "test" {
  454. name = "acctestremediation-%[1]s"
  455. scope = azurerm_policy_assignment.test.scope
  456. policy_assignment_id = azurerm_policy_assignment.test.id
  457. location_filters = ["westus"]
  458. }
  459. `, data.RandomString, data.Locations.Primary)
  460. }
  461. func testAccAzureRMPolicyRemediation_requiresImport(data acceptance.TestData) string {
  462. template := testAccAzureRMPolicyRemediation_atResourceGroup(data)
  463. return fmt.Sprintf(`
  464. %s
  465. resource "azurerm_policy_remediation" "import" {
  466. name = azurerm_policy_remediation.test.name
  467. scope = azurerm_policy_remediation.test.scope
  468. policy_assignment_id = azurerm_policy_remediation.test.policy_assignment_id
  469. }
  470. `, template)
  471. }
  472. func testAccAzureRMPolicyRemediation_atManagementGroup(data acceptance.TestData) string {
  473. return fmt.Sprintf(`
  474. provider "azurerm" {
  475. features {}
  476. }
  477. resource "azurerm_management_group" "test" {
  478. display_name = "acctest-policy-%[1]s"
  479. }
  480. resource "azurerm_policy_definition" "test" {
  481. name = "acctestDef-%[1]s"
  482. policy_type = "Custom"
  483. mode = "All"
  484. display_name = "my-policy-definition"
  485. management_group_id = azurerm_management_group.test.group_id
  486. policy_rule = <<POLICY_RULE
  487. {
  488. "if": {
  489. "not": {
  490. "field": "location",
  491. "in": "[parameters('allowedLocations')]"
  492. }
  493. },
  494. "then": {
  495. "effect": "audit"
  496. }
  497. }
  498. POLICY_RULE
  499. parameters = <<PARAMETERS
  500. {
  501. "allowedLocations": {
  502. "type": "Array",
  503. "metadata": {
  504. "description": "The list of allowed locations for resources.",
  505. "displayName": "Allowed locations",
  506. "strongType": "location"
  507. }
  508. }
  509. }
  510. PARAMETERS
  511. }
  512. resource "azurerm_policy_assignment" "test" {
  513. name = "acctestAssign-%[1]s"
  514. # scope = azurerm_resource_group.test.id
  515. # scope = data.azurerm_subscription.current.id
  516. scope = azurerm_management_group.test.id
  517. # scope = azurerm_virtual_machine.main.id
  518. policy_definition_id = azurerm_policy_definition.test.id
  519. description = "Policy Assignment created via an Acceptance Test"
  520. display_name = "My Example Policy Assignment"
  521. parameters = <<PARAMETERS
  522. {
  523. "allowedLocations": {
  524. "value": [ "West Europe" ]
  525. }
  526. }
  527. PARAMETERS
  528. }
  529. resource "azurerm_policy_remediation" "test" {
  530. name = "acctestremediation-%[1]s"
  531. scope = azurerm_policy_assignment.test.scope
  532. policy_assignment_id = azurerm_policy_assignment.test.id
  533. }
  534. `, data.RandomString)
  535. }
  536. func testAccAzureRMPolicyRemediation_atResource(data acceptance.TestData) string {
  537. return fmt.Sprintf(`
  538. provider "azurerm" {
  539. features {}
  540. }
  541. resource "azurerm_resource_group" "test" {
  542. name = "acctestRG-policy-%[1]s"
  543. location = "%[2]s"
  544. }
  545. resource "azurerm_virtual_network" "test" {
  546. name = "acctest-network-%[1]s"
  547. address_space = ["10.0.0.0/16"]
  548. location = azurerm_resource_group.test.location
  549. resource_group_name = azurerm_resource_group.test.name
  550. }
  551. resource "azurerm_subnet" "test" {
  552. name = "acctestsubnet%[1]s"
  553. resource_group_name = azurerm_resource_group.test.name
  554. virtual_network_name = azurerm_virtual_network.test.name
  555. address_prefix = "10.0.2.0/24"
  556. }
  557. resource "azurerm_network_interface" "test" {
  558. name = "acctestnic-%[1]s"
  559. location = azurerm_resource_group.test.location
  560. resource_group_name = azurerm_resource_group.test.name
  561. ip_configuration {
  562. name = "testconfiguration1"
  563. subnet_id = azurerm_subnet.test.id
  564. private_ip_address_allocation = "Dynamic"
  565. }
  566. }
  567. resource "azurerm_linux_virtual_machine" "test" {
  568. name = "acctest-vm-%[1]s"
  569. resource_group_name = azurerm_resource_group.test.name
  570. location = azurerm_resource_group.test.location
  571. size = "Standard_F2"
  572. admin_username = "adminuser"
  573. admin_password = "P@ssw0rd1234!"
  574. disable_password_authentication = false
  575. network_interface_ids = [
  576. azurerm_network_interface.test.id,
  577. ]
  578. source_image_reference {
  579. publisher = "Canonical"
  580. offer = "UbuntuServer"
  581. sku = "16.04-LTS"
  582. version = "latest"
  583. }
  584. os_disk {
  585. storage_account_type = "Standard_LRS"
  586. caching = "ReadWrite"
  587. }
  588. }
  589. resource "azurerm_policy_definition" "test" {
  590. name = "acctestDef-%[1]s"
  591. policy_type = "Custom"
  592. mode = "All"
  593. display_name = "my-policy-definition"
  594. policy_rule = <<POLICY_RULE
  595. {
  596. "if": {
  597. "not": {
  598. "field": "location",
  599. "in": "[parameters('allowedLocations')]"
  600. }
  601. },
  602. "then": {
  603. "effect": "audit"
  604. }
  605. }
  606. POLICY_RULE
  607. parameters = <<PARAMETERS
  608. {
  609. "allowedLocations": {
  610. "type": "Array",
  611. "metadata": {
  612. "description": "The list of allowed locations for resources.",
  613. "displayName": "Allowed locations",
  614. "strongType": "location"
  615. }
  616. }
  617. }
  618. PARAMETERS
  619. }
  620. resource "azurerm_policy_assignment" "test" {
  621. name = "acctestAssign-%[1]s"
  622. scope = azurerm_linux_virtual_machine.test.id
  623. policy_definition_id = azurerm_policy_definition.test.id
  624. description = "Policy Assignment created via an Acceptance Test"
  625. display_name = "My Example Policy Assignment"
  626. parameters = <<PARAMETERS
  627. {
  628. "allowedLocations": {
  629. "value": [ "West Europe" ]
  630. }
  631. }
  632. PARAMETERS
  633. }
  634. resource "azurerm_policy_remediation" "test" {
  635. name = "acctestremediation-%[1]s"
  636. scope = azurerm_policy_assignment.test.scope
  637. policy_assignment_id = azurerm_policy_assignment.test.id
  638. }
  639. `, data.RandomString, data.Locations.Primary)
  640. }