Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jpalomaki
Copy link
Contributor

@jpalomaki jpalomaki commented Oct 13, 2022

πŸ‘‹

Use case: we build custom runner AMIs periodically (as new actions/runner versions are released), and we have disabled auto-updates on the runners (to keep things predictable and fast). Now the problem is that currently we need to re-apply the runner terraform config, to pick up a newly-built AMI (since it is looked up by the terraform data source).

This PR introduces an option to have the scale up lambda look up the runner AMI ID from an SSM parameter at runner instance launch time, thereby allowing us to update the AMI, without having to re-apply runner stacks.

To make this work fully automated, we'd also amend our AMI build workflow to update this AMI ID SSM parameter, as a new AMI version is built. Then it would be automatically picked up by the runner stack.

This PR is a draft for now, because I assume we'd need to add some tests and amend documentation if this feature is seen as merge-worthy.

I have quickly smoke-tested the happy path in an actual GitHub repo/AWS account.

Let me know what you think.

Thanks,
Jukka

@jpalomaki jpalomaki changed the title Add support for looking up pre-built runner AMI ID from an SSM parameter at instance launch time feat(runners):add support for looking up pre-built runner AMI ID from an SSM parameter at instance launch time Oct 13, 2022
@jpalomaki jpalomaki changed the title feat(runners):add support for looking up pre-built runner AMI ID from an SSM parameter at instance launch time feat(runners): add support for looking up pre-built runner AMI ID from an SSM parameter at instance launch time Oct 13, 2022
@GuptaNavdeep1983
Copy link

@jpalomaki the PR looks nice, can you add some more tests around this PR to meet the coverage goals, its failing the build.

@jpalomaki jpalomaki marked this pull request as ready for review October 14, 2022 18:26
@jpalomaki
Copy link
Contributor Author

jpalomaki commented Oct 14, 2022

@GuptaNavdeep1983 Added some tests

Copy link
Member

@npalm npalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice, need to test and added some comments. Can you also add the default example with a commented out part to show how the AMI override works?

@npalm
Copy link
Member

npalm commented Oct 21, 2022

@jpalomaki did you had time to check our comments?

@jpalomaki
Copy link
Contributor Author

@jpalomaki did you had time to check our comments?

@npalm Not yet (I was afk this week). I will have a look at them on Monday. πŸ‘

@jpalomaki
Copy link
Contributor Author

@npalm @GuptaNavdeep1983 Comments addressed. Let me know what you think

@jpalomaki
Copy link
Contributor Author

@npalm

Can you also add the default example with a commented out part to show how the AMI override works?

This is now also done in philips-labs/terraform-aws-github-runner@8fe47d6

Copy link
Member

@npalm npalm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good. Test the PR on top of the default example with the code below:

module "runners" {
  ...
  ami_id_ssm_parameter_name = aws_ssm_parameter.runner_enable_cloudwatch.name
}

data "aws_ami" "runner" {
  most_recent = "true"

  filter {
      name   = "name"
      values = ["amzn2-ami-kernel-5.*-hvm-2.0.202209*-x86_64-gp*"] # some older AMI
  }

  owners = ["amazon"]
}

resource "aws_ssm_parameter" "runner_enable_cloudwatch" {
  name  = "/${local.environment}/runners/ami"
  type  = "String"
  value =  data.aws_ami.runner.image_id
}

@npalm npalm merged commit 68e2381 into github-aws-runners:develop Oct 31, 2022
forest-releaser bot pushed a commit that referenced this pull request Oct 31, 2022
@jpalomaki jpalomaki deleted the dynamic-runner-ami-id branch October 31, 2022 19:49
"ssm:GetParameter"
],
"Resource": [
"arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/${trimprefix(var.ami_id_ssm_parameter_name, "/")}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the partition might need to be parameterized here, so that it can run in the various govcloud implementations
(I believe it's already part of some of the options passed in to various modules, maybe not this one)

npalm pushed a commit that referenced this pull request Nov 17, 2022
npalm pushed a commit that referenced this pull request Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants