Skip to content

Commit 65d1982

Browse files
authored
feat!: Refactor to use latest modules provided by terraform-aws-modules (#366)
1 parent 2200b56 commit 65d1982

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1429
-2665
lines changed

.github/.gitkeep

Whitespace-only changes.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.DS_Store
2+
13
# Local .terraform directories
24
**/.terraform/*
35

@@ -7,6 +9,7 @@
79
# .tfstate files
810
*.tfstate
911
*.tfstate.*
12+
*.tfplan
1013

1114
# Crash log files
1215
crash.log

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.76.0
3+
rev: v1.83.5
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_validate
@@ -23,6 +23,6 @@ repos:
2323
- '--args=--only=terraform_standard_module_structure'
2424
- '--args=--only=terraform_workspace_remote'
2525
- repo: https://github.com/pre-commit/pre-commit-hooks
26-
rev: v4.3.0
26+
rev: v4.5.0
2727
hooks:
2828
- id: check-merge-conflict

README.md

Lines changed: 188 additions & 397 deletions
Large diffs are not rendered by default.

docs/README.md

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Supplemental Documentation
2+
3+
## GitHub
4+
5+
### Authenticated Access via GitHub App
6+
7+
A [GitHub App](https://docs.github.com/en/apps/creating-github-apps/about-creating-github-apps/about-creating-github-apps) can be generated to provide Atlantis access instead of using a GitHub personal access token (PAT):
8+
9+
1. Create a GitHub App and give it a name - that name must be globally unique, and you can change it later if needed.
10+
2. Provide a valid Homepage URL - this can be the atlantis server url, for instance `https://atlantis.mydomain.com`
11+
3. Provide a valid [Webhook URL](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/using-webhooks-with-github-apps). The Atlantis webhook server path is located by default at `https://atlantis.mydomain.com/events`.
12+
4. Generate a [Webhook Secret](https://docs.github.com/en/webhooks/using-webhooks/validating-webhook-deliveries). This is the value supplied to the `ATLANTIS_GH_WEBHOOK_SECRET` in the Atlantis server configuration.
13+
5. Generate a Private Key. This is the value supplied to the `ATLANTIS_GH_APP_KEY` in the Atlantis server configuration.
14+
6. On the App's settings page (at the top) you find the App ID. This is the value supplied to `ATLANTIS_GH_APP_ID` in the Atlantis server configuration.
15+
7. On the Permissions & Events you need to setup all the permissions and events according to [Atlantis documentation](https://www.runatlantis.io/docs/access-credentials.html#github-app)
16+
17+
Now you need to [install the App](https://docs.github.com/en/apps/using-github-apps/installing-your-own-github-app) on your organization.
18+
19+
A self-provisioned GitHub App usually has two parts: the App and the Installation.
20+
21+
The App part is the first step and its where you setup all the requirements, such as authentication, webhook, permissions, etc... The Installation part is where you add the created App to an organization/personal-account. It is on the installation page where you setup which repositories the application can access and receive events from.
22+
23+
Once you have your GitHub App registered you will be able to access/manage the required parameters either through `environment` or `secret` (we strongly suggest supplying these through `secret`):
24+
25+
```hcl
26+
module "atlantis" {
27+
source = "terraform-aws-modules/atlantis/aws"
28+
29+
# Truncated for brevity ...
30+
31+
# ECS Container Definition
32+
atlantis = {
33+
secrets = [
34+
{
35+
name = "ATLANTIS_GH_APP_ID"
36+
valueFrom = "<SECRETSMANAGER_ARN>"
37+
},
38+
{
39+
name = "ATLANTIS_GH_APP_KEY"
40+
valueFrom = "<SECRETSMANAGER_ARN>"
41+
},
42+
{
43+
name = "ATLANTIS_GH_WEBHOOK_SECRET"
44+
valueFrom = "<SECRETSMANAGER_ARN>"
45+
},
46+
]
47+
}
48+
}
49+
```
50+
51+
## GitLab
52+
53+
> TODO
54+
55+
## BitBucket
56+
57+
> TODO

examples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Examples
2+
3+
Please note - the examples provided serve two primary means:
4+
5+
1. Show users working examples of the various ways in which the module can be configured and features supported
6+
2. A means of testing/validating module changes
7+
8+
Please do not mistake the examples provided as "best practices". It is up to users to consult the AWS service documentation for best practices, usage recommendations, etc.

examples/github-complete/README.md

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,70 @@
1-
# Complete Atlantis example with GitHub App and Webhooks
1+
# Complete GitHub example
22

3-
Configuration in this directory creates the necessary infrastructure and resources for running Atlantis on Fargate plus GitHub repository webhooks configured to Atlantis URL.
4-
5-
An existing Route53 hosted zone and domain is required to deploy this example.
3+
Configuration in this directory provisions Atlantis on ECS with EFS storage, ALB, Route53 record and GitHub repository webhooks.
64

75
## Usage
86

97
To run this code you need to copy `terraform.tfvars.sample` into `terraform.tfvars` and update the values locally or specify them using environment variables (`TF_VAR_github_app_id=xxx`, `TF_VAR_github_owner=xxx`, etc.). Ensure that `bootstrap_github_app` is `true`. Once ready, execute:
108

119
```bash
12-
$ terraform init
13-
$ terraform plan
14-
$ terraform apply
10+
terraform init
11+
terraform plan
12+
terraform apply
1513
```
1614

17-
Terraform will output a URL to setup a new Github App via Atlantis, which should look something like https://$ATLANTIS_HOST/github-app/setup. Open that URL and go through the setup process. Before closing the window, click the link to install the new GitHub App on you repositories and copy the values `github_app_id`, `github_app_key`, and `github_webhook_secret` into `terraform.tfvars`. You should also set `bootstrap_github_app` to `false` . Now execute:
18-
19-
```bash
20-
$ terraform plan
21-
$ terraform apply
22-
23-
```
24-
25-
Note - if you receive the following error when running apply:
26-
27-
`Error: InvalidParameterException: The new ARN and resource ID format must be enabled to add tags to the service. Opt in to the new format and try again. "atlantiscomplete"`
28-
29-
Go to https://eu-west-1.console.aws.amazon.com/ecs/home?region=eu-west-1#/settings (update for your region of use) and change `Container instance`, `Service`, and `Task` to `Enabled`.
30-
31-
⚠️ This example will create resources which cost money. Run `terraform destroy` when you don't need these resources. ⚠️
15+
Note that this example may create resources which cost money. Run `terraform destroy` when you don't need these resources.
3216

3317
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
3418
## Requirements
3519

3620
| Name | Version |
3721
|------|---------|
38-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
39-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.69 |
40-
| <a name="requirement_github"></a> [github](#requirement\_github) | >= 4.8 |
22+
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
23+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.0 |
24+
| <a name="requirement_github"></a> [github](#requirement\_github) | >= 5.0 |
25+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
4126

4227
## Providers
4328

4429
| Name | Version |
4530
|------|---------|
46-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.69 |
31+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.0 |
32+
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
4733

4834
## Modules
4935

5036
| Name | Source | Version |
5137
|------|--------|---------|
5238
| <a name="module_atlantis"></a> [atlantis](#module\_atlantis) | ../../ | n/a |
53-
| <a name="module_atlantis_access_log_bucket"></a> [atlantis\_access\_log\_bucket](#module\_atlantis\_access\_log\_bucket) | terraform-aws-modules/s3-bucket/aws | ~> 3.0 |
39+
| <a name="module_github_repository_webhooks"></a> [github\_repository\_webhooks](#module\_github\_repository\_webhooks) | ../../modules/github-repository-webhook | n/a |
40+
| <a name="module_secrets_manager"></a> [secrets\_manager](#module\_secrets\_manager) | terraform-aws-modules/secrets-manager/aws | ~> 1.0 |
41+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 |
5442

5543
## Resources
5644

5745
| Name | Type |
5846
|------|------|
59-
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
60-
| [aws_elb_service_account.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/elb_service_account) | data source |
61-
| [aws_iam_policy_document.atlantis_access_log_bucket_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
62-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
47+
| [random_password.webhook_secret](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
48+
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
49+
| [aws_route53_zone.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/route53_zone) | data source |
6350

6451
## Inputs
6552

6653
| Name | Description | Type | Default | Required |
6754
|------|-------------|------|---------|:--------:|
68-
| <a name="input_alb_ingress_cidr_blocks"></a> [alb\_ingress\_cidr\_blocks](#input\_alb\_ingress\_cidr\_blocks) | List of IPv4 CIDR ranges to use on all ingress rules of the ALB - use your personal IP in the form of `x.x.x.x/32` for restricted testing | `list(string)` | n/a | yes |
69-
| <a name="input_bootstrap_github_app"></a> [bootstrap\_github\_app](#input\_bootstrap\_github\_app) | Flag to configure Atlantis to bootstrap a new Github App | `bool` | n/a | yes |
55+
| <a name="input_atlantis_github_user"></a> [atlantis\_github\_user](#input\_atlantis\_github\_user) | GitHub user or organization name | `string` | n/a | yes |
56+
| <a name="input_atlantis_repo_allowlist"></a> [atlantis\_repo\_allowlist](#input\_atlantis\_repo\_allowlist) | List of GitHub repositories that Atlantis will be allowed to access | `list(string)` | n/a | yes |
7057
| <a name="input_domain"></a> [domain](#input\_domain) | Route53 domain name to use for ACM certificate. Route53 zone for this domain should be created in advance | `string` | n/a | yes |
71-
| <a name="input_github_app_id"></a> [github\_app\_id](#input\_github\_app\_id) | GitHub App ID that is running the Atlantis command | `string` | n/a | yes |
72-
| <a name="input_github_app_key"></a> [github\_app\_key](#input\_github\_app\_key) | The PEM encoded private key for the GitHub App | `string` | n/a | yes |
73-
| <a name="input_github_owner"></a> [github\_owner](#input\_github\_owner) | Github owner | `string` | n/a | yes |
74-
| <a name="input_github_repo_names"></a> [github\_repo\_names](#input\_github\_repo\_names) | List of Github repositories that should be monitored by Atlantis | `list(string)` | n/a | yes |
75-
| <a name="input_github_webhook_secret"></a> [github\_webhook\_secret](#input\_github\_webhook\_secret) | Webhook secret | `string` | n/a | yes |
58+
| <a name="input_github_owner"></a> [github\_owner](#input\_github\_owner) | Github owner to use when creating webhook | `string` | n/a | yes |
59+
| <a name="input_github_token"></a> [github\_token](#input\_github\_token) | Github token to use when creating webhook | `string` | n/a | yes |
7660

7761
## Outputs
7862

7963
| Name | Description |
8064
|------|-------------|
81-
| <a name="output_atlantis_github_app_setup_url"></a> [atlantis\_github\_app\_setup\_url](#output\_atlantis\_github\_app\_setup\_url) | URL to create a new Github App with Atlantis |
82-
| <a name="output_atlantis_repo_allowlist"></a> [atlantis\_repo\_allowlist](#output\_atlantis\_repo\_allowlist) | Git repositories where webhook should be created |
65+
| <a name="output_alb"></a> [alb](#output\_alb) | ALB created and all of its associated outputs |
8366
| <a name="output_atlantis_url"></a> [atlantis\_url](#output\_atlantis\_url) | URL of Atlantis |
84-
| <a name="output_ecs_task_definition"></a> [ecs\_task\_definition](#output\_ecs\_task\_definition) | Task definition for ECS service (used for external triggers) |
85-
| <a name="output_task_role_arn"></a> [task\_role\_arn](#output\_task\_role\_arn) | The Atlantis ECS task role arn |
67+
| <a name="output_cluster"></a> [cluster](#output\_cluster) | ECS cluster created and all of its associated outputs |
68+
| <a name="output_efs"></a> [efs](#output\_efs) | EFS created and all of its associated outputs |
69+
| <a name="output_service"></a> [service](#output\_service) | ECS service created and all of its associated |
8670
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

0 commit comments

Comments
 (0)