Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle write-only properties #86

Merged
merged 8 commits into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
261 changes: 261 additions & 0 deletions internal/aws/kms/key_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions internal/aws/kms/key_gen_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions internal/generic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,8 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,

tflog.Debug(ctx, "Resource.Read enter", "cfTypeName", cfTypeName, "tfTypeName", tfTypeName)

tflog.Debug(ctx, "Request.State.Raw", "value", hclog.Fmt("%v", request.State.Raw))

conn := r.provider.CloudFormationClient(ctx)

currentState := &request.State
Expand Down Expand Up @@ -446,15 +448,27 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,
return
}

// TODO
// TODO Consider write-only values. They can only be in the current state.
// TODO

response.State = tfsdk.State{
Schema: *schema,
Raw: val,
}

// Copy over any write-only values.
// They can only be in the current state.
for _, path := range r.resourceType.writeOnlyAttributePaths {
err = CopyValueAtPath(ctx, &response.State, &request.State, path)

if err != nil {
response.Diagnostics = append(response.Diagnostics, &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Terraform State Value Not Set",
Detail: fmt.Sprintf("Unable to set Terraform State value %s. This is typically an error with the Terraform provider implementation. Original Error: %s", path, err.Error()),
})

return
}
}

// Set the "id" attribute.
err = r.setId(ctx, id, &response.State)

Expand All @@ -464,6 +478,8 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,
return
}

tflog.Debug(ctx, "Response.State.Raw", "value", hclog.Fmt("%v", response.State.Raw))

tflog.Debug(ctx, "Resource.Read exit", "cfTypeName", cfTypeName, "tfTypeName", tfTypeName)
}

Expand Down
Loading