Skip to content

Commit c1265bb

Browse files
Merge pull request #4 from bytesourceoss/fix_runtime_issue
fix share datasource value mapping error
2 parents 2870673 + 32337de commit c1265bb

File tree

6 files changed

+48
-27
lines changed

6 files changed

+48
-27
lines changed

.github/workflows/test_lint_build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
uses: actions/setup-go@v5
2121
with:
2222
go-version: 1.23.0
23+
passphrase: ${{ secrets.PASSPHRASE }}
2324
- name: Test, Lint, & Build # Everything should pass normally before building with GoReleaser
2425
run: |
2526
curl --proto '=https' --tlsv1.2 -fsSL https://static.pantsbuild.org/setup/get-pants.sh | bash

docs/data-sources/share.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,21 @@ output "share" {
2727

2828
### Read-Only
2929

30-
- `share` (Attributes List) (see [below for nested schema](#nestedatt--share))
30+
- `id` (String) The ID of this resource.
31+
- `shares` (Attributes List) (see [below for nested schema](#nestedatt--shares))
3132

32-
<a id="nestedatt--share"></a>
33-
### Nested Schema for `share`
33+
<a id="nestedatt--shares"></a>
34+
### Nested Schema for `shares`
3435

35-
Required:
36+
Read-Only:
3637

38+
- `active` (Boolean)
3739
- `created` (String)
3840
- `created_by` (String)
39-
- `id` (String)
40-
- `modified` (String)
41-
42-
Optional:
43-
44-
- `active` (Boolean)
4541
- `deleted` (Boolean)
4642
- `folder_parent_id` (String)
43+
- `id` (String)
44+
- `modified` (String)
4745
- `modified_by` (String)
4846
- `name` (String)
4947
- `role_id` (String)

internal/provider/share_data_source.go

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type shareDataSource struct {
2727
}
2828

2929
type shareDataSourceModel struct {
30+
ID types.String `tfsdk:"id"`
3031
Shares []shareModel `tfsdk:"shares"`
3132
}
3233

@@ -70,42 +71,45 @@ func (d *shareDataSource) Metadata(_ context.Context, req datasource.MetadataReq
7071
func (d *shareDataSource) Schema(_ context.Context, _ datasource.SchemaRequest, resp *datasource.SchemaResponse) {
7172
resp.Schema = schema.Schema{
7273
Attributes: map[string]schema.Attribute{
73-
"share": schema.ListNestedAttribute{
74+
"id": schema.StringAttribute{
75+
Optional: true,
76+
},
77+
"shares": schema.ListNestedAttribute{
7478
Computed: true,
7579
NestedObject: schema.NestedAttributeObject{
7680
Attributes: map[string]schema.Attribute{
7781
"id": schema.StringAttribute{
78-
Required: true,
82+
Computed: true,
7983
},
8084
"role_id": schema.StringAttribute{
81-
Optional: true,
85+
Computed: true,
8286
},
8387
"name": schema.StringAttribute{
84-
Optional: true,
88+
Computed: true,
8589
},
8690
"username": schema.StringAttribute{
87-
Optional: true,
91+
Computed: true,
8892
},
8993
"active": schema.BoolAttribute{
90-
Optional: true,
94+
Computed: true,
9195
},
9296
"deleted": schema.BoolAttribute{
93-
Optional: true,
97+
Computed: true,
9498
},
9599
"created": schema.StringAttribute{
96-
Required: true,
100+
Computed: true,
97101
},
98102
"modified": schema.StringAttribute{
99-
Required: true,
103+
Computed: true,
100104
},
101105
"created_by": schema.StringAttribute{
102-
Required: true,
106+
Computed: true,
103107
},
104108
"modified_by": schema.StringAttribute{
105-
Optional: true,
109+
Computed: true,
106110
},
107111
"folder_parent_id": schema.StringAttribute{
108-
Optional: true,
112+
Computed: true,
109113
},
110114
},
111115
},
@@ -117,11 +121,14 @@ func (d *shareDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
117121
// Read refreshes the Terraform state with the latest data.
118122
func (d *shareDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
119123
var state shareDataSourceModel
120-
var data shareModel
121-
diag := req.Config.Get(ctx, &data)
122-
resp.Diagnostics.Append(diag...)
123124

124-
shares, err := d.client.Client.SearchAROs(d.client.Context, api.SearchAROsOptions{FilterSearch: data.ID.String()})
125+
resp.Diagnostics.Append(req.Config.Get(ctx, &state)...)
126+
127+
var opts api.SearchAROsOptions
128+
if state.ID.String() != "" {
129+
opts = api.SearchAROsOptions{FilterSearch: state.ID.String()}
130+
}
131+
shares, err := d.client.Client.SearchAROs(d.client.Context, opts)
125132
if err != nil {
126133
resp.Diagnostics.AddError(
127134
"Unable to Read shares", "",
@@ -130,6 +137,7 @@ func (d *shareDataSource) Read(ctx context.Context, req datasource.ReadRequest,
130137
}
131138

132139
// Map response body to model
140+
state.Shares = make([]shareModel, 0)
133141
for _, share := range shares {
134142
shareState := shareModel{
135143
ID: types.StringValue(share.User.ID),

internal/provider/share_resource.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ func (r *shareResource) Read(ctx context.Context, req resource.ReadRequest, resp
132132
resp.Diagnostics.AddError(fmt.Sprintf("failed to lookup permission, folder: %s, share-target: %s, share-value: %s", data.Name.ValueString(), data.ShareTargetType.ValueString(), data.ShareTargetValue.ValueString()), err.Error())
133133
return
134134
}
135-
data.SharePermission = types.StringValue(fmt.Sprintf("%d", pem.Type))
135+
if pem != nil {
136+
data.SharePermission = types.StringValue(fmt.Sprintf("%d", pem.Type))
137+
}
136138

137139
diags = resp.State.Set(ctx, &data)
138140
resp.Diagnostics.Append(diags...)

tf-test/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
.envrc
2+
.terraform
3+
.terraform.lock.hcl
4+
.terraform.tfstate
5+
.terraform.tfstate.backup

tf-test/main.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,11 @@ resource "passbolt_share" "share-folder-with-group-open" {
3636
share_target_value = "group-open"
3737
share_permission = "1"
3838
}
39+
40+
41+
data "passbolt_share" "all" {}
42+
43+
output "share" {
44+
# `value` will be a list of all available share
45+
value = data.passbolt_share.all
46+
}

0 commit comments

Comments
 (0)