Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit bb7346b

Browse files
bshelton229npalm
andauthored
feat(packer): Allow passing in an instance_profile to packer (#4278)
We ran into needing to pass a custom instance profile to packer in order to get AWS IAM credentials for pre-pulling some ECR images. I noticed what I think was a missing `instance_type` override variable in the windows-core-2022 file. I'm not sure if that was an oversight, or if it was omitted for a reason. It's been a long time since I've been proficient in Windows, so I wasn't able to test that part of this very well. Thanks so much for this project, this has been immensely beneficial for us. --------- Co-authored-by: Niek Palm <[email protected]>
1 parent 1282e11 commit bb7346b

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

Diff for: images/linux-al2023/github_agent.linux.pkr.hcl

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "instance_type" {
4242
default = "m3.medium"
4343
}
4444

45+
variable "iam_instance_profile" {
46+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
47+
type = string
48+
default = ""
49+
}
50+
4551
variable "root_volume_size_gb" {
4652
type = number
4753
default = 8
@@ -98,6 +104,7 @@ locals {
98104
source "amazon-ebs" "githubrunner" {
99105
ami_name = "github-runner-al2023-x86_64-${formatdate("YYYYMMDDhhmm", timestamp())}"
100106
instance_type = var.instance_type
107+
iam_instance_profile = var.iam_instance_profile
101108
region = var.region
102109
security_group_id = var.security_group_id
103110
subnet_id = var.subnet_id

Diff for: images/ubuntu-focal/github_agent.ubuntu.pkr.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "instance_type" {
4242
default = "t3.medium"
4343
}
4444

45+
variable "iam_instance_profile" {
46+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
47+
type = string
48+
default = ""
49+
}
50+
4551
variable "root_volume_size_gb" {
4652
type = number
4753
default = 8
@@ -98,6 +104,7 @@ locals {
98104
source "amazon-ebs" "githubrunner" {
99105
ami_name = "github-runner-ubuntu-focal-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}"
100106
instance_type = var.instance_type
107+
iam_instance_profile = var.iam_instance_profile
101108
region = var.region
102109
security_group_id = var.security_group_id
103110
subnet_id = var.subnet_id
@@ -200,6 +207,7 @@ build {
200207
"sudo chmod +x /var/lib/cloud/scripts/per-boot/start-runner.sh",
201208
]
202209
}
210+
203211
post-processor "manifest" {
204212
output = "manifest.json"
205213
strip_path = true

Diff for: images/ubuntu-jammy-arm64/github_agent.ubuntu.pkr.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "instance_type" {
4242
default = "t4g.small"
4343
}
4444

45+
variable "iam_instance_profile" {
46+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
47+
type = string
48+
default = ""
49+
}
50+
4551
variable "root_volume_size_gb" {
4652
type = number
4753
default = 8
@@ -98,6 +104,7 @@ locals {
98104
source "amazon-ebs" "githubrunner" {
99105
ami_name = "github-runner-ubuntu-jammy-arm64-${formatdate("YYYYMMDDhhmm", timestamp())}"
100106
instance_type = var.instance_type
107+
iam_instance_profile = var.iam_instance_profile
101108
region = var.region
102109
security_group_id = var.security_group_id
103110
subnet_id = var.subnet_id
@@ -200,6 +207,7 @@ build {
200207
"sudo chmod +x /var/lib/cloud/scripts/per-boot/start-runner.sh",
201208
]
202209
}
210+
203211
post-processor "manifest" {
204212
output = "manifest.json"
205213
strip_path = true

Diff for: images/ubuntu-jammy/github_agent.ubuntu.pkr.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ variable "instance_type" {
4242
default = "t3.medium"
4343
}
4444

45+
variable "iam_instance_profile" {
46+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
47+
type = string
48+
default = ""
49+
}
50+
4551
variable "root_volume_size_gb" {
4652
type = number
4753
default = 8
@@ -98,6 +104,7 @@ locals {
98104
source "amazon-ebs" "githubrunner" {
99105
ami_name = "github-runner-ubuntu-jammy-amd64-${formatdate("YYYYMMDDhhmm", timestamp())}"
100106
instance_type = var.instance_type
107+
iam_instance_profile = var.iam_instance_profile
101108
region = var.region
102109
security_group_id = var.security_group_id
103110
subnet_id = var.subnet_id
@@ -200,6 +207,7 @@ build {
200207
"sudo chmod +x /var/lib/cloud/scripts/per-boot/start-runner.sh",
201208
]
202209
}
210+
203211
post-processor "manifest" {
204212
output = "manifest.json"
205213
strip_path = true

Diff for: images/windows-core-2019/github_agent.windows.pkr.hcl

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ variable "instance_type" {
2424
default = "t3a.medium"
2525
}
2626

27+
variable "iam_instance_profile" {
28+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
29+
type = string
30+
default = ""
31+
}
32+
2733
variable "ebs_delete_on_termination" {
2834
description = "Indicates whether the EBS volume is deleted on instance termination."
2935
type = bool
@@ -64,6 +70,7 @@ source "amazon-ebs" "githubrunner" {
6470
ami_name = "github-runner-windows-core-2019-${formatdate("YYYYMMDDhhmm", timestamp())}"
6571
communicator = "winrm"
6672
instance_type = var.instance_type
73+
iam_instance_profile = var.iam_instance_profile
6774
region = var.region
6875
associate_public_ip_address = var.associate_public_ip_address
6976
temporary_security_group_source_public_ip = var.temporary_security_group_source_public_ip
@@ -114,6 +121,7 @@ build {
114121
})
115122
], var.custom_shell_commands)
116123
}
124+
117125
post-processor "manifest" {
118126
output = "manifest.json"
119127
strip_path = true

Diff for: images/windows-core-2022/github_agent.windows.pkr.hcl

+14-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ variable "region" {
1818
default = "eu-west-1"
1919
}
2020

21+
variable "instance_type" {
22+
description = "The instance type Packer will use for the builder"
23+
type = string
24+
default = "m4.xlarge"
25+
}
26+
27+
variable "iam_instance_profile" {
28+
description = "IAM instance profile Packer will use for the builder. An empty string (default) means no profile will be assigned."
29+
type = string
30+
default = ""
31+
}
32+
2133
variable "security_group_id" {
2234
description = "The ID of the security group Packer will associate with the builder to enable access"
2335
type = string
@@ -74,7 +86,8 @@ locals {
7486
source "amazon-ebs" "githubrunner" {
7587
ami_name = "github-runner-windows-core-2022-${formatdate("YYYYMMDDhhmm", timestamp())}"
7688
communicator = "winrm"
77-
instance_type = "m4.xlarge"
89+
instance_type = var.instance_type
90+
iam_instance_profile = var.iam_instance_profile
7891
region = var.region
7992
security_group_id = var.security_group_id
8093
subnet_id = var.subnet_id

0 commit comments

Comments
 (0)