Skip to content

Commit

Permalink
add terraform script and workflow for create ami
Browse files Browse the repository at this point in the history
  • Loading branch information
ehearneRedHat committed Jun 26, 2024
1 parent 636a721 commit e057003
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/create-self-hosted-runner-ami.yaml
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 }}
28 changes: 28 additions & 0 deletions ami-self-hosted-runner.tf
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
}
}

Check failure on line 28 in ami-self-hosted-runner.tf

View workflow job for this annotation

GitHub Actions / EOF Newline

[EOF Newline] ami-self-hosted-runner.tf#L28

Missing newline
Raw output
ami-self-hosted-runner.tf:28: Missing newline

0 comments on commit e057003

Please sign in to comment.