Skip to content

Commit a6ea2ba

Browse files
committed
Add AWS integration automation files for JIT authentication
- Introduced .gitignore to exclude Terraform and IDE-related files. - Added data.tf for JIT API authentication to retrieve access tokens. - Configured REST API provider in providers.tf for global headers and authentication. - Updated README.md to advise on moving the restapi provider for better module management when commenting out.
1 parent 0170e26 commit a6ea2ba

5 files changed

Lines changed: 71 additions & 36 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Terraform files
2+
*.tfstate
3+
*.tfstate.*
4+
.terraform/
5+
.terraform.lock.hcl
6+
crash.log
7+
crash.*.log
8+
9+
# Terraform plan files
10+
*.tfplan
11+
*.tfplan.*
12+
13+
# Environment variables
14+
.env
15+
.env.local
16+
17+
# IDE files
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
*~
23+
24+
# OS files
25+
.DS_Store
26+
Thumbs.db
27+
28+
# JIT state token file (contains sensitive data)
29+
.jit_state_token
30+
31+
# Backup files
32+
*.backup
33+
*.bak
34+
35+
# Log files
36+
*.log

src/integrations/aws_integration_automation/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ The module uses the `restapi_object` resource for state token management:
122122
- To regenerate a state token, you must manually destroy and recreate the `restapi_object.jit_state_token` resource along with the created AWS stack.
123123
- **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
124124
- **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
125+
- If you intend to comment out the entire module - it's better to move the restapi provider outside - to allow commenting it out without performing `terraform destroy`.
125126

126127
## CloudFormation Templates
127128

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Authentication with JIT API to get access token
2+
data "http" "jit_auth" {
3+
url = "${local.jit_api_endpoint}/authentication/login"
4+
method = "POST"
5+
6+
request_headers = {
7+
"Accept" = "application/json"
8+
"Content-Type" = "application/json"
9+
}
10+
11+
request_body = jsonencode({
12+
clientId = var.jit_client_id
13+
secret = var.jit_secret
14+
})
15+
16+
lifecycle {
17+
postcondition {
18+
condition = self.status_code == 200
19+
error_message = "JIT authentication failed with status ${self.status_code}"
20+
}
21+
}
22+
}

src/integrations/aws_integration_automation/main.tf

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
# Configure the REST API provider with global headers
2-
provider "restapi" {
3-
uri = local.jit_api_endpoint
4-
write_returns_object = true
5-
create_returns_object = true
6-
7-
headers = {
8-
"Accept" = "application/json"
9-
"Content-Type" = "application/json"
10-
"Authorization" = "Bearer ${jsondecode(data.http.jit_auth.response_body).accessToken}"
11-
}
12-
}
13-
14-
# Authentication with JIT API to get access token
15-
data "http" "jit_auth" {
16-
url = "${local.jit_api_endpoint}/authentication/login"
17-
method = "POST"
18-
19-
request_headers = {
20-
"Accept" = "application/json"
21-
"Content-Type" = "application/json"
22-
}
23-
24-
request_body = jsonencode({
25-
clientId = var.jit_client_id
26-
secret = var.jit_secret
27-
})
28-
29-
lifecycle {
30-
postcondition {
31-
condition = self.status_code == 200
32-
error_message = "JIT authentication failed with status ${self.status_code}"
33-
}
34-
}
35-
}
36-
371
# Create state token using REST API provider
382
resource "restapi_object" "jit_state_token" {
393
path = "/oauth/state-token"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Configure the REST API provider with global headers
2+
provider "restapi" {
3+
uri = local.jit_api_endpoint
4+
write_returns_object = true
5+
create_returns_object = true
6+
7+
headers = {
8+
"Accept" = "application/json"
9+
"Content-Type" = "application/json"
10+
"Authorization" = "Bearer ${jsondecode(data.http.jit_auth.response_body).accessToken}"
11+
}
12+
}

0 commit comments

Comments
 (0)