Skip to content

Commit 35a1c9c

Browse files
Copilottobio
andcommitted
Address PR feedback: simplify version, remove sensitive flag, read from config, delete extra files
Co-authored-by: tobio <[email protected]>
1 parent 4622dc8 commit 35a1c9c

File tree

7 files changed

+14
-88
lines changed

7 files changed

+14
-88
lines changed

docs/resources/kibana_import_saved_objects.md

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ Create sets of Kibana saved objects from a file created by the export API. See h
1212

1313
## Example Usage
1414

15-
### Basic usage
16-
1715
```terraform
1816
provider "elasticstack" {
1917
kibana {}
@@ -28,44 +26,14 @@ EOT
2826
}
2927
```
3028

31-
### Using write-only attributes
32-
33-
The `file_contents_wo` and `file_contents_wo_version` attributes provide write-only alternatives to `file_contents`.
34-
These attributes are not stored in the Terraform state, making them useful for sensitive content management.
35-
36-
```terraform
37-
provider "elasticstack" {
38-
kibana {}
39-
}
40-
41-
# Example using write-only file_contents_wo attribute
42-
resource "elasticstack_kibana_import_saved_objects" "settings_write_only" {
43-
overwrite = true
44-
file_contents_wo = <<-EOT
45-
{"attributes":{"buildNum":42747,"defaultIndex":"metricbeat-*","theme:darkMode":true},"coreMigrationVersion":"7.0.0","id":"7.14.0","managed":false,"references":[],"type":"config","typeMigrationVersion":"7.0.0","updated_at":"2021-08-04T02:04:43.306Z","version":"WzY1MiwyXQ=="}
46-
{"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":1,"missingRefCount":0,"missingReferences":[]}
47-
EOT
48-
}
49-
50-
# Example using write-only file_contents_wo with version tracking
51-
resource "elasticstack_kibana_import_saved_objects" "settings_with_version" {
52-
overwrite = true
53-
file_contents_wo = <<-EOT
54-
{"attributes":{"buildNum":42747,"defaultIndex":"metricbeat-*","theme:darkMode":true},"coreMigrationVersion":"7.0.0","id":"7.14.0","managed":false,"references":[],"type":"config","typeMigrationVersion":"7.0.0","updated_at":"2021-08-04T02:04:43.306Z","version":"WzY1MiwyXQ=="}
55-
{"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":1,"missingRefCount":0,"missingReferences":[]}
56-
EOT
57-
file_contents_wo_version = "v1.0.0"
58-
}
59-
```
60-
6129
<!-- schema generated by tfplugindocs -->
6230
## Schema
6331

6432
### Optional
6533

6634
- `file_contents` (String) The contents of the exported saved objects file.
6735
- `file_contents_wo` (String, Sensitive) The contents of the exported saved objects file (write-only, not stored in state).
68-
- `file_contents_wo_version` (String, Sensitive) Version or identifier for the file contents (write-only, not stored in state).
36+
- `file_contents_wo_version` (String) Version or identifier for the file contents (write-only, not stored in state).
6937
- `ignore_import_errors` (Boolean) If set to true, errors during the import process will not fail the configuration application
7038
- `overwrite` (Boolean) Overwrites saved objects when they already exist. When used, potential conflict errors are automatically resolved by overwriting the destination object.
7139
- `space_id` (String) An identifier for the space. If space_id is not provided, the default space is used.

examples/resources/elasticstack_kibana_import_saved_objects/resource-write-only.tf

Lines changed: 0 additions & 22 deletions
This file was deleted.

internal/kibana/import_saved_objects/acc_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ resource "elasticstack_kibana_import_saved_objects" "wo_version_test" {
162162
{"attributes":{"buildNum":42747,"defaultIndex":"metricbeat-*","theme:darkMode":true},"coreMigrationVersion":"7.0.0","id":"7.14.0","managed":false,"references":[],"type":"config","typeMigrationVersion":"7.0.0","updated_at":"2021-08-04T02:04:43.306Z","version":"WzY1MiwyXQ=="}
163163
{"excludedObjects":[],"excludedObjectsCount":0,"exportedCount":1,"missingRefCount":0,"missingReferences":[]}
164164
EOT
165-
file_contents_wo_version = "v1.0.0"
165+
file_contents_wo_version = "1"
166166
}
167167
`
168168
}

internal/kibana/import_saved_objects/create.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
)
1616

1717
func (r *Resource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) {
18-
r.importObjects(ctx, request.Plan, &response.State, &response.Diagnostics)
18+
r.importObjects(ctx, request.Plan, request.Config, &response.State, &response.Diagnostics)
1919
}
2020

21-
func (r *Resource) importObjects(ctx context.Context, plan tfsdk.Plan, state *tfsdk.State, diags *diag.Diagnostics) {
21+
func (r *Resource) importObjects(ctx context.Context, plan tfsdk.Plan, config tfsdk.Config, state *tfsdk.State, diags *diag.Diagnostics) {
2222
var model modelV0
2323

2424
diags.Append(plan.Get(ctx, &model)...)
@@ -33,9 +33,16 @@ func (r *Resource) importObjects(ctx context.Context, plan tfsdk.Plan, state *tf
3333
}
3434

3535
// Determine which file contents to use (file_contents or file_contents_wo)
36+
// Read write-only attributes from config as per Terraform best practices
37+
var fileContentsWO types.String
38+
diags.Append(config.GetAttribute(ctx, path.Root("file_contents_wo"), &fileContentsWO)...)
39+
if diags.HasError() {
40+
return
41+
}
42+
3643
fileContents := model.FileContents.ValueString()
37-
if !model.FileContentsWO.IsNull() && !model.FileContentsWO.IsUnknown() {
38-
fileContents = model.FileContentsWO.ValueString()
44+
if !fileContentsWO.IsNull() && !fileContentsWO.IsUnknown() {
45+
fileContents = fileContentsWO.ValueString()
3946
}
4047

4148
resp, err := kibanaClient.KibanaSavedObject.Import([]byte(fileContents), model.Overwrite.ValueBool(), model.SpaceID.ValueString())

internal/kibana/import_saved_objects/schema.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ func (r *Resource) Schema(_ context.Context, _ resource.SchemaRequest, resp *res
9595
"file_contents_wo_version": schema.StringAttribute{
9696
Description: "Version or identifier for the file contents (write-only, not stored in state).",
9797
Optional: true,
98-
Sensitive: true,
9998
Validators: []validator.String{
10099
stringvalidator.AlsoRequires(path.MatchRoot("file_contents_wo")),
101100
},

internal/kibana/import_saved_objects/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ import (
77
)
88

99
func (r *Resource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) {
10-
r.importObjects(ctx, request.Plan, &response.State, &response.Diagnostics)
10+
r.importObjects(ctx, request.Plan, request.Config, &response.State, &response.Diagnostics)
1111
}

templates/resources/kibana_import_saved_objects.md.tmpl

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)