Skip to content

Commit

Permalink
Infl 8529 use official hashicorp http provider instead of devops rod …
Browse files Browse the repository at this point in the history
…terracurl (#48)

BREAKING CHANGE: Replace terracurl with official hashicorp http
  • Loading branch information
nirfirefly authored Mar 7, 2024
1 parent a104268 commit 270074e
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 77 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ module "firefly-read-only" {
}
```

### Upgrading to from v1.y.z to v2.y.z
Use of `devops-rob/terracurl` provider is removed in favour of official `hashicorp/http`
Prior to upgrading it is reuqired to remove the deprecated resources from the state eg:
```
terraform state list | grep terracurl_request
module.firefly.module.firefly_aws_integration[0].terracurl_request.firefly_aws_integration_request
```
```
terraform state rm "module.firefly.module.firefly_aws_integration[0].terracurl_request.firefly_aws_integration_request"
Removed module.firefly.module.firefly_aws_integration[0].terracurl_request.firefly_aws_integration_request
Successfully removed 1 resource instance(s).
```


### Installation with Event Driven

```hcl-terraform
Expand Down
11 changes: 5 additions & 6 deletions modules/firefly_auth/main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
data "terracurl_request" "firefly_login" {
name = "firefly_aws_integration"
url = "${var.firefly_endpoint}/account/access_keys/login"
method = "POST"
headers = {
Content-Type: "application/json",
data "http" "firefly_login" {
url = "${var.firefly_endpoint}/account/access_keys/login"
method = "POST"
request_headers = {
Content-Type = "application/json"
}
request_body = jsonencode({ "accessKey"=var.firefly_access_key, "secretKey"=var.firefly_secret_key })
}
2 changes: 1 addition & 1 deletion modules/firefly_auth/output.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
locals {
response_obj = try(jsondecode(data.terracurl_request.firefly_login.response), {})
response_obj = try(jsondecode(data.http.firefly_login.response_body), {})
token = lookup(local.response_obj, "access_token", "error")
}
output "firefly_token" {
Expand Down
6 changes: 3 additions & 3 deletions modules/firefly_auth/terraform.tf
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
terraform {
required_providers {
terracurl = {
version = "0.1.0"
source= "devops-rob/terracurl"
http = {
source = "hashicorp/http"
version = "3.4.2"
}
}
}
45 changes: 13 additions & 32 deletions modules/firefly_aws_integration/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,27 @@ resource "time_sleep" "wait_10_seconds" {
create_duration = "10s"
}

resource "terracurl_request" "firefly_aws_integration_request" {
name = "firefly aws provider integration"
url = "${var.firefly_endpoint}/integrations/aws/"
method = "POST"
request_body = jsonencode(
data "http" "firefly_aws_integration_request" {
url = "${var.firefly_endpoint}/integrations/aws/"
method = "POST"
request_headers = {
Content-Type = "application/json"
Authorization = "Bearer ${var.firefly_token}"
}
request_body = jsonencode(
{
"name"= var.name,
"roleArn"= aws_iam_role.firefly_cross_account_access_role.arn,
"externalId"= var.role_external_id,
"fullScanEnabled"= var.full_scan_enabled,
"isProd"= var.is_prod
"isEventDriven" = var.event_driven
"eventDrivenRegions" = var.event_driven_regions
"shouldRunWorkflow" = !var.terraform_create_rules
"isProd"= var.is_prod,
"isEventDriven" = var.event_driven,
"eventDrivenRegions" = var.event_driven_regions,
"shouldRunWorkflow" = !var.terraform_create_rules,
"isIacAutoDiscoverDisabled" = var.should_autodiscover_disabled
}
)

headers = {
Content-Type = "application/json"
Authorization: "Bearer ${var.firefly_token}"
}

lifecycle {
ignore_changes = [
headers,
destroy_headers,
request_body
]
}
response_codes = [200, 409, 401]

destroy_url = "https://www.google.com"
destroy_method = "GET"

destroy_headers = {}

destroy_request_body = ""
destroy_response_codes = [200]
depends_on = [
depends_on = [
aws_iam_policy.firefly_readonly_policy_deny_list, aws_iam_policy.firefly_s3_specific_permission,
aws_iam_role.firefly_cross_account_access_role, time_sleep.wait_10_seconds
]
Expand Down
6 changes: 3 additions & 3 deletions modules/firefly_aws_integration/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ terraform {
version = ">= 4.12.1"
}

terracurl = {
version = "0.1.0"
source= "devops-rob/terracurl"
http = {
source = "hashicorp/http"
version = "3.4.2"
}
}
}
34 changes: 8 additions & 26 deletions modules/run_workflow/main.tf
Original file line number Diff line number Diff line change
@@ -1,34 +1,16 @@
resource "terracurl_request" "firefly_run_workflow_request" {
name = "firefly run workflow on aws provider integration"
url = "${var.firefly_endpoint}/integrations/aws/runWorkflow"
method = "POST"
request_body = jsonencode(
data "http" "firefly_run_workflow_request" {
url = "${var.firefly_endpoint}/integrations/aws/runWorkflow"
method = "POST"
request_headers = {
Content-Type = "application/json"
Authorization = "Bearer ${var.firefly_token}"
}
request_body = jsonencode(
{
"name"= var.name
"eventsRoleArn": var.events_role_arn
"eventDrivenRegions": var.event_driven_regions
}
)

headers = {
Content-Type = "application/json"
Authorization: "Bearer ${var.firefly_token}"
}

lifecycle {
ignore_changes = [
headers,
destroy_headers,
request_body
]
}
response_codes = [200, 409]

destroy_url = "https://www.google.com"
destroy_method = "GET"

destroy_headers = {}

destroy_request_body = ""
destroy_response_codes = [200]
}
6 changes: 3 additions & 3 deletions modules/run_workflow/terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ terraform {
source = "hashicorp/aws"
version = ">= 4.12.1"
}
terracurl = {
version = "0.1.0"
source= "devops-rob/terracurl"
http = {
source = "hashicorp/http"
version = "3.4.2"
}
}
}
6 changes: 3 additions & 3 deletions terraform.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ terraform {
version = ">= 4.12.1, <= 5.38.0"
}

terracurl = {
version = "0.1.0"
source= "devops-rob/terracurl"
http = {
source = "hashicorp/http"
version = "3.4.2"
}
}
}

0 comments on commit 270074e

Please sign in to comment.