Skip to content

Commit c7e19e3

Browse files
authored
Merge pull request #9 from TerraformInDepth/doc_updates
Update Docs, Copyright, Add Preserve on Destroy
2 parents ab922f7 + ab5b6ff commit c7e19e3

File tree

11 files changed

+92
-85
lines changed

11 files changed

+92
-85
lines changed

LICENSE

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
Copyright (c) 2021 HashiCorp, Inc.
1+
Original Template Copyright (c) 2021 HashiCorp, Inc.
2+
Mastodon Provider Copyright (c) 2024 Robert Hafner
23

34
Mozilla Public License Version 2.0
45
==================================
56

67
1. Definitions
8+
79
--------------
810

911
1.1. "Contributor"
@@ -86,6 +88,7 @@ Mozilla Public License Version 2.0
8688
ownership of such entity.
8789

8890
2. License Grants and Conditions
91+
8992
--------------------------------
9093

9194
2.1. Grants
@@ -157,6 +160,7 @@ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
157160
in Section 2.1.
158161

159162
3. Responsibilities
163+
160164
-------------------
161165

162166
3.1. Distribution of Source Form
@@ -219,6 +223,7 @@ disclaimers of warranty and limitations of liability specific to any
219223
jurisdiction.
220224

221225
4. Inability to Comply Due to Statute or Regulation
226+
222227
---------------------------------------------------
223228

224229
If it is impossible for You to comply with any of the terms of this
@@ -232,6 +237,7 @@ or regulation, such description must be sufficiently detailed for a
232237
recipient of ordinary skill to be able to understand it.
233238

234239
5. Termination
240+
235241
--------------
236242

237243
5.1. The rights granted under this License will terminate automatically
@@ -261,48 +267,53 @@ have been validly granted by You or Your distributors under this License
261267
prior to termination shall survive termination.
262268

263269
************************************************************************
270+
264271
* *
265-
* 6. Disclaimer of Warranty *
266-
* ------------------------- *
272+
* 6. Disclaimer of Warranty *
273+
* ------------------------- *
267274
* *
268-
* Covered Software is provided under this License on an "as is" *
269-
* basis, without warranty of any kind, either expressed, implied, or *
270-
* statutory, including, without limitation, warranties that the *
271-
* Covered Software is free of defects, merchantable, fit for a *
272-
* particular purpose or non-infringing. The entire risk as to the *
273-
* quality and performance of the Covered Software is with You. *
274-
* Should any Covered Software prove defective in any respect, You *
275-
* (not any Contributor) assume the cost of any necessary servicing, *
276-
* repair, or correction. This disclaimer of warranty constitutes an *
277-
* essential part of this License. No use of any Covered Software is *
278-
* authorized under this License except under this disclaimer. *
275+
* Covered Software is provided under this License on an "as is" *
276+
* basis, without warranty of any kind, either expressed, implied, or *
277+
* statutory, including, without limitation, warranties that the *
278+
* Covered Software is free of defects, merchantable, fit for a *
279+
* particular purpose or non-infringing. The entire risk as to the *
280+
* quality and performance of the Covered Software is with You. *
281+
* Should any Covered Software prove defective in any respect, You *
282+
* (not any Contributor) assume the cost of any necessary servicing, *
283+
* repair, or correction. This disclaimer of warranty constitutes an *
284+
* essential part of this License. No use of any Covered Software is *
285+
* authorized under this License except under this disclaimer. *
279286
* *
287+
280288
************************************************************************
281289

282290
************************************************************************
291+
283292
* *
284-
* 7. Limitation of Liability *
285-
* -------------------------- *
293+
* 7. Limitation of Liability *
294+
* -------------------------- *
286295
* *
287-
* Under no circumstances and under no legal theory, whether tort *
288-
* (including negligence), contract, or otherwise, shall any *
289-
* Contributor, or anyone who distributes Covered Software as *
290-
* permitted above, be liable to You for any direct, indirect, *
291-
* special, incidental, or consequential damages of any character *
292-
* including, without limitation, damages for lost profits, loss of *
293-
* goodwill, work stoppage, computer failure or malfunction, or any *
294-
* and all other commercial damages or losses, even if such party *
295-
* shall have been informed of the possibility of such damages. This *
296-
* limitation of liability shall not apply to liability for death or *
297-
* personal injury resulting from such party's negligence to the *
298-
* extent applicable law prohibits such limitation. Some *
299-
* jurisdictions do not allow the exclusion or limitation of *
300-
* incidental or consequential damages, so this exclusion and *
301-
* limitation may not apply to You. *
296+
* Under no circumstances and under no legal theory, whether tort *
297+
* (including negligence), contract, or otherwise, shall any *
298+
* Contributor, or anyone who distributes Covered Software as *
299+
* permitted above, be liable to You for any direct, indirect, *
300+
* special, incidental, or consequential damages of any character *
301+
* including, without limitation, damages for lost profits, loss of *
302+
* goodwill, work stoppage, computer failure or malfunction, or any *
303+
* and all other commercial damages or losses, even if such party *
304+
* shall have been informed of the possibility of such damages. This *
305+
* limitation of liability shall not apply to liability for death or *
306+
* personal injury resulting from such party's negligence to the *
307+
* extent applicable law prohibits such limitation. Some *
308+
* jurisdictions do not allow the exclusion or limitation of *
309+
* incidental or consequential damages, so this exclusion and *
310+
* limitation may not apply to You. *
302311
* *
312+
303313
************************************************************************
304314

305315
8. Litigation
316+
306317
-------------
307318

308319
Any litigation relating to this License may be brought only in the
@@ -313,6 +324,7 @@ Nothing in this Section shall prevent a party's ability to bring
313324
cross-claims or counter-claims.
314325

315326
9. Miscellaneous
327+
316328
----------------
317329

318330
This License represents the complete agreement concerning the subject
@@ -323,6 +335,7 @@ that the language of a contract shall be construed against the drafter
323335
shall not be used to construe this License against a Contributor.
324336

325337
10. Versions of the License
338+
326339
---------------------------
327340

328341
10.1. New Versions
@@ -359,7 +372,7 @@ Exhibit A - Source Code Form License Notice
359372

360373
This Source Code Form is subject to the terms of the Mozilla Public
361374
License, v. 2.0. If a copy of the MPL was not distributed with this
362-
file, You can obtain one at http://mozilla.org/MPL/2.0/.
375+
file, You can obtain one at <http://mozilla.org/MPL/2.0/>.
363376

364377
If it is not possible or desirable to put the notice in a particular
365378
file, then You may include the notice in a location (such as a LICENSE

docs/data-sources/account.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ data "mastodon_account" "example" {
2323

2424
### Required
2525

26-
- `username` (String) Account configurable attribute
26+
- `username` (String) The username of the account to lookup. This should include the domain.
2727

2828
### Read-Only
2929

30-
- `bot` (Boolean)
31-
- `display_name` (String)
32-
- `id` (String) Account identifier
33-
- `locked` (Boolean)
34-
- `note` (String)
30+
- `bot` (Boolean) Whether the account is a bot or not.
31+
- `display_name` (String) The account's display name.
32+
- `id` (String) A unique account identifier retrieved from the server.
33+
- `locked` (Boolean) Whether the account is locked or not.
34+
- `note` (String) The note or biography of the account.

docs/resources/post.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ Post resource
1717

1818
### Required
1919

20-
- `content` (String) Post content
20+
- `content` (String) The content of the post.
2121

2222
### Optional
2323

24-
- `sensitive` (Boolean) Post sensitive
25-
- `visibility` (String) Post visibility
24+
- `preserve_on_destroy` (Boolean) When destroyed, preserve the post on the server.
25+
- `sensitive` (Boolean) Whether the post contains sensitive content.
26+
- `visibility` (String) The post visibility: can be `public`, `unlisted`, `private`, or `direct`.
2627

2728
### Read-Only
2829

2930
- `account` (String) Account that created the post
30-
- `created_at` (String) Post creation timestamp
31-
- `id` (String) Post identifier
31+
- `created_at` (String) Timestamp of when the post was created.
32+
- `id` (String) Unique identifier of the post.

internal/provider/account_data_source.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (
@@ -47,36 +44,36 @@ func (d *AccountDataSource) Schema(ctx context.Context, req datasource.SchemaReq
4744

4845
Attributes: map[string]schema.Attribute{
4946
"username": schema.StringAttribute{
50-
MarkdownDescription: "Account configurable attribute",
47+
MarkdownDescription: "The username of the account to lookup. This should include the domain.",
5148
Optional: false,
5249
Required: true,
5350
},
5451
"id": schema.StringAttribute{
55-
MarkdownDescription: "Account identifier",
52+
MarkdownDescription: "A unique account identifier retrieved from the server.",
5653
Computed: true,
5754
Optional: false,
5855
Required: false,
5956
},
6057
"display_name": schema.StringAttribute{
61-
MarkdownDescription: "",
58+
MarkdownDescription: "The account's display name.",
6259
Computed: true,
6360
Optional: false,
6461
Required: false,
6562
},
6663
"note": schema.StringAttribute{
67-
MarkdownDescription: "",
64+
MarkdownDescription: "The note or biography of the account.",
6865
Computed: true,
6966
Optional: false,
7067
Required: false,
7168
},
7269
"locked": schema.BoolAttribute{
73-
MarkdownDescription: "",
70+
MarkdownDescription: "Whether the account is locked or not.",
7471
Computed: true,
7572
Optional: false,
7673
Required: false,
7774
},
7875
"bot": schema.BoolAttribute{
79-
MarkdownDescription: "",
76+
MarkdownDescription: "Whether the account is a bot or not.",
8077
Computed: true,
8178
Optional: false,
8279
Required: false,

internal/provider/account_data_source_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (

internal/provider/identity_function.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (

internal/provider/identity_function_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (

internal/provider/post_resource.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (
@@ -35,12 +32,13 @@ type PostResource struct {
3532

3633
// PostResourceModel describes the resource data model.
3734
type PostResourceModel struct {
38-
Id types.String `tfsdk:"id"`
39-
CreatedAt types.String `tfsdk:"created_at"`
40-
Account types.String `tfsdk:"account"`
41-
Content types.String `tfsdk:"content"`
42-
Visibility types.String `tfsdk:"visibility"`
43-
Sensitive types.Bool `tfsdk:"sensitive"`
35+
Id types.String `tfsdk:"id"`
36+
CreatedAt types.String `tfsdk:"created_at"`
37+
Account types.String `tfsdk:"account"`
38+
Content types.String `tfsdk:"content"`
39+
Visibility types.String `tfsdk:"visibility"`
40+
Sensitive types.Bool `tfsdk:"sensitive"`
41+
PreserveOnDestroy types.Bool `tfsdk:"preserve_on_destroy"`
4442
}
4543

4644
func (r *PostResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
@@ -57,13 +55,13 @@ func (r *PostResource) Schema(ctx context.Context, req resource.SchemaRequest, r
5755
Computed: true,
5856
Required: false,
5957
Optional: false,
60-
MarkdownDescription: "Post identifier",
58+
MarkdownDescription: "Unique identifier of the post.",
6159
PlanModifiers: []planmodifier.String{
6260
stringplanmodifier.UseStateForUnknown(),
6361
},
6462
},
6563
"created_at": schema.StringAttribute{
66-
MarkdownDescription: "Post creation timestamp",
64+
MarkdownDescription: "Timestamp of when the post was created.",
6765
Computed: true,
6866
Required: false,
6967
Optional: false,
@@ -81,17 +79,23 @@ func (r *PostResource) Schema(ctx context.Context, req resource.SchemaRequest, r
8179
},
8280
},
8381
"content": schema.StringAttribute{
84-
MarkdownDescription: "Post content",
82+
MarkdownDescription: "The content of the post.",
8583
Required: true,
8684
},
8785
"visibility": schema.StringAttribute{
88-
MarkdownDescription: "Post visibility",
86+
MarkdownDescription: "The post visibility: can be `public`, `unlisted`, `private`, or `direct`.",
8987
Optional: true,
9088
Computed: true,
9189
Default: stringdefault.StaticString("public"),
9290
},
9391
"sensitive": schema.BoolAttribute{
94-
MarkdownDescription: "Post sensitive",
92+
MarkdownDescription: "Whether the post contains sensitive content.",
93+
Optional: true,
94+
Computed: true,
95+
Default: booldefault.StaticBool(false),
96+
},
97+
"preserve_on_destroy": schema.BoolAttribute{
98+
MarkdownDescription: "When destroyed, preserve the post on the server.",
9599
Optional: true,
96100
Computed: true,
97101
Default: booldefault.StaticBool(false),
@@ -187,6 +191,11 @@ func (r *PostResource) Read(ctx context.Context, req resource.ReadRequest, resp
187191
data.Visibility = types.StringValue(post.Visibility)
188192
data.Sensitive = types.BoolValue(post.Sensitive)
189193

194+
// During imports the `preserve_on_destroy` attribute may not be set.
195+
if data.PreserveOnDestroy.IsNull() {
196+
data.PreserveOnDestroy = types.BoolValue(false)
197+
}
198+
190199
// Save updated data into Terraform state
191200
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
192201
}
@@ -237,10 +246,15 @@ func (r *PostResource) Delete(ctx context.Context, req resource.DeleteRequest, r
237246
return
238247
}
239248

249+
if data.PreserveOnDestroy.ValueBool() {
250+
tflog.Debug(ctx, "preserve_on_destroy is enabled: preserving post on server.")
251+
return
252+
}
253+
240254
err := r.client.DeleteStatus(context.Background(), mastodon.ID(data.Id.ValueString()))
241255

242256
if err != nil {
243-
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to create post, got error: %s", err))
257+
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to delete post, got error: %s", err))
244258
return
245259
}
246260

internal/provider/post_resource_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (

internal/provider/provider.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright (c) HashiCorp, Inc.
2-
// SPDX-License-Identifier: MPL-2.0
3-
41
package provider
52

63
import (

0 commit comments

Comments
 (0)