Skip to content

Commit

Permalink
fix astra token integration test (#402)
Browse files Browse the repository at this point in the history
The token integration test started failing after the addition of the
optional `org_id` field
(#399). The
initial token creation works successfully but subsequent calls to
Terraform apply cause the token to be regenerated instead of re-using
the previously generated token. Adding the `Computed: true` flag fixes
this issue by indicating to the Terraform SDK that the field was
automatically generated from the auth token.

Error message from tests:
```
=== RUN   TestToken
2024/09/19 21:00:31 [DEBUG] POST https://api.test.cloud.datastax.com/v2/organizations/roles
2024/09/19 21:00:31 [DEBUG] GET https://api.test.cloud.datastax.com/v2/currentOrg
2024/09/19 21:00:31 [DEBUG] GET https://api.test.cloud.datastax.com/v2/organizations/roles/6c081bb7-3dce-4525-8c19-2ae16e0b13e9
2024/09/19 21:00:31 [DEBUG] POST https://api.test.cloud.datastax.com/v2/tokens
    resource_token_test.go:11: Step 1/1 error: After applying this test step, the plan was not empty.
        stdout:
        
        
        Terraform used the selected providers to generate the following execution
        plan. Resource actions are indicated with the following symbols:
        -/+ destroy and then create replacement
        
        Terraform will perform the following actions:
        
          # astra_token.example must be replaced
        -/+ resource "astra_token" "example" {
              ~ client_id = "kqOPeOShqbFZXMbpdzstdmKs" -> (known after apply)
              ~ id        = "kqOPeOShqbFZXMbpdzstdmKs" -> (known after apply)
              - org_id    = "3155c078-f822-4ae2-8605-f2f49e6d7ca1" -> null # forces replacement
              ~ secret    = (sensitive value)
              ~ token     = (sensitive value)
                # (1 unchanged attribute hidden)
            }
        
        Plan: 1 to add, 0 to change, 1 to destroy.

--- FAIL: TestToken (2.89s)
```
  • Loading branch information
pgier authored Sep 30, 2024
1 parent f103fca commit 1ca01d5
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions internal/provider/resource_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func resourceToken() *schema.Resource {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
},
"client_id": {
Description: "Client id, use as username in cql to connect",
Expand Down

0 comments on commit 1ca01d5

Please sign in to comment.