Skip to content

Commit 876e662

Browse files
authored
Merge pull request #1 from HollowByt3/main
changed provider to oidc
2 parents a9a8f84 + 116330b commit 876e662

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed

terraform/pipelines/OIDC_SETUP.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Setting up OIDC Authentication for Terraform Cloud
2+
3+
This guide explains how to set up OpenID Connect (OIDC) authentication between Terraform Cloud and AWS for the DevSecOps Pipeline project.
4+
5+
## Prerequisites
6+
7+
1. AWS Account with administrative access
8+
2. Terraform Cloud account
9+
3. Organization and workspace already created in Terraform Cloud
10+
11+
## Setup Steps
12+
13+
### 1. Apply the OIDC Configuration
14+
15+
First, apply the OIDC configuration to create the necessary AWS resources:
16+
17+
```bash
18+
cd terraform/pipelines
19+
terraform init
20+
terraform apply
21+
```
22+
23+
This will create:
24+
- An OIDC provider for Terraform Cloud
25+
- An IAM role that can be assumed by Terraform Cloud
26+
- Required policy attachments
27+
28+
### 2. Configure Terraform Cloud
29+
30+
1. Log in to your Terraform Cloud account
31+
2. Navigate to your organization settings
32+
3. Go to "Provider Configuration"
33+
4. Click "Add Provider Configuration"
34+
5. Select "AWS"
35+
6. Choose "OIDC" as the authentication method
36+
7. Enter the following details:
37+
- Role ARN: The ARN of the role created in step 1 (output will be shown after terraform apply)
38+
- Session Duration: 3600 (or your preferred duration)
39+
- Workspace: dsb-aws-devsecops-pipelines
40+
41+
### 3. Update Workspace Variables
42+
43+
In your Terraform Cloud workspace:
44+
45+
1. Go to "Variables"
46+
2. Add the following environment variables:
47+
- `TFC_AWS_PROVIDER_AUTH`: true
48+
- `TFC_AWS_RUN_ROLE_ARN`: The ARN of the role created in step 1
49+
50+
### 4. Verify Configuration
51+
52+
1. Run a plan in Terraform Cloud
53+
2. Check the logs to ensure the OIDC authentication is working
54+
3. Verify that the AWS resources are being created with the correct permissions
55+
56+
## Security Considerations
57+
58+
- The OIDC configuration is scoped to your specific organization and workspace
59+
- The role has administrative access - consider restricting permissions based on your needs
60+
- Regularly rotate the OIDC provider's thumbprint if Terraform Cloud updates their certificates
61+
62+
## Troubleshooting
63+
64+
If you encounter issues:
65+
66+
1. Verify the OIDC provider's thumbprint is correct
67+
2. Check that the role ARN is correctly configured in Terraform Cloud
68+
3. Ensure the workspace name matches exactly in both the IAM role policy and Terraform Cloud
69+
4. Check AWS CloudTrail logs for any authentication failures

terraform/pipelines/oidc.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# OIDC Provider for Terraform Cloud
2+
resource "aws_iam_openid_connect_provider" "terraform_cloud" {
3+
url = "https://app.terraform.io"
4+
client_id_list = ["aws.workload.identity"]
5+
thumbprint_list = ["9e99a48a9960b14926bb7f3b02e22da2b0ab7280"]
6+
}
7+
8+
# IAM Role for Terraform Cloud
9+
resource "aws_iam_role" "terraform_cloud" {
10+
name = "terraform-cloud-role"
11+
12+
assume_role_policy = jsonencode({
13+
Version = "2012-10-17"
14+
Statement = [
15+
{
16+
Effect = "Allow"
17+
Principal = {
18+
Federated = aws_iam_openid_connect_provider.terraform_cloud.arn
19+
}
20+
Action = "sts:AssumeRoleWithWebIdentity"
21+
Condition = {
22+
StringEquals = {
23+
"app.terraform.io:aud" = "aws.workload.identity"
24+
},
25+
StringLike = {
26+
"app.terraform.io:sub" = "organization:DSB:workspace:dsb-aws-devsecops-pipelines:run_phase:*"
27+
}
28+
}
29+
}
30+
]
31+
})
32+
}
33+
34+
# Attach necessary policies to the role
35+
resource "aws_iam_role_policy_attachment" "terraform_cloud_admin" {
36+
role = aws_iam_role.terraform_cloud.name
37+
policy_arn = "arn:aws:iam::aws:policy/AdministratorAccess"
38+
}

terraform/pipelines/provider.tf

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,15 @@ terraform {
1212
name = "dsb-aws-devsecops-pipelines"
1313
}
1414
}
15+
16+
required_providers {
17+
aws = {
18+
source = "hashicorp/aws"
19+
version = "~> 5.0"
20+
}
21+
random = {
22+
source = "hashicorp/random"
23+
version = "~> 3.0"
24+
}
25+
}
1526
}

0 commit comments

Comments
 (0)