Skip to content

Commit f2c1527

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

File tree

18 files changed

+511
-0
lines changed

18 files changed

+511
-0
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+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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: Configure AWS Credentials
34+
uses: aws-actions/configure-aws-credentials@v4
35+
with:
36+
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions-role
37+
aws-region: eu-west-3
38+
39+
- name: Setup Terraform
40+
uses: hashicorp/setup-terraform@v3
41+
with:
42+
terraform_version: 1.13.5
43+
44+
- name: Terraform Init
45+
run: terraform init
46+
47+
- name: Terraform Format
48+
run: terraform fmt -check
49+
continue-on-error: true
50+
51+
- name: Terraform Validate
52+
run: terraform validate
53+
54+
- name: Terraform Plan
55+
id: plan
56+
run: terraform plan -no-color -var="aws_profile=" -out=tfplan
57+
continue-on-error: true
58+
59+
- name: Comment PR
60+
if: github.event_name == 'pull_request'
61+
uses: actions/github-script@v7
62+
with:
63+
script: |
64+
const output = `#### Terraform Plan 📖\`${{ steps.plan.outcome }}\`
65+
66+
<details><summary>Show Plan</summary>
67+
68+
\`\`\`terraform
69+
${{ steps.plan.outputs.stdout }}
70+
\`\`\`
71+
72+
</details>`;
73+
74+
github.rest.issues.createComment({
75+
issue_number: context.issue.number,
76+
owner: context.repo.owner,
77+
repo: context.repo.repo,
78+
body: output
79+
})
80+
81+
- name: Terraform Apply
82+
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
83+
run: terraform apply -auto-approve -var="aws_profile=" tfplan

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)

github-oidc/backend.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
backend "s3" {
3+
bucket = "aws-q-academy-terraform-states"
4+
key = "github-oidc/terraform.tfstate"
5+
region = "eu-west-3"
6+
use_lockfile = true
7+
profile = "ippon-data-lab"
8+
}
9+
}

github-oidc/iam.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
data "aws_caller_identity" "current" {}
2+
3+
resource "aws_iam_openid_connect_provider" "github" {
4+
url = "https://token.actions.githubusercontent.com"
5+
client_id_list = ["sts.amazonaws.com"]
6+
thumbprint_list = ["6938fd4d98bab03faadb97b34396831e3780aea1"]
7+
8+
tags = {
9+
Name = "github-actions-oidc"
10+
ManagedBy = "terraform"
11+
Environment = "shared"
12+
}
13+
}
14+
15+
resource "aws_iam_role" "github_actions" {
16+
name = var.role_name
17+
18+
assume_role_policy = jsonencode({
19+
Version = "2012-10-17"
20+
Statement = [
21+
{
22+
Effect = "Allow"
23+
Principal = {
24+
Federated = aws_iam_openid_connect_provider.github.arn
25+
}
26+
Action = "sts:AssumeRoleWithWebIdentity"
27+
Condition = {
28+
StringEquals = {
29+
"token.actions.githubusercontent.com:aud" = "sts.amazonaws.com"
30+
}
31+
StringLike = {
32+
"token.actions.githubusercontent.com:sub" = "repo:${var.github_org}/${var.github_repo}:*"
33+
}
34+
}
35+
}
36+
]
37+
})
38+
39+
tags = {
40+
Name = var.role_name
41+
ManagedBy = "terraform"
42+
Environment = "shared"
43+
}
44+
}
45+
46+
resource "aws_iam_role_policy_attachment" "github_actions_admin" {
47+
role = aws_iam_role.github_actions.name
48+
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
49+
}

github-oidc/outputs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "oidc_provider_arn" {
2+
description = "ARN of the GitHub OIDC provider"
3+
value = aws_iam_openid_connect_provider.github.arn
4+
}
5+
6+
output "role_arn" {
7+
description = "ARN of the IAM role for GitHub Actions"
8+
value = aws_iam_role.github_actions.arn
9+
}
10+
11+
output "role_name" {
12+
description = "Name of the IAM role for GitHub Actions"
13+
value = aws_iam_role.github_actions.name
14+
}

github-oidc/providers.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
provider "aws" {
2+
region = var.region
3+
profile = "ippon-data-lab"
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
github_org = "your-github-org"
2+
github_repo = "aws-q-academy"
3+
role_name = "github-actions-role"
4+
region = "eu-west-3"

github-oidc/variables.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
variable "region" {
2+
description = "AWS region"
3+
type = string
4+
default = "eu-west-3"
5+
}
6+
7+
variable "github_org" {
8+
description = "GitHub organization or username"
9+
type = string
10+
}
11+
12+
variable "github_repo" {
13+
description = "GitHub repository name"
14+
type = string
15+
}
16+
17+
variable "role_name" {
18+
description = "IAM role name for GitHub Actions"
19+
type = string
20+
default = "github-actions-role"
21+
}

0 commit comments

Comments
 (0)