|
| 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 |
0 commit comments