-
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
- Loading branch information
1 parent
636a721
commit e057003
Showing
2 changed files
with
58 additions
and
0 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,30 @@ | ||
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: | | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
access_key = var.aws_access_key | ||
secret_key = var.aws_secret_key | ||
} | ||
|
||
variable instance_id { | ||
description = "ID for EC2 instance (self-hosted-runner)" | ||
type = string | ||
} | ||
|
||
data "aws_instance" "self_hosted_runner_instance" { | ||
instance_id = var.instance_id | ||
} | ||
|
||
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 | ||
} | ||
} | ||