-
Notifications
You must be signed in to change notification settings - Fork 33
32 lines (26 loc) · 1.32 KB
/
create-self-hosted-runner-ami.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 }}