-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add terraform script and workflow for create ami
e e e e create ami e e final touches :)
- Loading branch information
1 parent
636a721
commit 4bdee2b
Showing
4 changed files
with
76 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: Create Self Hosted Runner AMI | ||
|
||
on: | ||
push: | ||
paths: | ||
- self-hosted-runner.tf | ||
|
||
jobs: | ||
create-self-hosted-runner-ami: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: hashicorp/setup-terraform@v3 | ||
|
||
- name: Initialize Terraform Environment | ||
run: | | ||
terraform init | ||
- name: Create PEM file | ||
run: | | ||
echo "${{ secrets.AWS_PEM_KEY }}" > ${{ secrets.AWS_KEY_NAME }}.pem | ||
chmod 400 ${{ secrets.AWS_KEY_NAME }}.pem | ||
- name: Apply Terraform Configuration | ||
run: | | ||
terraform apply -auto-approve -var=aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }} -var=aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }} -var=aws_key_name=${{ secrets.AWS_KEY_NAME }} | ||
- name: Destroy Terraform Configuration (should retain AMI from config) | ||
run: | | ||
# Remove AMI from terraform so it does not destroy | ||
terraform state rm aws_ami_from_instance.self_hosted_runner_ami | ||
terraform destroy -auto-approve -var=aws_access_key=${{ secrets.AWS_ACCESS_KEY_ID }} -var=aws_secret_key=${{ secrets.AWS_SECRET_ACCESS_KEY }} -var=aws_key_name=${{ secrets.AWS_KEY_NAME }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
data "aws_instance" "self_hosted_runner_instance" { | ||
instance_id = aws_instance.self_hosted_runner.id | ||
depends_on = [ null_resource.wait_for_user_data ] | ||
} | ||
|
||
resource "aws_ami_from_instance" "self_hosted_runner_ami" { | ||
name = "self-hosted-runner-ami" | ||
source_instance_id = data.aws_instance.self_hosted_runner_instance.id | ||
description = "An AMI created from an existing EC2 instance which contains the environment needed for self-hosted runner on kuadrant-operator." | ||
|
||
tags = { | ||
Name = "self-hosted-runner-ami" | ||
} | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
|
||
depends_on = [ null_resource.wait_for_user_data ] | ||
} | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters