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

Use terraform-plugin-framework@v0.3.0 #141

Merged
merged 6 commits into from
Sep 8, 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ replace github.com/aws/aws-sdk-go-v2/service/cloudformation => github.com/hashic

replace github.com/aws/aws-sdk-go-v2/credentials => github.com/gdavison/aws-sdk-go-v2/credentials v1.2.2-0.20210811194025-146c1ad6c3b2

replace github.com/hashicorp/terraform-plugin-framework => github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210902190237-e20bf3555d0c
replace github.com/hashicorp/terraform-plugin-framework => github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210908155737-cef60d646d77
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210902181543-57c53acf
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210902181543-57c53acf8fa2/go.mod h1:JcYLIMJDUnOrPRSdbjRsNaJcOExNuPdZ6MS+OIBHjyE=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210902190237-e20bf3555d0c h1:HhE2mW8Ao+XRk7BCGhKF80dEB3r+YxMoaVLKI0IJr1Q=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210902190237-e20bf3555d0c/go.mod h1:JcYLIMJDUnOrPRSdbjRsNaJcOExNuPdZ6MS+OIBHjyE=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210908121805-ccf7ab658548 h1:XUFwM1ZpRawpDcEWKFE+tnNwHOoria0Hiq/e7SAum+Y=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210908121805-ccf7ab658548/go.mod h1:9pDOoxcGdAKOjDWUpa+QOpj2npeJvgf4imnwYBTwIq8=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210908155737-cef60d646d77 h1:EqGVXBO/5nVzp5OqTHUDn86isb8kXiRRxSPSRIg/3tc=
github.com/ewbankkit/terraform-plugin-framework v0.2.1-0.20210908155737-cef60d646d77/go.mod h1:9pDOoxcGdAKOjDWUpa+QOpj2npeJvgf4imnwYBTwIq8=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
Expand Down
90 changes: 41 additions & 49 deletions internal/generic/diagnostic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,61 @@ package generic
import (
"fmt"

"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-framework/diag"
)

func DesiredStateErrorDiag(source string, err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Creation Of CloudFormation Desired State Unsuccessful",
Detail: fmt.Sprintf("Unable to create CloudFormation Desired State from Terraform %s. This is typically an error with the Terraform provider implementation. Original Error: %s", source, err.Error()),
}
func DesiredStateErrorDiag(source string, err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"Creation Of CloudFormation Desired State Unsuccessful",
fmt.Sprintf("Unable to create CloudFormation Desired State from Terraform %s. This is typically an error with the Terraform provider implementation. Original Error: %s", source, err.Error()),
)
}

func ResourceIdentifierNotFoundDiag(err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Terraform Resource Identifier Not Found",
Detail: fmt.Sprintf("Terraform resource primary identifier not found in State. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
}
func ResourceIdentifierNotFoundDiag(err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"Terraform Resource Identifier Not Found",
fmt.Sprintf("Terraform resource primary identifier not found in State. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)
}

func ResourceIdentifierNotSetDiag(err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Terraform Resource Identifier Not Set",
Detail: fmt.Sprintf("Terraform resource primary identifier not set in State. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
}
func ResourceIdentifierNotSetDiag(err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"Terraform Resource Identifier Not Set",
fmt.Sprintf("Terraform resource primary identifier not set in State. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)
}

func ResourceNotFoundAfterCreationDiag(err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "AWS Resource Not Found After Creation",
Detail: fmt.Sprintf("After creating the AWS resource and attempting to read the resource, the API returned a resource not found error. This is typically an error with the Terraform resource implementation. Original Error: %s", err.Error()),
}
func ResourceNotFoundAfterCreationDiag(err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"AWS Resource Not Found After Creation",
fmt.Sprintf("After creating the AWS resource and attempting to read the resource, the API returned a resource not found error. This is typically an error with the Terraform resource implementation. Original Error: %s", err.Error()),
)
}

func ResourceNotFoundWarningDiag(err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityWarning,
Summary: "AWS Resource Not Found During Refresh",
Detail: fmt.Sprintf("Automatically removing from Terraform State instead of returning the error, which may trigger resource recreation. Original Error: %s", err.Error()),
}
func ResourceNotFoundWarningDiag(err error) diag.Diagnostic {
return diag.NewWarningDiagnostic(
"AWS Resource Not Found During Refresh",
fmt.Sprintf("Automatically removing from Terraform State instead of returning the error, which may trigger resource recreation. Original Error: %s", err.Error()),
)
}

func ServiceOperationEmptyResultDiag(service string, operation string) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "AWS SDK Go Service Operation Empty Response",
Detail: fmt.Sprintf("Calling %s service %s operation returned missing contents in the response. This is typically an error with the API implementation.", service, operation),
}
func ServiceOperationEmptyResultDiag(service string, operation string) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"AWS SDK Go Service Operation Empty Response",
fmt.Sprintf("Calling %s service %s operation returned missing contents in the response. This is typically an error with the API implementation.", service, operation),
)
}

func ServiceOperationErrorDiag(service string, operation string, err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "AWS SDK Go Service Operation Unsuccessful",
Detail: fmt.Sprintf("Calling %s service %s operation returned: %s", service, operation, err.Error()),
}
func ServiceOperationErrorDiag(service string, operation string, err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"AWS SDK Go Service Operation Unsuccessful",
fmt.Sprintf("Calling %s service %s operation returned: %s", service, operation, err.Error()),
)
}

func ServiceOperationWaiterErrorDiag(service string, operation string, err error) *tfprotov6.Diagnostic {
return &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "AWS SDK Go Service Operation Incomplete",
Detail: fmt.Sprintf("Waiting for %s service %s operation completion returned: %s", service, operation, err.Error()),
}
func ServiceOperationWaiterErrorDiag(service string, operation string, err error) diag.Diagnostic {
return diag.NewErrorDiagnostic(
"AWS SDK Go Service Operation Incomplete",
fmt.Sprintf("Waiting for %s service %s operation completion returned: %s", service, operation, err.Error()),
)
}
8 changes: 4 additions & 4 deletions internal/generic/plural_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
cftypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tftypes"
tflog "github.com/hashicorp/terraform-plugin-log"
tfcloudformation "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudformation"
Expand Down Expand Up @@ -51,11 +51,11 @@ func (pdt *PluralDataSourceType) New(dst *DataSourceType) *PluralDataSourceType
}
}

func (pdt *PluralDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, []*tfprotov6.Diagnostic) {
func (pdt *PluralDataSourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
return pdt.tfSchema, nil
}

func (pdt *PluralDataSourceType) NewDataSource(ctx context.Context, provider tfsdk.Provider) (tfsdk.DataSource, []*tfprotov6.Diagnostic) {
func (pdt *PluralDataSourceType) NewDataSource(ctx context.Context, provider tfsdk.Provider) (tfsdk.DataSource, diag.Diagnostics) {
return newGenericPluralDataSource(provider, pdt), nil
}

Expand Down Expand Up @@ -85,7 +85,7 @@ func (pd *pluralDataSource) Read(ctx context.Context, _ tfsdk.ReadDataSourceRequ
descriptions, err := pd.list(ctx, conn)

if err != nil {
response.Diagnostics = append(response.Diagnostics, ServiceOperationErrorDiag("CloudFormation", "ListResources", err))
response.Diagnostics.Append(ServiceOperationErrorDiag("CloudFormation", "ListResources", err))

return
}
Expand Down
55 changes: 25 additions & 30 deletions internal/generic/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/cloudformation"
cftypes "github.com/aws/aws-sdk-go-v2/service/cloudformation/types"
hclog "github.com/hashicorp/go-hclog"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
"github.com/hashicorp/terraform-plugin-go/tftypes"
tflog "github.com/hashicorp/terraform-plugin-log"
tfcloudformation "github.com/hashicorp/terraform-provider-awscc/internal/service/cloudformation"
Expand Down Expand Up @@ -333,11 +333,11 @@ func NewResourceType(_ context.Context, optFns ...ResourceTypeOptionsFunc) (tfsd
return resourceType, nil
}

func (rt *resourceType) GetSchema(ctx context.Context) (tfsdk.Schema, []*tfprotov6.Diagnostic) {
func (rt *resourceType) GetSchema(ctx context.Context) (tfsdk.Schema, diag.Diagnostics) {
return rt.tfSchema, nil
}

func (rt *resourceType) NewResource(ctx context.Context, provider tfsdk.Provider) (tfsdk.Resource, []*tfprotov6.Diagnostic) {
func (rt *resourceType) NewResource(ctx context.Context, provider tfsdk.Provider) (tfsdk.Resource, diag.Diagnostics) {
return newGenericResource(provider, rt), nil
}

Expand Down Expand Up @@ -487,23 +487,21 @@ func (r *resource) Create(ctx context.Context, request tfsdk.CreateResourceReque
unknowns, err := Unknowns(ctx, response.State.Raw, r.resourceType.tfToCfNameMap)

if err != nil {
response.Diagnostics = append(response.Diagnostics, &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Creation Of Terraform State Unsuccessful",
Detail: fmt.Sprintf("Unable to set Terraform State Unknown values from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
})
response.Diagnostics.AddError(
"Creation Of Terraform State Unsuccessful",
fmt.Sprintf("Unable to set Terraform State Unknown values from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)

return
}

err = unknowns.SetValuesFromString(ctx, &response.State, aws.ToString(description.ResourceModel))

if err != nil {
response.Diagnostics = append(response.Diagnostics, &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Creation Of Terraform State Unsuccessful",
Detail: fmt.Sprintf("Unable to set Terraform State Unknown values from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
})
response.Diagnostics.AddError(
"Creation Of Terraform State Unsuccessful",
fmt.Sprintf("Unable to set Terraform State Unknown values from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)

return
}
Expand Down Expand Up @@ -554,11 +552,10 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,
val, err := translator.FromString(ctx, schema, aws.ToString(description.ResourceModel))

if err != nil {
response.Diagnostics = append(response.Diagnostics, &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Creation Of Terraform State Unsuccessful",
Detail: fmt.Sprintf("Unable to create a Terraform State value from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
})
response.Diagnostics.AddError(
"Creation Of Terraform State Unsuccessful",
fmt.Sprintf("Unable to create a Terraform State value from a CloudFormation Resource Model. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)

return
}
Expand All @@ -574,11 +571,10 @@ func (r *resource) Read(ctx context.Context, request tfsdk.ReadResourceRequest,
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()),
})
response.Diagnostics.AddError(
"Terraform State Value Not Set",
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
}
Expand Down Expand Up @@ -639,11 +635,10 @@ func (r *resource) Update(ctx context.Context, request tfsdk.UpdateResourceReque
patchDocument, err := patchDocument(currentDesiredState, plannedDesiredState)

if err != nil {
response.Diagnostics = append(response.Diagnostics, &tfprotov6.Diagnostic{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Creation Of JSON Patch Unsuccessful",
Detail: fmt.Sprintf("Unable to create a JSON Patch for resource update. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
})
response.Diagnostics.AddError(
"Creation Of JSON Patch Unsuccessful",
fmt.Sprintf("Unable to create a JSON Patch for resource update. This is typically an error with the Terraform provider implementation. Original Error: %s", err.Error()),
)

return
}
Expand Down Expand Up @@ -741,7 +736,7 @@ func (r *resource) describe(ctx context.Context, conn *cloudformation.Client, id
func (r *resource) getId(ctx context.Context, state *tfsdk.State) (string, error) {
val, diags := state.GetAttribute(ctx, idAttributePath)

if tfresource.DiagsHasError(diags) {
if diags.HasError() {
return "", tfresource.DiagsError(diags)
}

Expand All @@ -756,7 +751,7 @@ func (r *resource) getId(ctx context.Context, state *tfsdk.State) (string, error
func (r *resource) setId(ctx context.Context, val string, state *tfsdk.State) error {
diags := state.SetAttribute(ctx, idAttributePath, val)

if tfresource.DiagsHasError(diags) {
if diags.HasError() {
return tfresource.DiagsError(diags)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/generic/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
func CopyValueAtPath(ctx context.Context, dst, src *tfsdk.State, path *tftypes.AttributePath) error {
val, diags := src.GetAttribute(ctx, path)

if tfresource.DiagsHasError(diags) {
if diags.HasError() {
return tfresource.DiagsError(diags)
}

diags = dst.SetAttribute(ctx, path, val)

if tfresource.DiagsHasError(diags) {
if diags.HasError() {
return tfresource.DiagsError(diags)
}

Expand Down
2 changes: 1 addition & 1 deletion internal/generic/unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (u unknowns) SetValuesFromRaw(ctx context.Context, state *tfsdk.State, reso
// Set it in the Terraform State.
diags := state.SetAttribute(ctx, path.InTerraformState, val)

if tfresource.DiagsHasError(diags) {
if diags.HasError() {
return fmt.Errorf("error setting value at %s: %w", path.InTerraformState, tfresource.DiagsError(diags))
}
}
Expand Down
Loading