Skip to content

Commit

Permalink
Use source_ami_filter for RHEL 7 (#14)
Browse files Browse the repository at this point in the history
* Use source_ami_filter instead of hard-coded source_ami ID

* Include deleting snapshot and deregister ami if AMI already exist

* Change default region to Canada Central

* Add Publish RHEL AMI step in workflow

* Fix working-dir path

* Change default region for ubuntu
  • Loading branch information
pranavmalaviya committed Dec 14, 2021
1 parent cab9eeb commit 667aa2c
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/publish-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ jobs:
uses: hashicorp-contrib/setup-packer@v1

- name: Publish Ubuntu-20.04 AMI
working-directory: ubuntu/ubuntu-20-04
working-directory: aws/ubuntu/ubuntu-20-04
run: |
packer init -upgrade ubuntu-focal.pkr.hcl
packer build -var-file="config.auto.pkrvars.hcl" .
- name: Publish Ubuntu-18.04 AMI
working-directory: ubuntu/ubuntu-18-04
working-directory: aws/ubuntu/ubuntu-18-04
run: |
packer init -upgrade ubuntu-bionic.pkr.hcl
packer build -var-file="config.auto.pkrvars.hcl" .
- name: Publish RHEL7 AMI
working-directory: aws/rhel/rhel7
run: |
packer init -upgrade rhel7.pkr.hcl
packer build -var-file="config.auto.pkrvars.hcl" .
2 changes: 1 addition & 1 deletion aws/rhel/rhel7/config.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws_access_key = ""
aws_secret_key = ""
aws_region = "us-west-2"
aws_region = "ca-central-1"
12 changes: 11 additions & 1 deletion aws/rhel/rhel7/rhel7.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,18 @@ source "amazon-ebs" "rhel7" {
region = "${var.aws_region}"
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
source_ami = "ami-02d40d11bb3aaf3e5"
source_ami_filter {
filters = {
name = "RHEL-7*-x86_64-*"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["309956199498"]
}
ssh_username = "ec2-user"
force_deregister = true
force_delete_snapshot = true
}

build {
Expand Down
2 changes: 1 addition & 1 deletion aws/ubuntu/ubuntu-18-04/config.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws_access_key = ""
aws_secret_key = ""
aws_region = "us-west-2"
aws_region = "ca-central-1"
2 changes: 1 addition & 1 deletion aws/ubuntu/ubuntu-20-04/config.auto.pkrvars.hcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws_access_key = ""
aws_secret_key = ""
aws_region = "us-west-2"
aws_region = "ca-central-1"

0 comments on commit 667aa2c

Please sign in to comment.