Skip to content

Commit a2d81bc

Browse files
author
jsf9k
committed
Merge https://github.com/cisagov/skeleton-packer into lineage/skeleton
# Conflicts: # .github/workflows/build.yml # .github/workflows/prerelease.yml # .github/workflows/release.yml # README.md # ami_arm64.pkr.hcl # ami_x86_64.pkr.hcl # terraform-post-packer/main.tf # version.txt
2 parents 55205a8 + b702664 commit a2d81bc

20 files changed

+258
-121
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ jobs:
227227
uses: mxschmitt/action-tmate@v3
228228
if: env.RUN_TMATE
229229
build:
230+
environment: dev-a
230231
# The AMI build process is an expensive test (in terms of time) so
231232
# let's not run it unless the other jobs succeed.
232233
needs:
@@ -291,7 +292,7 @@ jobs:
291292
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
292293
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
293294
aws-region: ${{ env.AWS_DEFAULT_REGION }}
294-
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME_STAGING }}
295+
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME }}
295296
role-duration-seconds: 3600
296297
# When called by Packer, Ansible will find /usr/bin/python3 and
297298
# use it; therefore, we must ensure that /usr/bin/python3 points
@@ -307,13 +308,16 @@ jobs:
307308
- name: Install Packer plugins
308309
run: packer init .
309310
- name: Create machine image
310-
# This runs through the AMI creation process but does not
311-
# actually create an AMI
312311
run: |
313312
packer build -only amazon-ebs.${{ matrix.architecture }} \
314313
-timestamp-ui \
314+
<<<<<<< HEAD
315315
-var build_bucket=${{ secrets.THIRD_PARTY_BUCKET_STAGING }} \
316316
-var skip_create_ami=true \
317+
=======
318+
-var github_ref_name=${{ github.ref_name }} \
319+
-var github_sha=${{ github.sha }} \
320+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
317321
.
318322
- name: Remove /usr/bin/python3 symlink to the installed Python
319323
run: |

.github/workflows/prerelease.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
name: Dump context
3838
uses: crazy-max/ghaction-dump-context@v2
3939
prerelease:
40+
environment: staging-a
4041
needs:
4142
- diagnostics
4243
permissions:
@@ -90,15 +91,15 @@ jobs:
9091
python -m pip install --upgrade pip
9192
pip install --upgrade \
9293
--requirement requirements.txt
93-
- name: Install ansible roles
94+
- name: Install Ansible roles
9495
run: ansible-galaxy install --force --role-file ansible/requirements.yml
9596
- name: Assume AWS build role
9697
uses: aws-actions/configure-aws-credentials@v4
9798
with:
9899
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
99100
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
100101
aws-region: ${{ env.AWS_DEFAULT_REGION }}
101-
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME_STAGING }}
102+
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME }}
102103
role-duration-seconds: 3600
103104
# When called by Packer, Ansible will find /usr/bin/python3 and
104105
# use it; therefore, we must ensure that /usr/bin/python3 points
@@ -123,7 +124,12 @@ jobs:
123124
run: |
124125
packer build -only amazon-ebs.${{ matrix.architecture }} \
125126
-timestamp-ui \
127+
<<<<<<< HEAD
126128
-var build_bucket=${{ secrets.THIRD_PARTY_BUCKET_STAGING }} \
129+
=======
130+
-var github_ref_name=${{ github.ref_name }} \
131+
-var github_sha=${{ github.sha }} \
132+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
127133
-var is_prerelease=${{ github.event.release.prerelease }} \
128134
-var release_tag=${{ github.event.release.tag_name }} \
129135
-var release_url=${{ github.event.release.html_url }} \

.github/workflows/release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ jobs:
4444
name: Dump context
4545
uses: crazy-max/ghaction-dump-context@v2
4646
release:
47+
environment: production
4748
needs:
4849
- diagnostics
4950
permissions:
@@ -97,7 +98,7 @@ jobs:
9798
python -m pip install --upgrade pip
9899
pip install --upgrade \
99100
--requirement requirements.txt
100-
- name: Install ansible roles
101+
- name: Install Ansible roles
101102
run: ansible-galaxy install --force --role-file ansible/requirements.yml
102103
# Do not copy the AMI to other regions until we have figured out a
103104
# workable mechanism for creating and managing AMI KMS keys in other
@@ -113,7 +114,7 @@ jobs:
113114
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
114115
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
115116
aws-region: ${{ env.AWS_DEFAULT_REGION }}
116-
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME_PRODUCTION }}
117+
role-to-assume: ${{ secrets.BUILD_ROLE_TO_ASSUME }}
117118
role-duration-seconds: 3600
118119
# When called by Packer, Ansible will find /usr/bin/python3 and
119120
# use it; therefore, we must ensure that /usr/bin/python3 points
@@ -138,7 +139,12 @@ jobs:
138139
run: |
139140
packer build -only amazon-ebs.${{ matrix.architecture }} \
140141
-timestamp-ui \
142+
<<<<<<< HEAD
141143
-var build_bucket=${{ secrets.THIRD_PARTY_BUCKET_PRODUCTION }} \
144+
=======
145+
-var github_ref_name=${{ github.ref_name }} \
146+
-var github_sha=${{ github.sha }} \
147+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
142148
-var is_prerelease=${{ github.event.release.prerelease }} \
143149
-var release_tag=${{ github.event.release.tag_name }} \
144150
-var release_url=${{ github.event.release.html_url }} \

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ dist
1919
.terraform.lock.hcl
2020
terraform.tfstate
2121
terraform.tfstate.backup
22+
*.tfconfig
2223
*.tfvars

README.md

Lines changed: 144 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,63 @@ next steps. Note that you will need to know where your team stores their
2828
remote profile data in order to use
2929
[`aws-profile-sync`](https://github.com/cisagov/aws-profile-sync).
3030

31-
To create the build user, follow these instructions:
31+
### Creating a build user ###
3232

33-
```console
34-
cd terraform-build-user
35-
terraform init --upgrade=true
36-
terraform apply
37-
```
33+
You will need to create a build user for each environment that you use. The
34+
following steps show how to create a build user for an environment named "dev".
35+
You will need to repeat this process for any additional environments.
36+
37+
1. Change into the `terraform-build-user` directory:
38+
39+
```console
40+
cd terraform-build-user
41+
```
42+
43+
1. Create a backend configuration file named `dev.tfconfig` containing the
44+
name of the bucket where "dev" environment Terraform state is stored - this file
45+
is required to initialize the Terraform backend in each environment:
46+
47+
```hcl
48+
bucket = "my-dev-terraform-state-bucket"
49+
```
50+
51+
1. Initialize the Terraform backend for the "dev" environment using your backend
52+
configuration file:
53+
54+
```console
55+
terraform init -backend-config=dev.tfconfig
56+
```
3857

39-
Once the user is created you will need to update the
58+
> [!NOTE]
59+
> When performing this step for additional environments (i.e. not your first
60+
> environment), use the `-reconfigure` flag:
61+
>
62+
> ```console
63+
> terraform init -backend-config=other-env.tfconfig -reconfigure
64+
> ```
65+
66+
1. Create a Terraform variables file named `dev.tfvars` containing all
67+
required variables (currently only `terraform_state_bucket`):
68+
69+
```hcl
70+
terraform_state_bucket = "my-dev-terraform-state-bucket"
71+
```
72+
73+
1. Create a Terraform workspace for the "dev" environment:
74+
75+
```console
76+
terraform workspace new dev
77+
```
78+
79+
1. Initialize and upgrade the Terraform workspace, then apply the configuration
80+
to create the build user in the "dev" environment:
81+
82+
```console
83+
terraform init -upgrade=true
84+
terraform apply -var-file=dev.tfvars
85+
```
86+
87+
Once the build user is created you will need to update the
4088
[repository's secrets](https://help.github.com/en/actions/configuring-and-managing-workflows/creating-and-storing-encrypted-secrets)
4189
with the new encrypted environment variables. This should be done using the
4290
[`terraform-to-secrets`](https://github.com/cisagov/development-guide/tree/develop/project_setup#terraform-iam-credentials-to-github-secrets-)
@@ -55,7 +103,7 @@ IMPORTANT: The account where your images will be built must have a VPC and
55103
a public subnet both tagged with the name "AMI Build", otherwise `packer`
56104
will not be able to build images.
57105

58-
## Building the Image ##
106+
## Building the image ##
59107

60108
### Using GitHub Actions ###
61109

@@ -66,21 +114,23 @@ will not be able to build images.
66114
GitHub Actions can build this project in three different modes depending on
67115
how the build was triggered from GitHub.
68116

69-
1. **Non-release test**: After a normal commit or pull request GitHub Actions
70-
will build the project, and run tests and validation on the
71-
Packer template. It will **not** build an image.
72-
1. **Pre-release deploy**: Publish a GitHub release
73-
with the "This is a pre-release" checkbox checked. An image will be built
74-
and deployed using the [`prerelease`](.github/workflows/prerelease.yml)
75-
workflow. This should be configured to deploy the image to a single region
76-
using a non-production account (e.g. "staging").
77-
1. **Production release deploy**: Publish a GitHub release with
78-
the "This is a pre-release" checkbox unchecked. An image will be built
79-
and deployed using the [`release`](.github/workflows/release.yml)
80-
workflow. This should be configured to deploy the image to multiple regions
81-
using a production account.
82-
83-
### Using Your Local Environment ###
117+
1. **Development release**: After a normal commit and also on a pull request,
118+
GitHub Actions will run tests and validation on the Packer template, and then
119+
build the project. An image will be built and deployed using the
120+
[`build`](.github/workflows/build.yml) workflow. This should be configured
121+
to deploy the image to a single region using a development account.
122+
1. **Pre-release**: Publish a GitHub release with the "This is a pre-release"
123+
checkbox checked. An image will be built and deployed using the
124+
[`prerelease`](.github/workflows/prerelease.yml) workflow. This should be
125+
configured to deploy the image to a single region using a non-production
126+
account (e.g. "staging").
127+
1. **Production release**: Publish a GitHub release with the "This is a
128+
pre-release" checkbox unchecked. An image will be built and deployed using
129+
the [`release`](.github/workflows/release.yml) workflow. This should be
130+
configured to deploy the image to multiple regions using a production
131+
account.
132+
133+
### Using your local environment ###
84134

85135
Packer will use your
86136
[standard AWS environment](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html)
@@ -139,21 +189,73 @@ region_kms_keys = {
139189
AWS_PROFILE=cool-images-ec2amicreate-openvpn-packer packer build --timestamp-ui -var-file release.pkrvars.hcl .
140190
```
141191

142-
### Giving Other AWS Accounts Permission to Launch the Image ###
192+
### Giving other AWS accounts permission to launch the image ###
143193

144194
After the AMI has been successfully created, you may want to allow other
195+
<<<<<<< HEAD
145196
accounts in your AWS organization permission to launch it. For this project,
146197
we want to allow the "Shared Services" account to launch the
147198
most-recently-created AMI. To do that, follow these instructions, noting that
148199
"ENVIRONMENT_TYPE" below should be replaced with where the AMI was created
149200
(e.g "production", "staging", etc.):
201+
=======
202+
accounts in your AWS organization permission to launch it. The following steps
203+
show how to do this for an environment named "dev". You will need to repeat this
204+
process for any additional environments.
205+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
150206
151-
```console
152-
cd terraform-post-packer
153-
terraform workspace select ENVIRONMENT_TYPE
154-
terraform init --upgrade=true
155-
terraform apply
156-
```
207+
> [!NOTE]
208+
> Refer to the `ami_share_account_name_regex` variable if you want to customize
209+
> which accounts in your AWS organization to share your AMI with.
210+
211+
1. Change into the `terraform-post-packer` directory:
212+
213+
```console
214+
cd terraform-post-packer
215+
```
216+
217+
1. Create a backend configuration file named `dev.tfconfig` containing the
218+
name of the bucket where "dev" environment Terraform state is stored - this file
219+
is required to initialize the Terraform backend in each environment:
220+
221+
```hcl
222+
bucket = "my-dev-terraform-state-bucket"
223+
```
224+
225+
1. Initialize the Terraform backend for the "dev" environment using your backend
226+
configuration file:
227+
228+
```console
229+
terraform init -backend-config=dev.tfconfig
230+
```
231+
232+
> [!NOTE]
233+
> When performing this step for additional environments (i.e. not your first
234+
> environment), use the `-reconfigure` flag:
235+
>
236+
> ```console
237+
> terraform init -backend-config=other-env.tfconfig -reconfigure
238+
> ```
239+
240+
1. If not already created, create a Terraform workspace for the "dev" environment:
241+
242+
```console
243+
terraform workspace new dev
244+
```
245+
246+
Otherwise, switch to the existing "dev" workspace:
247+
248+
```console
249+
terraform workspace select dev
250+
```
251+
252+
1. Initialize and upgrade the Terraform workspace, then apply the configuration
253+
to share the AMI with accounts in the "dev" environment:
254+
255+
```console
256+
terraform init -upgrade=true
257+
terraform apply
258+
```
157259

158260
<!-- BEGIN_TF_DOCS -->
159261
## Requirements ##
@@ -185,6 +287,8 @@ No modules.
185287
| build\_bucket | The S3 bucket containing the CDM tool installers. | `string` | `""` | no |
186288
| build\_region | The region in which to retrieve the base AMI from and build the new AMI. | `string` | `"us-east-1"` | no |
187289
| build\_region\_kms | The ID or ARN of the KMS key to use for AMI encryption. | `string` | `"alias/cool-amis"` | no |
290+
| github\_ref\_name | The GitHub short ref name to use for the tags applied to the created AMI. | `string` | `""` | no |
291+
| github\_sha | The GitHub commit SHA to use for the tags applied to the created AMI. | `string` | `""` | no |
188292
| is\_prerelease | The pre-release status to use for the tags applied to the created AMI. | `bool` | `false` | no |
189293
| region\_kms\_keys | A map of regions to copy the created AMI to and the KMS keys to use for encryption in that region. The keys for this map must match the values provided to the aws\_regions variable. Example: {"us-east-1": "alias/example-kms"} | `map(string)` | `{}` | no |
190294
| release\_tag | The GitHub release tag to use for the tags applied to the created AMI. | `string` | `""` | no |
@@ -196,6 +300,16 @@ No modules.
196300
No outputs.
197301
<!-- END_TF_DOCS -->
198302

303+
<<<<<<< HEAD
304+
=======
305+
## New repositories from a skeleton ##
306+
307+
Please see our [Project Setup guide](https://github.com/cisagov/development-guide/tree/develop/project_setup)
308+
for step-by-step instructions on how to start a new repository from
309+
a skeleton. This will save you time and effort when configuring a
310+
new repository!
311+
312+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
199313
## Contributing ##
200314

201315
We welcome contributions! Please see [`CONTRIBUTING.md`](CONTRIBUTING.md) for

ami_arm64.pkr.hcl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ source "amazon-ebs" "arm64" {
2525
tags = {
2626
Application = "OpenVPN"
2727
Architecture = "arm64"
28+
<<<<<<< HEAD
2829
Base_AMI_Name = data.amazon-ami.ubuntu_noble_arm64.name
2930
GitHub_Release_URL = var.release_url
3031
OS_Version = "Ubuntu Noble Numbat"
32+
=======
33+
Base_AMI_Name = data.amazon-ami.debian_bookworm_arm64.name
34+
GitHub_Ref_Name = var.github_ref_name
35+
GitHub_Release_URL = var.release_url
36+
GitHub_SHA = var.github_sha
37+
OS_Version = "Debian Bookworm"
38+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
3139
Pre_Release = var.is_prerelease
3240
Release = var.release_tag
3341
Team = "VM Fusion - Development"

ami_x86_64.pkr.hcl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ source "amazon-ebs" "x86_64" {
2525
tags = {
2626
Application = "OpenVPN"
2727
Architecture = "x86_64"
28+
<<<<<<< HEAD
2829
Base_AMI_Name = data.amazon-ami.ubuntu_noble_x86_64.name
2930
GitHub_Release_URL = var.release_url
3031
OS_Version = "Ubuntu Noble Numbat"
32+
=======
33+
Base_AMI_Name = data.amazon-ami.debian_bookworm_x86_64.name
34+
GitHub_Ref_Name = var.github_ref_name
35+
GitHub_Release_URL = var.release_url
36+
GitHub_SHA = var.github_sha
37+
OS_Version = "Debian Bookworm"
38+
>>>>>>> b702664447def7d112564cadeda1ebe32e064c2d
3139
Pre_Release = var.is_prerelease
3240
Release = var.release_tag
3341
Team = "VM Fusion - Development"

bump-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ if [ -n "$label" ] && [ "$with_prerelease" = false ] && [[ ! " ${commands_with_l
125125
invalid_option "Setting the label is only allowed for the following commands: ${commands_with_label[*]}"
126126
fi
127127

128-
if [ "$with_prerelease" = true ] && [[ ! " ${commands_with_prerelease[*]} " =~ [[:space:]]${bump_part}[[:space:]] ]]; then
128+
if [ "$with_prerelease" = true ] && [ -n "$bump_part" ] && [[ ! " ${commands_with_prerelease[*]} " =~ [[:space:]]${bump_part}[[:space:]] ]]; then
129129
invalid_option "Changing the prerelease is only allowed in conjunction with the following commands: ${commands_with_prerelease[*]}"
130130
fi
131131

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ansible>=10,<11
4141
ansible-core>=2.17
4242
boto3
4343
docopt
44+
# The bump-version script requires at least version 3 of semver.
4445
semver>=3
4546
setuptools
4647
wheel

0 commit comments

Comments
 (0)