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?

TerraformでFortiGate(FortiOS)をIaC管理する

Posted at

はじめに

今回は FortiGate(FortiOS)をTerraformで管理する方法 を紹介します。

環境

項目 内容
Terraform v1.12.1
Provider fortinetdev/fortios 1.23.0
FortiGate OS v7.6.4 build3596
動作環境 Windows11 の VMware Workstation Pro 17

FortiGateでの準備

まずはTerraformからFortiGateを操作できるようにするための準備を行います。

管理者ユーザーを作成

Terraform用にAPIアクセス可能な管理者プロファイル、管理者を作成します。

管理者プロファイル

システム > 管理者プロファイル > 新規作成
名前:任意
アクセスコントロールは全て読み書き可
image.png

管理者ユーザー

システム > 管理者 > 新規作成 > REST API 管理者
ユーザー名:任意
管理者プロファイル:上で作成したプロファイル
PKIグループ:OFF
image.png

APIトークンを発行

管理者ユーザー作成後APIアクセスキーが発行されます。
image.png

Terraformの設定

次にTerraform側の設定を行います。
まずはprovider.tfを作成します。

provider.tf
terraform {
  required_providers {
    fortios = {
      source  = "fortinetdev/fortios"
    }
  }
}

provider "fortios" {
  hostname = "192.168.11.19" #FortiosにアクセスできるIPやFQDN
  token    = "fqpzhwyqqxw8j7H4pyhbGHxHHN8y9N" #先ほど作成したAPIアクセスキー
  insecure = true #trueの場合、アクセスするときに証明書を必要としません。
}

実際にリソースを作成する

例として、Firewall Address をTerraformで作成してみます。

main.tf
resource "fortios_firewall_address" "this" {
  name                 = "OCI_OS_OSAKA"
  color                = 2
  associated_interface = ""
  subnet               = "134.70.80.0 255.255.252.0"
  type                 = "ipmask"
  allow_routing        = "disable"
  comment              = "OCI 東京リージョン オブジェクトストレージ"
}

保存後、以下のコマンドを実行します:

terraform init
terraform plan
terraform apply

成功すると、FortiGate上にOCI_OS_OSAKAというアドレスオブジェクトが作成されます。

image.png

まとめ

このように、GUIで行っていたポリシー作成もコード化できます。
設定のコード化という意味ではFortiOS独自のAPIやCLIもありますが、terraformがわかっていれば学習コストの削減ができると思います。

参考資料

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?