Skip to content

Commit fbc818c

Browse files
authored
feat: Add an IAM policy for deploying to each documentation prefix. (#20)
1 parent 17d3d28 commit fbc818c

File tree

6 files changed

+53
-5
lines changed

6 files changed

+53
-5
lines changed

.github/workflows/docs.yaml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
- 'docs/**'
1515
- 'mkdocs.yaml'
1616
- '.github/workflows/docs.yaml'
17+
- '*.md'
1718
branches:
1819
- main
1920

@@ -22,8 +23,8 @@ permissions:
2223

2324
jobs:
2425
deploy:
25-
name: Deploy Documentation to ${{ inputs.environment }}
26-
environment: ${{ inputs.environment }}
26+
name: Deploy Documentation to ${{ inputs.environment || 'development'}}
27+
environment: ${{ inputs.environment || 'development'}}
2728
runs-on: ubuntu-latest
2829
steps:
2930
- uses: actions/checkout@v4
@@ -43,6 +44,13 @@ jobs:
4344
path: .cache
4445
restore-keys: |
4546
mkdocs-material-
46-
- run: pip install mkdocs-material markdown-callouts mdx_truly_sane_lists mkdocs-nav-weight pymdown-extensions
47+
- name: Install python dependencies
48+
run: |
49+
pip install \
50+
mkdocs-material \
51+
markdown-callouts \
52+
mdx_truly_sane_lists \
53+
mkdocs-nav-weight \
54+
pymdown-extensions
4755
- run: mkdocs build
4856
- run: aws s3 sync ./site "s3://${{ env.DOCS_BUCKET || 'docs.dev.services.cfa.codes' }}/${{ env.PREFIX || 'shared-services' }}"

tofu/config/development/docs/main.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ module "docs" {
1616
domain = "dev.services.cfa.codes"
1717
subdomain = "docs"
1818

19+
# TODO: Get these from app specs.
20+
prefixes = [
21+
"cmr-entity-resolution",
22+
"document-transfer-service",
23+
"shared-services",
24+
"tax-benefits-backend",
25+
"tofu-modules"
26+
]
27+
1928
# Use the same VPC we use for shared hosting.
2029
# TODO: Use data resources to look this up.
2130
logging_bucket = "shared-services-development-logs"

tofu/modules/docs/files/rewrite-function.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function handler(event) {
2-
var request = event.request;
3-
var uri = request.uri;
2+
const request = event.request;
3+
const uri = request.uri;
44

55
// If the request is being made to a directory (e.g. / or /docs), we want to
66
// append "index.html" so that S3 serves the proper object. If the path

tofu/modules/docs/iam.tf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
resource "aws_iam_policy" "prefix" {
2+
for_each = var.prefixes
3+
4+
name = "${local.prefix}-deploy-${each.value}"
5+
path = "/"
6+
description = "Allow deploy access to ${each.value} in the documentation bucket"
7+
8+
policy = jsonencode(yamldecode(templatefile("${path.module}/templates/prefix-policy.yaml.tftpl", {
9+
bucket_arn : module.bucket.arn,
10+
prefix : each.value
11+
})))
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Version: "2012-10-17"
2+
Statement:
3+
- Sid: DocumentationPrefixPolicy
4+
Effect: Allow
5+
Action:
6+
- s3:PutObject
7+
- s3:GetObject
8+
- s3:ListBucket
9+
- s3:DeleteObject
10+
- s3:GetBucketLocation
11+
Resource:
12+
- ${bucket_arn}
13+
- ${bucket_arn}/${prefix}/*

tofu/modules/docs/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ variable "logging_bucket" {
2626
type = string
2727
}
2828

29+
variable "prefixes" {
30+
description = "A list of prefixes to create access policies for."
31+
type = set(string)
32+
default = []
33+
}
34+
2935
variable "subdomain" {
3036
description = "The subdomain for the documentation hosting."
3137
type = string

0 commit comments

Comments
 (0)