Skip to content

Commit

Permalink
fixed overwriting the token value during read
Browse files Browse the repository at this point in the history
  • Loading branch information
thulasirajkomminar committed Aug 23, 2024
1 parent 8b54a2c commit 2914560
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docs/resources/authorization.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ Required:

Required:

- `org_id` (String) An organization ID. Identifies the organization that owns the resource.
- `type` (String) A resource type. Identifies the API resource's type (or kind).

Optional:

- `id` (String) A resource ID. Identifies a specific resource.
- `org` (String) An organization name. The organization that owns the resource.
- `org_id` (String) An organization ID. Identifies the organization that owns the resource.

Read-Only:

Expand Down
18 changes: 14 additions & 4 deletions examples/resources/authorization/resource.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
influxdb = {
source = "komminarlabs/influxdb"
}
}
}

provider "influxdb" {}

data "influxdb_organization" "iot" {
Expand All @@ -15,15 +23,17 @@ resource "influxdb_authorization" "signals" {
permissions = [{
action = "read"
resource = {
id = data.influxdb_bucket.signals.id
type = "buckets"
id = data.influxdb_bucket.signals.id
org_id = data.influxdb_organization.iot.id
type = "buckets"
}
},
{
action = "write"
resource = {
id = data.influxdb_bucket.signals.id
type = "buckets"
id = data.influxdb_bucket.signals.id
org_id = data.influxdb_organization.iot.id
type = "buckets"
}
}]
}
Expand Down
8 changes: 8 additions & 0 deletions examples/resources/bucket/resource.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
influxdb = {
source = "komminarlabs/influxdb"
}
}
}

provider "influxdb" {}

data "influxdb_organization" "iot" {
Expand Down
8 changes: 8 additions & 0 deletions examples/resources/organization/resource.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
terraform {
required_providers {
influxdb = {
source = "komminarlabs/influxdb"
}
}
}

provider "influxdb" {}

resource "influxdb_organization" "iot" {
Expand Down
10 changes: 4 additions & 6 deletions internal/provider/authorization_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (r *AuthorizationResource) Schema(ctx context.Context, req resource.SchemaR
Computed: true,
Description: "The API token.",
Sensitive: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},

Check warning on line 64 in internal/provider/authorization_resource.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/authorization_resource.go#L62-L64

Added lines #L62 - L64 were not covered by tests
},
"status": schema.StringAttribute{
Optional: true,
Expand Down Expand Up @@ -142,12 +145,8 @@ func (r *AuthorizationResource) Schema(ctx context.Context, req resource.SchemaR
},
},
"org_id": schema.StringAttribute{
Computed: true,
Optional: true,
Required: true,

Check warning on line 148 in internal/provider/authorization_resource.go

View check run for this annotation

Codecov / codecov/patch

internal/provider/authorization_resource.go#L148

Added line #L148 was not covered by tests
Description: "An organization ID. Identifies the organization that owns the resource.",
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
},
"type": schema.StringAttribute{
Required: true,
Expand Down Expand Up @@ -300,7 +299,6 @@ func (r *AuthorizationResource) Read(ctx context.Context, req resource.ReadReque
state.Id = types.StringPointerValue(authorization.Id)
state.Org = types.StringPointerValue(authorization.Org)
state.OrgID = types.StringPointerValue(authorization.OrgID)
state.Token = types.StringPointerValue(authorization.Token)
state.CreatedAt = types.StringValue(authorization.CreatedAt.String())
state.UpdatedAt = types.StringValue(authorization.UpdatedAt.String())
state.Description = types.StringValue(*authorization.AuthorizationUpdateRequest.Description)
Expand Down

0 comments on commit 2914560

Please sign in to comment.