My Home NW Lab

逸般の誤家庭のネットワーク

TerraformからCatalyst 8000V (AWS版)の最新AMI IDの取得

TerraformからCatalyst 8000V (AWS版)の最新AMI IDを取得するための情報を整理しました。 特に filter 条件の指定に必要な情報に焦点を当てております。

2022年12月頃の Latest Version: 17.09.01a をベースに調査しております。

AWS MarketplaceのCatalyst 8000Vの情報

AWS Marketplaceには何種類かのCatalyst 8000Vが登録されておりますが主に候補となる3種類に絞りました。

AWS MarketplaceのCatalyst 8000V

本記事内で取り扱うCatalyst 8000Vは下記の3種類になります。

BYOL は Bring Your Own License の略でライセンス持ち込み型です。
PAYG は Pay-As-You-Go の略でライセンスの持ち込みは不要の従量課金型です。Cisco TAC support servicesは含まれていないため別途契約が必要になります。

Catalyst 8000VのAMIの情報

Catalyst 8000VのAMI IDを特定するための情報を整理します。

製品名 product_code_id Description (一例) AMI name (一例)
Cisco Catalyst 8000V Edge Software - BYOL 3ycwqehancx46bkpb3xkifiz5 Cisco-C8K-.17.09.01a Cisco-C8K-17.09.01a-42cb6e93-8d9d-490b-a73c-e3e56077ffd1
Cisco Catalyst 8000V Edge Software - PAYG - DNA Essentials k585h9fyh5prlazwh3vb0yh3 Cisco-C8K-.17.09.01a Cisco-C8K-PAYG-ESS-17.09.01a-0973be0f-17dc-43c1-9677-13348bbfe587
Cisco Catalyst 8000V Edge Software - PAYG - DNA Advantage cmhzse1i97ex4pkmb26dxhz2j Cisco-C8K-.17.09.01a Cisco-C8K-PAYG-ADV-17.09.01a-d54057d8-928f-4bf1-b2f7-15b344cec0cb

Catalyst 8000VのAMI情報における製品種別の特定

補足: PAYG版のサブスクライブ時のエラー

PAYG版のDNA EssentialsとDNA Advantageは、下記のエラーが表示されて筆者の場合はサブスクライブが出来ませんでした。

The seller has not made this product available in the geo location associated with your customer account.

PAYG版のサブスクライブ時のエラー

Cisco ASAvの情報ではありますが、下記に該当している可能性があります。

community.cisco.com

以下エラーでサブスクライブができない件についてコメントさせていただきます。

Error : The seller has not made this product available in the geo location associated with your customer account.

残念ながら、税制上の理由で、日本のアカウントのお持ちの方は、現在、ASAv Standard Package の新規サブスクライブが許可されてません。

そのため、新規サブスクライブ時は当制限のない ASAv BYOL で代用して頂くか、もしくは、グローバル企業に勤務されている方は ASAv Standard Package の利用が可能な場合がございます。

結局のところ筆者はPAYG版のデプロイは行えませんでしたが、filter 条件にBYOL版を指定する際にPAYG版の情報が引っかからないようにするために本記事では比較情報としてPAYG版の情報も掲載しております。

AMIの product_code_id の確認方法

BYOL版の Cisco Catalyst 8000V Edge Software - BYOL に関しては実際にデプロイして Products codes (product_code_type + product_code_id) の情報より確認しました。

Cisco Catalyst 8000V Edge Software - BYOL の Products codes

PAYG版の Cisco Catalyst 8000V Edge Software - PAYG - DNA EssentialsCisco Catalyst 8000V Edge Software - PAYG - DNA Advantage に関しては、AWS ConsoleのEC2の設定画面よりメニュー: Images > AMIs から Cisco-C8K-. で検索して該当のものを特定しました。

EC2の設定画面のメニュー: Images > AMIs

また、AWS Marketplaceの各製品のHTMLソース コードを見ると、offerARN の情報の一部に product_code_id が含まれていたので合致するか確認しております。HTMLソース コードより確認する方法は、筆者が独自に確認しただけであり、正式な方法ではないと思われるので注意してください。

"offerARN":"arn:aws:catalog:us-east-1::offer/3ycwqehancx46bkpb3xkifiz5/version/1",

AWS MarketplaceのHTMLソース コードからの「product_code_id」の類推

TerraformのCatalyst 8000VのAMI情報取得コード

TerraformでCatalyst 8000Vの最新AMI情報を取得するためのサンプル コードを掲載します。

まず前提情報ですが、製品種別を特定するために、product_code_idproduct_code_type の要素によって成り立っている product_codesfilter の条件指定に用いています。

      + product_codes         = [
          + {
              + product_code_id   = "3ycwqehancx46bkpb3xkifiz5"
              + product_code_type = "marketplace"
            },
        ]

TerraformでのCatalyst 8000Vの製品種別指定

AMI IDはRegionによって変わるので注意してください。本例ではRegionに ap-northeast-1 (Tokyo) を指定しています。 本サンプル コードでは3種類のAMIの情報を順に出力します。

# hashicorp/aws | Terraform Registry
# https://registry.terraform.io/providers/hashicorp/aws/latest
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
}

provider "aws" {
  region = "ap-northeast-1"
}

# AWS Marketplace: Cisco Catalyst 8000V Edge Software - BYOL
# https://aws.amazon.com/marketplace/pp/prodview-rohvq2cjd4ccg
data "aws_ami" "c8000v-byol" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "name"
    values = ["Cisco-C8K-*"]
  }

  filter {
    name   = "product-code"
    values = ["3ycwqehancx46bkpb3xkifiz5"]
  }

  filter {
    name   = "state"
    values = ["available"]
  }
}

# AWS Marketplace: Cisco Catalyst 8000V Edge Software - PAYG - DNA Essentials
# https://aws.amazon.com/marketplace/pp/prodview-o4o5hbn3kjyym
data "aws_ami" "c8000v-payg-ess" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "name"
    values = ["Cisco-C8K-PAYG-ESS-*"]
  }

  filter {
    name   = "product-code"
    values = ["k585h9fyh5prlazwh3vb0yh3"]
  }

  filter {
    name   = "state"
    values = ["available"]
  }
}

# AWS Marketplace: Cisco Catalyst 8000V Edge Software - PAYG - DNA Advantage
# https://aws.amazon.com/marketplace/pp/prodview-cjzny6dzcbrom
data "aws_ami" "c8000v-payg-adv" {
  most_recent = true
  owners      = ["aws-marketplace"]

  filter {
    name   = "name"
    values = ["Cisco-C8K-PAYG-ADV-*"]
  }

  filter {
    name   = "product-code"
    values = ["cmhzse1i97ex4pkmb26dxhz2j"]
  }

  filter {
    name   = "state"
    values = ["available"]
  }
}

output "c8000v-byol-ami-info" {
  description = "Cisco Catalyst 8000V Edge Software - BYOL"
  value       = data.aws_ami.c8000v-byol
}

output "c8000v-payg-ess-ami-info" {
  description = "Cisco Catalyst 8000V Edge Software - PAYG - DNA Essentials"
  value       = data.aws_ami.c8000v-payg-ess
}

output "c8000v-payg-adv-ami-info" {
  description = "Cisco Catalyst 8000V Edge Software - PAYG - DNA Advantage"
  value       = data.aws_ami.c8000v-payg-adv
}

筆者はTerraformの実行環境をAWS Cloud9に用意して確認しました。 上述のコードを main.tf ファイルとして保存して下記のコマンドで実行しております。

terraform init

terraform plan

AWS Cloud9上での実行例

Terraformのサンプル コードの出力例

サンプル コードを terraform plan で実行した際の出力例を掲載します。

ec2-user:~/environment $ terraform plan
data.aws_ami.c8000v-payg-ess: Reading...
data.aws_ami.c8000v-payg-adv: Reading...
data.aws_ami.c8000v-byol: Reading...
data.aws_ami.c8000v-payg-adv: Read complete after 1s [id=ami-04e8a322004495372]
data.aws_ami.c8000v-payg-ess: Read complete after 1s [id=ami-0007e399b265b580b]
data.aws_ami.c8000v-byol: Read complete after 1s [id=ami-0a6f4f867117f37c4]

Changes to Outputs:
  + c8000v-byol-ami-info     = {
      + architecture          = "x86_64"
      + arn                   = "arn:aws:ec2:ap-northeast-1::image/ami-0a6f4f867117f37c4"
      + block_device_mappings = [
          + {
              + device_name  = "/dev/xvda"
              + ebs          = {
                  + "delete_on_termination" = "true"
                  + "encrypted"             = "false"
                  + "iops"                  = "0"
                  + "snapshot_id"           = "snap-0a03c87047e46d19e"
                  + "throughput"            = "0"
                  + "volume_size"           = "16"
                  + "volume_type"           = "gp2"
                }
              + no_device    = ""
              + virtual_name = ""
            },
        ]
      + boot_mode             = ""
      + creation_date         = "2022-09-12T20:05:47.000Z"
      + deprecation_time      = "2024-09-12T20:05:47.000Z"
      + description           = "Cisco-C8K-.17.09.01a"
      + ena_support           = true
      + executable_users      = null
      + filter                = [
          + {
              + name   = "name"
              + values = [
                  + "Cisco-C8K-*",
                ]
            },
          + {
              + name   = "product-code"
              + values = [
                  + "3ycwqehancx46bkpb3xkifiz5",
                ]
            },
          + {
              + name   = "state"
              + values = [
                  + "available",
                ]
            },
        ]
      + hypervisor            = "xen"
      + id                    = "ami-0a6f4f867117f37c4"
      + image_id              = "ami-0a6f4f867117f37c4"
      + image_location        = "aws-marketplace/Cisco-C8K-17.09.01a-42cb6e93-8d9d-490b-a73c-e3e56077ffd1"
      + image_owner_alias     = "aws-marketplace"
      + image_type            = "machine"
      + imds_support          = ""
      + include_deprecated    = false
      + kernel_id             = ""
      + most_recent           = true
      + name                  = "Cisco-C8K-17.09.01a-42cb6e93-8d9d-490b-a73c-e3e56077ffd1"
      + name_regex            = null
      + owner_id              = "679593333241"
      + owners                = [
          + "aws-marketplace",
        ]
      + platform              = ""
      + platform_details      = "Linux/UNIX"
      + product_codes         = [
          + {
              + product_code_id   = "3ycwqehancx46bkpb3xkifiz5"
              + product_code_type = "marketplace"
            },
        ]
      + public                = true
      + ramdisk_id            = ""
      + root_device_name      = "/dev/xvda"
      + root_device_type      = "ebs"
      + root_snapshot_id      = "snap-0a03c87047e46d19e"
      + sriov_net_support     = "simple"
      + state                 = "available"
      + state_reason          = {
          + "code"    = "UNSET"
          + "message" = "UNSET"
        }
      + tags                  = {}
      + timeouts              = null
      + tpm_support           = ""
      + usage_operation       = "RunInstances"
      + virtualization_type   = "hvm"
    }
  + c8000v-payg-adv-ami-info = {
      + architecture          = "x86_64"
      + arn                   = "arn:aws:ec2:ap-northeast-1::image/ami-04e8a322004495372"
      + block_device_mappings = [
          + {
              + device_name  = "/dev/xvda"
              + ebs          = {
                  + "delete_on_termination" = "true"
                  + "encrypted"             = "false"
                  + "iops"                  = "0"
                  + "snapshot_id"           = "snap-01c52d7b01334c29e"
                  + "throughput"            = "0"
                  + "volume_size"           = "16"
                  + "volume_type"           = "gp2"
                }
              + no_device    = ""
              + virtual_name = ""
            },
        ]
      + boot_mode             = ""
      + creation_date         = "2022-09-12T19:51:43.000Z"
      + deprecation_time      = "2024-09-12T19:51:43.000Z"
      + description           = "Cisco-C8K-.17.09.01a"
      + ena_support           = true
      + executable_users      = null
      + filter                = [
          + {
              + name   = "name"
              + values = [
                  + "Cisco-C8K-PAYG-ADV-*",
                ]
            },
          + {
              + name   = "product-code"
              + values = [
                  + "cmhzse1i97ex4pkmb26dxhz2j",
                ]
            },
          + {
              + name   = "state"
              + values = [
                  + "available",
                ]
            },
        ]
      + hypervisor            = "xen"
      + id                    = "ami-04e8a322004495372"
      + image_id              = "ami-04e8a322004495372"
      + image_location        = "aws-marketplace/Cisco-C8K-PAYG-ADV-17.09.01a-d54057d8-928f-4bf1-b2f7-15b344cec0cb"
      + image_owner_alias     = "aws-marketplace"
      + image_type            = "machine"
      + imds_support          = ""
      + include_deprecated    = false
      + kernel_id             = ""
      + most_recent           = true
      + name                  = "Cisco-C8K-PAYG-ADV-17.09.01a-d54057d8-928f-4bf1-b2f7-15b344cec0cb"
      + name_regex            = null
      + owner_id              = "679593333241"
      + owners                = [
          + "aws-marketplace",
        ]
      + platform              = ""
      + platform_details      = "Linux/UNIX"
      + product_codes         = [
          + {
              + product_code_id   = "cmhzse1i97ex4pkmb26dxhz2j"
              + product_code_type = "marketplace"
            },
        ]
      + public                = true
      + ramdisk_id            = ""
      + root_device_name      = "/dev/xvda"
      + root_device_type      = "ebs"
      + root_snapshot_id      = "snap-01c52d7b01334c29e"
      + sriov_net_support     = "simple"
      + state                 = "available"
      + state_reason          = {
          + "code"    = "UNSET"
          + "message" = "UNSET"
        }
      + tags                  = {}
      + timeouts              = null
      + tpm_support           = ""
      + usage_operation       = "RunInstances"
      + virtualization_type   = "hvm"
    }
  + c8000v-payg-ess-ami-info = {
      + architecture          = "x86_64"
      + arn                   = "arn:aws:ec2:ap-northeast-1::image/ami-0007e399b265b580b"
      + block_device_mappings = [
          + {
              + device_name  = "/dev/xvda"
              + ebs          = {
                  + "delete_on_termination" = "true"
                  + "encrypted"             = "false"
                  + "iops"                  = "0"
                  + "snapshot_id"           = "snap-01303431805713aa2"
                  + "throughput"            = "0"
                  + "volume_size"           = "16"
                  + "volume_type"           = "gp2"
                }
              + no_device    = ""
              + virtual_name = ""
            },
        ]
      + boot_mode             = ""
      + creation_date         = "2022-09-12T19:58:48.000Z"
      + deprecation_time      = "2024-09-12T19:58:48.000Z"
      + description           = "Cisco-C8K-.17.09.01a"
      + ena_support           = true
      + executable_users      = null
      + filter                = [
          + {
              + name   = "name"
              + values = [
                  + "Cisco-C8K-PAYG-ESS-*",
                ]
            },
          + {
              + name   = "product-code"
              + values = [
                  + "k585h9fyh5prlazwh3vb0yh3",
                ]
            },
          + {
              + name   = "state"
              + values = [
                  + "available",
                ]
            },
        ]
      + hypervisor            = "xen"
      + id                    = "ami-0007e399b265b580b"
      + image_id              = "ami-0007e399b265b580b"
      + image_location        = "aws-marketplace/Cisco-C8K-PAYG-ESS-17.09.01a-0973be0f-17dc-43c1-9677-13348bbfe587"
      + image_owner_alias     = "aws-marketplace"
      + image_type            = "machine"
      + imds_support          = ""
      + include_deprecated    = false
      + kernel_id             = ""
      + most_recent           = true
      + name                  = "Cisco-C8K-PAYG-ESS-17.09.01a-0973be0f-17dc-43c1-9677-13348bbfe587"
      + name_regex            = null
      + owner_id              = "679593333241"
      + owners                = [
          + "aws-marketplace",
        ]
      + platform              = ""
      + platform_details      = "Linux/UNIX"
      + product_codes         = [
          + {
              + product_code_id   = "k585h9fyh5prlazwh3vb0yh3"
              + product_code_type = "marketplace"
            },
        ]
      + public                = true
      + ramdisk_id            = ""
      + root_device_name      = "/dev/xvda"
      + root_device_type      = "ebs"
      + root_snapshot_id      = "snap-01303431805713aa2"
      + sriov_net_support     = "simple"
      + state                 = "available"
      + state_reason          = {
          + "code"    = "UNSET"
          + "message" = "UNSET"
        }
      + tags                  = {}
      + timeouts              = null
      + tpm_support           = ""
      + usage_operation       = "RunInstances"
      + virtualization_type   = "hvm"
    }

You can apply this plan to save these new output values to the Terraform state, without changing any real infrastructure.

───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
ec2-user:~/environment $ 

image_id の値より、AMI IDが確認できます。 出力例の内容を整理すると下記の表のようになっております。

製品名 Version: 17.09.01a のAMI ID
Cisco Catalyst 8000V Edge Software - BYOL ami-0a6f4f867117f37c4 (Region: ap-northeast-1)
Cisco Catalyst 8000V Edge Software - PAYG - DNA Essentials ami-04e8a322004495372 (Region: ap-northeast-1)
Cisco Catalyst 8000V Edge Software - PAYG - DNA Advantage ami-0007e399b265b580b (Region: ap-northeast-1)

関連ドキュメント