Skip to content

Commit 4b91755

Browse files
author
Timothée Aufort
committed
feat: test live coding 6
1 parent 50589aa commit 4b91755

25 files changed

+581
-4
lines changed

.amazonq/agents/default.json

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "q_ide_default",
3+
"description": "Default agent configuration",
4+
"prompt": "",
5+
"mcpServers": {
6+
"terraform": {
7+
"command": "docker",
8+
"args": [
9+
"run",
10+
"-i",
11+
"--rm",
12+
"hashicorp/terraform-mcp-server:0.3"
13+
]
14+
}
15+
},
16+
"tools": [
17+
"fs_read",
18+
"execute_bash",
19+
"fs_write",
20+
"report_issue",
21+
"use_aws",
22+
"@terraform",
23+
"fsRead",
24+
"fsWrite",
25+
"fsReplace",
26+
"listDirectory",
27+
"fileSearch",
28+
"executeBash",
29+
"codeReview",
30+
"displayFindings"
31+
],
32+
"toolAliases": {},
33+
"allowedTools": [
34+
"fs_read",
35+
"report_issue",
36+
"use_aws",
37+
"execute_bash",
38+
"fs_write",
39+
"fsRead",
40+
"listDirectory",
41+
"fileSearch",
42+
"codeReview",
43+
"displayFindings"
44+
],
45+
"toolsSettings": {
46+
"use_aws": {
47+
"alwaysAllow": [
48+
{
49+
"preset": "readOnly"
50+
}
51+
]
52+
},
53+
"execute_bash": {
54+
"alwaysAllow": [
55+
{
56+
"preset": "readOnly"
57+
}
58+
]
59+
}
60+
},
61+
"resources": [
62+
"file://AmazonQ.md",
63+
"file://README.md",
64+
"file://.amazonq/rules/**/*.md"
65+
],
66+
"hooks": {
67+
"agentSpawn": [],
68+
"userPromptSubmit": []
69+
},
70+
"useLegacyMcpJson": true
71+
}

.amazonq/rules/common.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Common best Practices
2+
3+
## Linting and testing
4+
5+
- Use pre-commit to lint the code
6+
- Run "pre-commit run -a" before commiting/pushing to git remote
7+
- Use common hooks from https://github.com/pre-commit/pre-commit-hooks

.amazonq/rules/github_actions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ When generating or modifying GitHub actions template files, follow these best pr
55
## Code Best Practices
66

77
- When you use setup-* actions, try to get the latest versions of the software you need to install
8+
- Use pre-commit to run the hooks of the repository in the CI and install required software so hooks can work

.amazonq/rules/terraform_aws.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ When generating or modifying Terraform code for AWS, follow these best practices
7676
- To avoid regressions, it is best to fix dependency versions.
7777
- For Terraform OSS modules, use a fixed version (preferably the latest available on the Terraform registry) in the module version field
7878

79-
## Testing
79+
## Linting and testing
8080

81+
- Use pre-commit to lint the code with the following hooks: terraform_fmt, terraform_validate, terraform_docs, terraform_docs, terraform_trivy
8182
- Each validator for Terraform input variables must be tested, but only failed cases.
8283
- For each module generated, an example must be provided.
8384
- For each example, there must be a test that runs it.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: VPC Demo - Terraform Deploy
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'vpc-demo/**'
9+
pull_request:
10+
branches:
11+
- main
12+
paths:
13+
- 'vpc-demo/**'
14+
workflow_dispatch:
15+
16+
permissions:
17+
id-token: write
18+
contents: read
19+
pull-requests: write
20+
21+
jobs:
22+
terraform:
23+
name: Terraform
24+
runs-on: ubuntu-latest
25+
defaults:
26+
run:
27+
working-directory: vpc-demo
28+
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Setup Python
34+
uses: actions/setup-python@v5
35+
with:
36+
python-version: '3.12'
37+
38+
- name: Setup Terraform
39+
uses: hashicorp/setup-terraform@v3
40+
with:
41+
terraform_version: 1.13.5
42+
terraform_wrapper: false
43+
44+
- name: Install terraform-docs
45+
run: |
46+
curl -sSLo /tmp/terraform-docs.tar.gz https://github.com/terraform-docs/terraform-docs/releases/download/v0.19.0/terraform-docs-v0.19.0-linux-amd64.tar.gz
47+
tar -xzf /tmp/terraform-docs.tar.gz -C /tmp
48+
sudo mv /tmp/terraform-docs /usr/local/bin/
49+
50+
- name: Install trivy
51+
run: |
52+
curl -sfL https://raw.githubusercontent.com/aquasecurity/trivy/main/contrib/install.sh | sh -s -- -b /usr/local/bin
53+
54+
- name: Run pre-commit
55+
uses: pre-commit/[email protected]
56+
57+
- name: Configure AWS Credentials
58+
uses: aws-actions/configure-aws-credentials@v4
59+
with:
60+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-role
61+
aws-region: eu-west-3
62+
63+
- name: Terraform Init
64+
run: terraform init
65+
66+
- name: Terraform Plan
67+
id: plan
68+
run: terraform plan -no-color -var="aws_profile=" -out=tfplan
69+
continue-on-error: true
70+
71+
- name: Comment PR
72+
if: github.event_name == 'pull_request'
73+
uses: actions/github-script@v7
74+
with:
75+
script: |
76+
const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
77+
78+
<details><summary>Show Plan</summary>
79+
80+
\`\`\`terraform
81+
${{ steps.plan.outputs.stdout }}
82+
\`\`\`
83+
84+
</details>`;
85+
86+
github.rest.issues.createComment({
87+
issue_number: context.issue.number,
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
body: output
91+
})
92+
93+
- name: Terraform Apply
94+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
95+
run: terraform apply -auto-approve -var="aws_profile=" tfplan

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ crash.log
1010
crash.*.log
1111

1212
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
13-
# password, private keys, and other secrets. These should not be part of version
14-
# control as they are data points which are potentially sensitive and subject
13+
# password, private keys, and other secrets. These should not be part of version
14+
# control as they are data points which are potentially sensitive and subject
1515
# to change depending on the environment.
1616
*.tfvars
1717
*.tfvars.json

.pre-commit-config.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
repos:
2+
- repo: https://github.com/antonbabenko/pre-commit-terraform
3+
rev: v1.96.2
4+
hooks:
5+
- id: terraform_fmt
6+
- id: terraform_validate
7+
- id: terraform_docs
8+
args:
9+
- --hook-config=--path-to-file=README.md
10+
- --hook-config=--add-to-existing-file=true
11+
- --hook-config=--create-file-if-not-exists=true
12+
- id: terraform_trivy
13+
args:
14+
- --args=--severity=HIGH,CRITICAL
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v6.0.0
17+
hooks:
18+
- id: check-merge-conflict
19+
- id: end-of-file-fixer
20+
- id: trailing-whitespace

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ git checkout -b live-coding-5
4949
Prompt enrichi via les Q rules, le serveur MCP Terraform et code généré à partir d'un schéma Excalidraw ajouté dans le contexte du prompt suivant :
5050

5151
```
52-
Create the Terraform code from the schema.
52+
Create the Terraform code from the schema.
5353
```
5454

5555
## Live coding 6

github-oidc/.terraform.lock.hcl

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

github-oidc/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# GitHub OIDC Provider for AWS
2+
3+
This Terraform configuration creates an IAM OIDC provider for GitHub Actions and an IAM role that can be assumed by your GitHub workflows.
4+
5+
## Prerequisites
6+
7+
- AWS CLI configured with profile `ippon-data-lab`
8+
- Terraform 1.10.5
9+
10+
## Usage
11+
12+
1. Copy the example variables file:
13+
```bash
14+
cp terraform.tfvars.example terraform.tfvars
15+
```
16+
17+
2. Edit `terraform.tfvars` with your GitHub organization and repository:
18+
```hcl
19+
github_org = "your-org"
20+
github_repo = "aws-q-academy"
21+
```
22+
23+
3. Initialize Terraform:
24+
```bash
25+
terraform init
26+
```
27+
28+
4. Apply the configuration:
29+
```bash
30+
terraform apply
31+
```
32+
33+
## GitHub Actions Workflow
34+
35+
Use the role in your GitHub Actions workflow:
36+
37+
```yaml
38+
permissions:
39+
id-token: write
40+
contents: read
41+
42+
jobs:
43+
deploy:
44+
runs-on: ubuntu-latest
45+
steps:
46+
- name: Configure AWS credentials
47+
uses: aws-actions/configure-aws-credentials@v4
48+
with:
49+
role-to-assume: arn:aws:iam::721665305066:role/github-actions-role
50+
aws-region: eu-west-3
51+
52+
- name: Run AWS commands
53+
run: aws sts get-caller-identity
54+
```
55+
56+
## Resources Created
57+
58+
- IAM OIDC Provider for GitHub Actions
59+
- IAM Role with AdministratorAccess (adjust permissions as needed)

0 commit comments

Comments
 (0)