-
Notifications
You must be signed in to change notification settings - Fork 97
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
Request and response types #27
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
// ConfigureProviderRequest represents a request supplying the provider with | ||
// the values the user supplied for the provider configuration block, along with | ||
// other runtime information supplied by Terraform or the Plugin SDK. An | ||
// instance of this request struct is supplied as an argument to the provider's | ||
// Configure function. | ||
type ConfigureProviderRequest struct { | ||
// TerraformVersion is the version of Terraform executing the request. | ||
// This is supplied for logging, analytics, and User-Agent purposes | ||
// only. Providers should not try to gate provider behavior on | ||
// Terraform versions. | ||
TerraformVersion string | ||
|
||
// Config is the configuration the user supplied for the provider. This | ||
// information should usually be persisted to the underlying type | ||
// that's implementing the Provider interface, for use in later | ||
// resource CRUD operations. | ||
Config *tftypes.Value | ||
} | ||
|
||
// CreateResourceRequest represents a request for the provider to create a | ||
// resource. An instance of this request struct is supplied as an argument to | ||
// the resource's Create function. | ||
type CreateResourceRequest struct { | ||
// Config is the configuration the user supplied for the resource. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
// TODO uncomment when implemented | ||
// Config Config | ||
|
||
// Plan is the planned state for the resource. | ||
// TODO uncomment when implemented | ||
// Plan Plan | ||
} | ||
|
||
// ReadResourceRequest represents a request for the provider to read a | ||
// resource, i.e., update values in state according to the real state of the | ||
// resource. An instance of this request struct is supplied as an argument to | ||
// the resource's Read function. | ||
type ReadResourceRequest struct { | ||
// tfprotov6.ReadResourceRequest has no Config field | ||
// Config Config | ||
|
||
// State is the current state of the resource prior to the Read | ||
// operation. | ||
// TODO uncomment when implemented | ||
// State State | ||
} | ||
|
||
// UpdateResourceRequest represents a request for the provider to update a | ||
// resource. An instance of this request struct is supplied as an argument to | ||
// the resource's Update function. | ||
type UpdateResourceRequest struct { | ||
// Config is the configuration the user supplied for the resource. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
// TODO uncomment when implemented | ||
// Config Config | ||
|
||
// Plan is the planned state for the resource. | ||
// TODO uncomment when implemented | ||
// Plan Plan | ||
|
||
// State is the current state of the resource prior to the Update | ||
// operation. | ||
// TODO uncomment when implemented | ||
// State State | ||
} | ||
|
||
// DeleteResourceRequest represents a request for the provider to delete a | ||
// resource. An instance of this request struct is supplied as an argument to | ||
// the resource's Delete function. | ||
type DeleteResourceRequest struct { | ||
// Config is the configuration the user supplied for the resource. | ||
// | ||
// This configuration may contain unknown values if a user uses | ||
// interpolation or other functionality that would prevent Terraform | ||
// from knowing the value at request time. | ||
// TODO uncomment when implemented | ||
// Config Config | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,289 @@ | ||
package tfsdk | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-go/tftypes" | ||
) | ||
|
||
// ConfigureProviderResponse represents a response to a | ||
// ConfigureProviderRequest. An instance of this response struct is supplied as | ||
// an argument to the provider's Configure function, in which the provider | ||
// should set values on the ConfigureProviderResponse as appropriate. | ||
type ConfigureProviderResponse struct { | ||
// Diagnostics report errors or warnings related to configuring the | ||
// provider. An empty slice indicates success, with no warnings or | ||
// errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// AddWarning appends a warning diagnostic to the response. If the warning | ||
// concerns a particular attribute, AddAttributeWarning should be used instead. | ||
func (r *ConfigureProviderResponse) AddWarning(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddAttributeWarning appends a warning diagnostic to the response and labels | ||
// it with a specific attribute. | ||
func (r *ConfigureProviderResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddError appends an error diagnostic to the response. If the error concerns a | ||
// particular attribute, AddAttributeError should be used instead. | ||
func (r *ConfigureProviderResponse) AddError(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// AddAttributeError appends an error diagnostic to the response and labels it | ||
// with a specific attribute. | ||
func (r *ConfigureProviderResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// CreateResourceResponse represents a response to a CreateResourceRequest. An | ||
// instance of this response struct is supplied as | ||
// an argument to the resource's Create function, in which the provider | ||
// should set values on the CreateResourceResponse as appropriate. | ||
type CreateResourceResponse struct { | ||
// State is the state of the resource following the Create operation. | ||
// This field is pre-populated from CreateResourceRequest.Plan and | ||
// should be set during the resource's Create operation. | ||
// TODO uncomment when implemented | ||
// State State | ||
|
||
// Diagnostics report errors or warnings related to creating the | ||
// resource. An empty slice indicates a successful operation with no | ||
// warnings or errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// AddWarning appends a warning diagnostic to the response. If the warning | ||
// concerns a particular attribute, AddAttributeWarning should be used instead. | ||
func (r *CreateResourceResponse) AddWarning(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddAttributeWarning appends a warning diagnostic to the response and labels | ||
// it with a specific attribute. | ||
func (r *CreateResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddError appends an error diagnostic to the response. If the error concerns a | ||
// particular attribute, AddAttributeError should be used instead. | ||
func (r *CreateResourceResponse) AddError(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// AddAttributeError appends an error diagnostic to the response and labels it | ||
// with a specific attribute. | ||
func (r *CreateResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// ReadResourceResponse represents a response to a ReadResourceRequest. An | ||
// instance of this response struct is supplied as | ||
// an argument to the resource's Read function, in which the provider | ||
// should set values on the ReadResourceResponse as appropriate. | ||
type ReadResourceResponse struct { | ||
// State is the state of the resource following the Read operation. | ||
// This field is pre-populated from ReadResourceRequest.State and | ||
// should be set during the resource's Read operation. | ||
// TODO uncomment when implemented | ||
// State State | ||
|
||
// Diagnostics report errors or warnings related to reading the | ||
// resource. An empty slice indicates a successful operation with no | ||
// warnings or errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// AddWarning appends a warning diagnostic to the response. If the warning | ||
// concerns a particular attribute, AddAttributeWarning should be used instead. | ||
func (r *ReadResourceResponse) AddWarning(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddAttributeWarning appends a warning diagnostic to the response and labels | ||
// it with a specific attribute. | ||
func (r *ReadResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddError appends an error diagnostic to the response. If the error concerns a | ||
// particular attribute, AddAttributeError should be used instead. | ||
func (r *ReadResourceResponse) AddError(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// AddAttributeError appends an error diagnostic to the response and labels it | ||
// with a specific attribute. | ||
func (r *ReadResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// UpdateResourceResponse represents a response to an UpdateResourceRequest. An | ||
// instance of this response struct is supplied as | ||
// an argument to the resource's Update function, in which the provider | ||
// should set values on the UpdateResourceResponse as appropriate. | ||
type UpdateResourceResponse struct { | ||
// State is the state of the resource following the Update operation. | ||
// This field is pre-populated from UpdateResourceRequest.Plan and | ||
// should be set during the resource's Update operation. | ||
// TODO uncomment when implemented | ||
// State State | ||
|
||
// Diagnostics report errors or warnings related to updating the | ||
// resource. An empty slice indicates a successful operation with no | ||
// warnings or errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// AddWarning appends a warning diagnostic to the response. If the warning | ||
// concerns a particular attribute, AddAttributeWarning should be used instead. | ||
func (r *UpdateResourceResponse) AddWarning(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddAttributeWarning appends a warning diagnostic to the response and labels | ||
// it with a specific attribute. | ||
func (r *UpdateResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddError appends an error diagnostic to the response. If the error concerns a | ||
// particular attribute, AddAttributeError should be used instead. | ||
func (r *UpdateResourceResponse) AddError(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// AddAttributeError appends an error diagnostic to the response and labels it | ||
// with a specific attribute. | ||
func (r *UpdateResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// DeleteResourceResponse represents a response to a DeleteResourceRequest. An | ||
// instance of this response struct is supplied as | ||
// an argument to the resource's Delete function, in which the provider | ||
// should set values on the DeleteResourceResponse as appropriate. | ||
type DeleteResourceResponse struct { | ||
// Diagnostics report errors or warnings related to deleting the | ||
// resource. An empty slice indicates a successful operation with no | ||
// warnings or errors generated. | ||
Diagnostics []*tfprotov6.Diagnostic | ||
} | ||
|
||
// AddWarning appends a warning diagnostic to the response. If the warning | ||
// concerns a particular attribute, AddAttributeWarning should be used instead. | ||
func (r *DeleteResourceResponse) AddWarning(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddAttributeWarning appends a warning diagnostic to the response and labels | ||
// it with a specific attribute. | ||
func (r *DeleteResourceResponse) AddAttributeWarning(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityWarning, | ||
}) | ||
} | ||
|
||
// AddError appends an error diagnostic to the response. If the error concerns a | ||
// particular attribute, AddAttributeError should be used instead. | ||
func (r *DeleteResourceResponse) AddError(summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} | ||
|
||
// AddAttributeError appends an error diagnostic to the response and labels it | ||
// with a specific attribute. | ||
func (r *DeleteResourceResponse) AddAttributeError(attributePath *tftypes.AttributePath, summary, detail string) { | ||
r.Diagnostics = append(r.Diagnostics, &tfprotov6.Diagnostic{ | ||
Attribute: attributePath, | ||
Summary: summary, | ||
Detail: detail, | ||
Severity: tfprotov6.DiagnosticSeverityError, | ||
}) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no
Config
field intfprotov6.ReadResourceRequest
. Should providers have access to config during Read?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe providers only have access to the existing state during read.