|
1 |
| -# Copyright 2023-2024 The MathWorks Inc. |
| 1 | +# Copyright 2023-2024 The MathWorks, Inc. |
2 | 2 |
|
3 | 3 | # The following variables may have different value across releases and
|
4 | 4 | # it is recommended to modify them via the release-specific configuration file.
|
@@ -29,15 +29,10 @@ variable "RELEASE" {
|
29 | 29 | }
|
30 | 30 | }
|
31 | 31 |
|
32 |
| -variable "BASE_AMI" { |
| 32 | +variable "BASE_AMI_NAME" { |
33 | 33 | type = string
|
34 |
| - default = "ami-07543813a68cc4fe9" |
35 |
| - description = "Default AMI ID refers to the Ubuntu Server 22.04 image provided by Canonical." |
36 |
| - |
37 |
| - validation { |
38 |
| - condition = substr(var.BASE_AMI, 0, 4) == "ami-" |
39 |
| - error_message = "The BASE_AMI must start with \"ami-\"." |
40 |
| - } |
| 34 | + default = "ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" |
| 35 | + description = "Default AMI name refers to the Ubuntu Server 22.04 image provided by Canonical." |
41 | 36 | }
|
42 | 37 |
|
43 | 38 | variable "BUILD_SCRIPTS" {
|
@@ -136,6 +131,8 @@ variable "AMI_TAGS" {
|
136 | 131 | Name = "Packer Build"
|
137 | 132 | Build = "MATLAB"
|
138 | 133 | Type = "matlab-on-aws"
|
| 134 | + Base_AMI_ID = "{{ .SourceAMI }}" |
| 135 | + Base_AMI_Name = "{{ .SourceAMIName }}" |
139 | 136 | }
|
140 | 137 | description = "The tags Packer adds to the resultant machine image."
|
141 | 138 | }
|
@@ -169,7 +166,15 @@ source "amazon-ebs" "AMI_Builder" {
|
169 | 166 | volume_type = "gp2"
|
170 | 167 | }
|
171 | 168 | region = "us-east-1"
|
172 |
| - source_ami = "${var.BASE_AMI}" |
| 169 | + source_ami_filter { |
| 170 | + filters = { |
| 171 | + "virtualization-type" = "hvm" |
| 172 | + "name" = "${var.BASE_AMI_NAME}" |
| 173 | + "root-device-type" = "ebs" |
| 174 | + } |
| 175 | + owners = ["099720109477"] # Canonical's owner ID https://documentation.ubuntu.com/aws/en/latest/aws-how-to/instances/find-ubuntu-images/ |
| 176 | + most_recent = true |
| 177 | + } |
173 | 178 | ssh_username = "ubuntu"
|
174 | 179 | run_tags = "${var.INSTANCE_TAGS}"
|
175 | 180 | tags = "${var.AMI_TAGS}"
|
@@ -235,6 +240,8 @@ build {
|
235 | 240 | specified_products = "${var.PRODUCTS}"
|
236 | 241 | specified_spkgs = "${var.SPKGS}"
|
237 | 242 | build_scripts = join(", ", "${var.BUILD_SCRIPTS}")
|
| 243 | + base_ami_id = "{{ .SourceAMI }}" |
| 244 | + base_ami_name = "{{ .SourceAMIName }}" |
238 | 245 | }
|
239 | 246 | }
|
240 | 247 | }
|
0 commit comments