0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Terraform/Azure/azurerm_network_security_ruleについて

Last updated at Posted at 2025-02-20

azurerm_network_security_ruleについて

このリソースは、Azure のネットワークセキュリティグループ(NSG)に適用する個別のセキュリティルールを定義するために使用します。受信(Inbound)および送信(Outbound)のトラフィックを制御でき、許可(Allow)または拒否(Deny)を設定可能です。

公式ドキュメント

必須パラメータ

パラメーター名 説明
name string ルールの名前
priority number ルールの適用順
(100~4096、小さいほど優先)
direction string Inbound(受信)
Outbound(送信)
access string Allow(許可)
Deny(拒否)
protocol string Tcp、Udp、Icmp、Esp、Ah、
*(すべてのプロトコル)
source_port_range string 送信元ポートの範囲
(* で全ポート指定)
destination_port_range string 宛先ポートの範囲
* で全ポート指定)
source_address_prefix string 送信元 IP アドレスまたは範囲
(例: 10.0.0.0/24)
destination_address_prefix string 宛先 IP アドレスまたは範囲
(例: 0.0.0.0/0 は全宛先)
resource_group_name string リソースグループの名前
network_security_group_name string 適用する NSG の名前

任意パラメータ

パラメーター名 説明
description string ルールの説明
source_port_ranges list(string) 複数の送信元ポート範囲を
指定する場合に使用
destination_port_ranges list(string) 複数の宛先ポート範囲を
指定する場合に使用
source_address_prefixes list(string) 複数の送信元 IP を
指定する場合に使用
destination_address_prefixes list(string) 複数の宛先 IP を
指定する場合に使用

サンプルコード

以下は、SSH(ポート 22)を全ての送信元 IP から許可するルール を作成する Terraform の例です。

main.tf
resource "azurerm_network_security_rule" "allow_ssh" {
  name                        = "AllowSSH"
  priority                    = 100
  direction                   = "Inbound"
  access                      = "Allow"
  protocol                    = "Tcp"
  source_port_range           = "*"
  destination_port_range      = "22"
  source_address_prefix       = "0.0.0.0/0"
  destination_address_prefix  = "*"
  resource_group_name         = "example-resources"
  network_security_group_name = "example-nsg"
}
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?