用例是使用 PACKER 变量文件在“us-east-1”和“us-east-2”区域构建 AWS AMI。我可以为 NV 和 OH 区域提供两个单独的文件。但我正在尝试是否可以使用相同的变量文件来完成。
根据Packer_Var_File.json文件中变量“ PACKER_BUILD_REGION ”的值,我的打包程序构建应该只选择特定于 NV 或 OH 区域的值。任何建议如何实现这一目标?
Packer 构建命令:packer build -var-file Packer_Var_File.json Packer_Build_File.json
Packer_Var_File.json文件的详细信息如下所示
{
"PACKER_BUILD_REGION": "NV",
"1": "This Section to defined 'North Verginia' REGION SPECIFIC Varianles for AMI Build",
"!": "================================================================================",
"NV_region": "us-east-1",
"NV_vpc_id": "vpc-00112233",
"NV_subnet_id": "subnet-001122334455",
"NV_ssh_keypair_name": "NV_SSH_KEY",
"NV_ssh_private_key_file": "{{user `NV_ssh_keypair_name`}}.pem",
"NV_security_group_ids": "sg-0101010,sg-0202020,sg-03030303",
"2": "This Section to defined 'OHIO' REGION SPECIFIC Varianles for AMI Build",
"@": "======================================================================",
"OH_region": "us-east-2",
"OH_vpc_id": "vpc-33221100",
"OH_subnet_id": "subnet-554433221100",
"OH_ssh_keypair_name": "OH_SSH_KEY",
"OH_ssh_private_key_file": "{{user `OH_ssh_keypair_name`}}.pem",
"OH_security_group_ids": "sg-121314,sg-131517",
"3": "This Section to defined all COMMON Varianles for AMI Build",
"#": "==========================================================",
"KEY_region": "{{user `PACKER_BUILD_REGION`}}_region",
"KEY_vpc_id": "{{user `PACKER_BUILD_REGION`}}_vpc_id",
"KEY_subnet_id": "{{user `PACKER_BUILD_REGION`}}_subnet_id",
"KEY_source_ami": "{{user `PACKER_BUILD_REGION`}}_source_ami",
"KEY_ssh_keypair_name": "{{user `PACKER_BUILD_REGION`}}_ssh_keypair_name",
"KEY_ssh_private_key_file": "{{user `PACKER_BUILD_REGION`}}_ssh_private_key_file",
"KEY_security_group_ids": "{{user `PACKER_BUILD_REGION`}}_security_group_ids",
"region": "{{ user `KEY_region` }}",
"vpc_id": "{{user `KEY_vpc_id` }}",
"subnet_id": "{{user `KEY_subnet_id` }}",
"ssh_keypair_name": "{{user `KEY_ssh_keypair_name` }}",
"ssh_private_key_file": ".\\{{user `KEY_ssh_private_key_file`}}",
"security_group_ids": "{{user `KEY_security_group_ids` }}",
"aws_access_key": "{{env `AWS_ACCESS_KEY_ID`}}",
"aws_secret_key": "{{env `AWS_SECRET_ACCESS_KEY`}}",
"instance_type": "t3.large",
"iam_profile_name": "Agent_iam_Access",
"ami_description": "AMI on Windows Server 2019 with JDK 1.8.0_251, Chrome Driver 83.0.3987.106, Chrome Browser 83.0.3987.149, and Selenium 3.7.1 Jar",
"ami_regions": "us-east-1,us-east-2",
"ami_users": "01223334444,43322211110"
}