1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Terraform で Azure API Management を何度も作り直す時に便利なパージを入れてみた

1
Posted at

Azure API Management など、いくつかの Azure リソースは、リソースを削除して一定の期間 Soft Delete な状態になります。おそらく、誤って当該リソースを削除した時にセキュリティ的な観点で、元に戻す必要があるからだと思われます。同じリソース名でクリーンな環境を再度作成したい場合は、Purge してから作成することになります。そこで今回は、Terraform の設定で、リソース削除時に Purge まで行い、再度同じリソース名で作成できるか試してみました。

検証用 Terraform コード

main.tf
provider "azurerm" {
  features {
    api_management {
      purge_soft_delete_on_destroy = true
    }
  }
}

resource "azurerm_resource_group" "rg" {
  name     = "mnrapifn-rg"
  location = "japaneast"
}

resource "azurerm_api_management" "apim" {
  name                = "mnrapifn-apim"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  publisher_name      = "test"
  publisher_email     = "test@example.com"
  sku_name            = "Consumption_0"
}

Terraform を実行して動作確認

bash
$ terraform init

$ terraform plan

$ terraform apply -auto-approve

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

$ terraform destroy -auto-approve

Destroy complete! Resources: 2 destroyed.

$ terraform apply -auto-approve

Apply complete! Resources: 2 added, 0 changed, 0 destroyed.

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?