Skip to content

Commit 0170e26

Browse files
committed
Enhance AWS integration documentation and examples
- Updated README.md to clarify the organization integration process, specifying that it creates a CloudFormation stack with internal StackSets. - Revised module names in examples for better clarity, changing `jit_aws_integration` to `jit_aws_account_integration`. - Added detailed explanations for required CloudFormation capabilities for both single account and organization integrations. - Improved validation notes for parameters and added comprehensive examples for both integration types, ensuring users have clear guidance on usage.
1 parent 047c5d0 commit 0170e26

1 file changed

Lines changed: 106 additions & 63 deletions

File tree

  • src/integrations/aws_integration_automation

src/integrations/aws_integration_automation/README.md

Lines changed: 106 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@ A Terraform module for automating AWS integration with JIT (Just-in-Time) securi
55
## Features
66

77
- **Dual Integration Types**: Support for both single account and organization-wide deployments
8-
- **Native Terraform**: Pure Terraform implementation using `data "http"` resources
9-
- **Create-Only State Token**: Implements proper create-only behavior for JIT oauth/state-token using Terraform state
108
- **Multi-Region Support**: Monitor multiple AWS regions simultaneously
119
- **US/EU API Support**: Compatible with both US and EU JIT API endpoints
1210
- **Error Handling**: Built-in validation and error handling with postconditions
13-
- **State Management**: Pure Terraform state management without local file dependencies
1411

1512
## Integration Types
1613

1714
### Single Account Integration
1815
Deploys JIT integration to a single AWS account using CloudFormation stack.
1916

2017
### Organization Integration
21-
Deploys JIT integration across an entire AWS Organization using CloudFormation StackSet, automatically including all current and future accounts in the organization.
18+
Deploys JIT integration across an entire AWS Organization using a CloudFormation stack that creates internal StackSets, automatically including all current and future accounts in the organization.
2219

2320
## Prerequisites
2421

@@ -32,29 +29,27 @@ Deploys JIT integration across an entire AWS Organization using CloudFormation S
3229
### Single Account Integration
3330

3431
```hcl
35-
module "jit_aws_integration" {
32+
module "jit_aws_account_integration" {
3633
source = "path/to/aws_integration_automation"
3734
3835
# JIT Configuration
3936
jit_client_id = var.jit_client_id
4037
jit_secret = var.jit_secret
41-
jit_region = "us"
38+
jit_region = "us" # Use "eu" for European API endpoint
4239
4340
# Integration Type
4441
integration_type = "account"
4542
46-
# AWS Regions to Monitor
43+
# AWS Configuration
4744
aws_regions_to_monitor = ["us-east-1", "us-west-2"]
4845
49-
# Optional Configuration
46+
# Stack Configuration
5047
stack_name = "JitAccountIntegration"
5148
account_name = "Production Account"
5249
resource_name_prefix = "JitProd"
5350
54-
tags = {
55-
Environment = "production"
56-
Owner = "security-team"
57-
}
51+
# CloudFormation Configuration
52+
capabilities = ["CAPABILITY_NAMED_IAM"]
5853
}
5954
```
6055

@@ -67,7 +62,7 @@ module "jit_aws_org_integration" {
6762
# JIT Configuration
6863
jit_client_id = var.jit_client_id
6964
jit_secret = var.jit_secret
70-
jit_region = "us"
65+
jit_region = "us" # Use "eu" for European API endpoint
7166
7267
# Integration Type
7368
integration_type = "org"
@@ -76,11 +71,15 @@ module "jit_aws_org_integration" {
7671
organization_root_id = "r-xxxxxxxxxxxx"
7772
should_include_root_account = true
7873
79-
# AWS Regions to Monitor
74+
# AWS Configuration
8075
aws_regions_to_monitor = ["us-east-1", "us-west-2", "eu-west-1"]
8176
82-
# Optional Configuration
77+
# Stack Configuration
78+
stack_name = "JitOrgIntegration"
8379
resource_name_prefix = "JitOrg"
80+
81+
# CloudFormation Configuration
82+
capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
8483
}
8584
```
8685

@@ -93,55 +92,36 @@ module "jit_aws_org_integration" {
9392
| `integration_type` | Type of AWS integration (`account` or `org`) | `string` | n/a | yes |
9493
| `jit_region` | Jit API region (`us` or `eu`) | `string` | `"us"` | no |
9594
| `aws_regions_to_monitor` | List of AWS regions to monitor | `list(string)` | `["us-east-1"]` | no |
96-
| `stack_name` | Name for the CloudFormation stack or stackset | `string` | `"JitIntegrationStack"` | no |
95+
| `stack_name` | Name for the CloudFormation stack | `string` | `"JitIntegrationStack"` | no |
9796
| `account_name` | Optional account name alias for Jit platform | `string` | `""` | no |
98-
| `resource_name_prefix` | Prefix for CloudFormation resources | `string` | `null` (auto: "Jit" for account, "JitOrg" for org) | no |
99-
| `organization_root_id` | AWS Organization Root ID (required for org type) | `string` | `""` | no |
97+
| `resource_name_prefix` | Prefix for CloudFormation resources (1-40 chars, alphanumeric, hyphens, underscores) | `string` | `null` (auto: "Jit" for account, "JitOrg" for org) | no |
98+
| `organization_root_id` | AWS Organization Root ID (required for org type, format: `r-xxxxxxxxxx`) | `string` | `""` | no |
10099
| `should_include_root_account` | Include root account in organization integration | `bool` | `false` | no |
101100
| `capabilities` | CloudFormation capabilities required | `list(string)` | `["CAPABILITY_NAMED_IAM"]` | no |
102-
| `tags` | Tags to apply to CloudFormation resources | `map(string)` | `{}` | no |
103-
104-
## Outputs
105-
106-
| Name | Description |
107-
|------|-------------|
108-
| `integration_type` | Type of integration deployed |
109-
| `jit_api_endpoint` | JIT API endpoint used |
110-
| `cloudformation_template_url` | CloudFormation template URL used |
111-
| `stack_name` | CloudFormation stack/stackset name |
112-
| `account_name` | Account name alias used in Jit platform |
113-
| `resource_name_prefix` | Prefix used for CloudFormation resources |
114-
| `aws_regions_monitored` | List of AWS regions being monitored |
115-
| `cloudformation_stack_id` | Stack ID (account integration only) |
116-
| `cloudformation_stack_arn` | Stack ARN (account integration only) |
117-
| `cloudformation_stackset_id` | StackSet ID (organization integration only) |
118-
| `cloudformation_stackset_arn` | StackSet ARN (organization integration only) |
119-
| `organization_root_id` | Organization Root ID (organization integration only) |
120-
| `state_token_created` | Whether a new state token was created |
121-
| `state_token_flag_created` | Whether state token flag is initialized in Terraform state |
122-
| `state_token_stored` | Whether state token is stored in Terraform state |
123101

124102
## State Token Management
125103

126-
This module implements a **create-only** behavior for the JIT oauth/state-token endpoint using Terraform state management:
104+
This module implements a **create-only** behavior for the JIT oauth/state-token endpoint using the REST API provider:
127105

128-
1. **First Run**: Creates a new state token and stores it in Terraform state using `terraform_data` resource
106+
1. **First Run**: Creates a new state token via JIT API
129107
2. **Subsequent Runs**: Reuses the existing state token from Terraform state
130-
3. **No Updates**: The state token is never updated or regenerated unless the Terraform state is manually modified
108+
3. **No Updates**: The state token is never updated or regenerated unless explicitly recreated
131109

132110
### State Token Implementation
133111

134-
The module uses three key resources for state token management:
112+
The module uses the `restapi_object` resource for state token management:
135113

136-
- `terraform_data.state_token_flag`: Tracks whether a token has been created
137-
- `data.http.jit_state_token`: Only executes when the flag indicates first creation
138-
- `terraform_data.state_token_storage`: Stores the actual token value in Terraform state
114+
- Creates state token via JIT API endpoint `/oauth/state-token`
115+
- Stores token in Terraform state automatically
116+
- Uses `ignore_changes` lifecycle rule to prevent updates
139117

140118
### Important Notes
141119

142-
- State token is managed entirely within Terraform state - no local files required
120+
- State token is managed entirely within Terraform state
143121
- Token persists across Terraform runs and is only created once
144-
- To regenerate a state token, you must manually modify or destroy the relevant Terraform state resources
122+
- To regenerate a state token, you must manually destroy and recreate the `restapi_object.jit_state_token` resource along with the created AWS stack.
123+
- **External ID Persistence**: The state token (external_id) should be created only once. Changing AWS regions, account configurations, or other integration parameters will not affect the existing integration's configuration or regenerate the token
124+
- **External ID Uniqueness**: The external_id is generated by JIT and cannot be reused across integrations. After a successful integration, changing or regenerating the external_id value will cause issues with the existing integration and may break the connection between JIT and your AWS environment
145125

146126
## CloudFormation Templates
147127

@@ -150,13 +130,31 @@ The module automatically selects the appropriate CloudFormation template:
150130
- **Account Integration**: `https://jit-aws-prod.s3.amazonaws.com/jit_aws_integration_stack.json`
151131
- **Organization Integration**: `https://jit-aws-prod.s3.amazonaws.com/jit_aws_org_integration_stack.json`
152132

133+
## Required Capabilities
134+
135+
### Single Account Integration
136+
```terraform
137+
capabilities = ["CAPABILITY_NAMED_IAM"]
138+
```
139+
140+
### Organization Integration
141+
```terraform
142+
capabilities = ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]
143+
```
144+
145+
The organization integration requires additional capabilities because:
146+
- `CAPABILITY_AUTO_EXPAND`: For creating nested stacks and StackSets within the CloudFormation template
147+
- `CAPABILITY_IAM`: For creating IAM resources
148+
- `CAPABILITY_NAMED_IAM`: For creating IAM resources with custom names
149+
153150
## Resource Name Prefix
154151

155152
The `resource_name_prefix` parameter controls the prefix used for CloudFormation resources:
156153

157154
- **Default for Account Integration**: "Jit"
158155
- **Default for Organization Integration**: "JitOrg"
159156
- **Custom Prefix**: Provide your own prefix (1-40 characters, alphanumeric, hyphens, underscores only)
157+
- **Validation**: The module validates the prefix format automatically
160158

161159
## API Endpoints
162160

@@ -169,21 +167,62 @@ The module supports both JIT API regions:
169167

170168
The module includes comprehensive error handling:
171169

172-
- **Authentication Validation**: Ensures JIT API authentication succeeds
173-
- **State Token Validation**: Verifies state token creation
174-
- **Input Validation**: Validates required parameters and formats
170+
- **Authentication Validation**: Ensures JIT API authentication succeeds with postconditions
171+
- **Input Validation**: Validates required parameters and formats using Terraform validation blocks
172+
- **Integration Type Validation**: Ensures integration_type is either "account" or "org"
173+
- **Region Validation**: Ensures jit_region is either "us" or "eu"
174+
- **Organization Root ID Validation**: Validates proper format for organization root IDs
175175
- **Lifecycle Management**: Prevents accidental destruction of resources
176176

177-
## Examples
177+
## Complete Working Examples
178+
179+
The `examples/` directory contains complete working examples organized by integration type:
180+
181+
### Single Account Integration
182+
- **Directory**: [`examples/single_account/`](examples/single_account/)
183+
- **Main File**: `account_integration.tf`
184+
- **Variables**: `variables.tf`
185+
- **Configuration**: `terraform.tfvars`
186+
187+
To use the single account example:
188+
```bash
189+
cd examples/single_account/
190+
cp terraform.tfvars.example terraform.tfvars
191+
# Edit terraform.tfvars with your values
192+
terraform init
193+
terraform plan
194+
terraform apply
195+
```
196+
197+
### Organization Integration
198+
- **Directory**: [`examples/aws_organization/`](examples/aws_organization/)
199+
- **Main File**: `organization_integration.tf`
200+
- **Variables**: `variables.tf`
201+
- **Configuration**: `terraform.tfvars`
202+
203+
To use the organization example:
204+
```bash
205+
cd examples/aws_organization/
206+
cp terraform.tfvars.example terraform.tfvars
207+
# Edit terraform.tfvars with your values
208+
terraform init
209+
terraform plan
210+
terraform apply
211+
```
212+
213+
## How Organization Integration Works
214+
215+
The organization integration creates a **single CloudFormation stack** that internally:
178216

179-
See the `examples/` directory for complete working examples:
217+
1. **Creates an IAM Role** for JIT to assume across the organization
218+
2. **Creates a StackSet** (`JitOrganizationsStacksSetRocket`) that automatically deploys to all accounts in the organization
219+
3. **Optionally creates a stack** in the root account if `should_include_root_account = true`
180220

181-
- [`examples/account_integration.tf`](examples/account_integration.tf) - Single account integration
182-
- [`examples/organization_integration.tf`](examples/organization_integration.tf) - Organization integration
221+
The CloudFormation template handles the StackSet creation and deployment automatically using AWS Organizations' `SERVICE_MANAGED` permission model.
183222

184223
## Security Considerations
185224

186-
1. **Sensitive Variables**: `jit_client_id` and `jit_secret` are marked as sensitive
225+
1. **Sensitive Variables**: `jit_client_id`, `jit_secret`, and `organization_root_id` are marked as sensitive
187226
2. **State Files**: Ensure Terraform state files are stored securely (e.g., S3 with encryption)
188227
3. **State Token**: Stored in Terraform state - secure your state backend appropriately
189228
4. **IAM Permissions**: Follow principle of least privilege for AWS IAM permissions
@@ -200,17 +239,20 @@ See the `examples/` directory for complete working examples:
200239
- Ensure the organization root ID is in the correct format (`r-xxxxxxxxxxxx`)
201240
- Verify AWS Organizations is enabled and accessible
202241

203-
3. **State Token Issues**
204-
- Check Terraform state for `terraform_data.state_token_storage` resource
205-
- Use `terraform state show` to inspect state token resources
242+
3. **CloudFormation Capabilities Error**
243+
- For organization integration, ensure you have all three capabilities: `["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM", "CAPABILITY_AUTO_EXPAND"]`
244+
- For single account integration, use: `["CAPABILITY_NAMED_IAM"]`
206245

207-
4. **CloudFormation Failures**
246+
4. **CloudFormation Stack Errors**
208247
- Verify AWS permissions for CloudFormation operations
209248
- Check CloudFormation events in the AWS console for detailed error messages
249+
- For organization integration, ensure AWS Organizations service is properly configured
210250

211251
5. **Parameter Validation Errors**
212-
- Verify `resource_name_prefix` meets length and character requirements
213-
- Check that `organization_root_id` follows the correct pattern for org integration
252+
- Verify `resource_name_prefix` meets length and character requirements (1-40 chars, alphanumeric, hyphens, underscores)
253+
- Check that `organization_root_id` follows the correct pattern (`r-` followed by 4-32 alphanumeric characters)
254+
- Ensure `integration_type` is exactly "account" or "org"
255+
- Ensure `jit_region` is exactly "us" or "eu"
214256

215257
### Debug Information
216258

@@ -229,11 +271,12 @@ terraform apply
229271
| aws | >= 5.0 |
230272
| http | >= 3.0 |
231273
| local | >= 2.0 |
274+
| restapi | >= 1.19.1 |
232275

233276
## Contributing
234277

235278
1. Follow existing code patterns and documentation standards
236-
2. Test changes with both integration types
279+
2. Test changes with both integration types using the provided examples
237280
3. Update examples and documentation as needed
238281
4. Ensure all variables have proper validation where applicable
239282

0 commit comments

Comments
 (0)