Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Remove vendored terraform RPC diagnostics code #350

Merged
merged 1 commit into from
Aug 1, 2022
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ terraform_gen:
-exec sed -i".bak" 's#github\.com/hashicorp/terraform/version#github.com/fugue/regula/v2/pkg/terraform/version#' '{}' \;
find pkg/terraform/ -name '*.bak' -delete
find pkg/terraform/ -name '*_test.go' -delete
git apply patches/terraform.patch
rm -rf terraform.zip terraform-$(TERRAFORM_VERSION)

#############
Expand Down
109 changes: 109 additions & 0 deletions patches/terraform.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
diff --git a/pkg/terraform/configs/configload/loader_snapshot.go b/pkg/terraform/configs/configload/loader_snapshot.go
index 243939f..6ca8b4f 100644
--- a/pkg/terraform/configs/configload/loader_snapshot.go
+++ b/pkg/terraform/configs/configload/loader_snapshot.go
@@ -325,6 +325,10 @@ func (fs snapshotFS) Chmod(name string, mode os.FileMode) error {
return fmt.Errorf("cannot set file mode inside configuration snapshot")
}

+func (fs snapshotFS) Chown(string, int, int) error {
+ return fmt.Errorf("cannot set file owner inside configuration snapshot")
+}
+
func (fs snapshotFS) Chtimes(name string, atime, mtime time.Time) error {
return fmt.Errorf("cannot set file times inside configuration snapshot")
}
diff --git a/pkg/terraform/tfdiags/diagnostics.go b/pkg/terraform/tfdiags/diagnostics.go
index 30476ee..25cd135 100644
--- a/pkg/terraform/tfdiags/diagnostics.go
+++ b/pkg/terraform/tfdiags/diagnostics.go
@@ -107,24 +107,6 @@ func (diags Diagnostics) HasErrors() bool {
return false
}

-// ForRPC returns a version of the receiver that has been simplified so that
-// it is friendly to RPC protocols.
-//
-// Currently this means that it can be serialized with encoding/gob and
-// subsequently re-inflated. It may later grow to include other serialization
-// formats.
-//
-// Note that this loses information about the original objects used to
-// construct the diagnostics, so e.g. the errwrap API will not work as
-// expected on an error-wrapped Diagnostics that came from ForRPC.
-func (diags Diagnostics) ForRPC() Diagnostics {
- ret := make(Diagnostics, len(diags))
- for i := range diags {
- ret[i] = makeRPCFriendlyDiag(diags[i])
- }
- return ret
-}
-
// Err flattens a diagnostics list into a single Go error, or to nil
// if the diagnostics list does not include any error-level diagnostics.
//
diff --git a/pkg/terraform/tfdiags/rpc_friendly.go b/pkg/terraform/tfdiags/rpc_friendly.go
deleted file mode 100644
index 485063b..0000000
--- a/pkg/terraform/tfdiags/rpc_friendly.go
+++ /dev/null
@@ -1,59 +0,0 @@
-package tfdiags
-
-import (
- "encoding/gob"
-)
-
-type rpcFriendlyDiag struct {
- Severity_ Severity
- Summary_ string
- Detail_ string
- Subject_ *SourceRange
- Context_ *SourceRange
-}
-
-// rpcFriendlyDiag transforms a given diagnostic so that is more friendly to
-// RPC.
-//
-// In particular, it currently returns an object that can be serialized and
-// later re-inflated using gob. This definition may grow to include other
-// serializations later.
-func makeRPCFriendlyDiag(diag Diagnostic) Diagnostic {
- desc := diag.Description()
- source := diag.Source()
- return &rpcFriendlyDiag{
- Severity_: diag.Severity(),
- Summary_: desc.Summary,
- Detail_: desc.Detail,
- Subject_: source.Subject,
- Context_: source.Context,
- }
-}
-
-func (d *rpcFriendlyDiag) Severity() Severity {
- return d.Severity_
-}
-
-func (d *rpcFriendlyDiag) Description() Description {
- return Description{
- Summary: d.Summary_,
- Detail: d.Detail_,
- }
-}
-
-func (d *rpcFriendlyDiag) Source() Source {
- return Source{
- Subject: d.Subject_,
- Context: d.Context_,
- }
-}
-
-func (d rpcFriendlyDiag) FromExpr() *FromExpr {
- // RPC-friendly diagnostics cannot preserve expression information because
- // expressions themselves are not RPC-friendly.
- return nil
-}
-
-func init() {
- gob.Register((*rpcFriendlyDiag)(nil))
-}
18 changes: 0 additions & 18 deletions pkg/terraform/tfdiags/diagnostics.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,24 +107,6 @@ func (diags Diagnostics) HasErrors() bool {
return false
}

// ForRPC returns a version of the receiver that has been simplified so that
// it is friendly to RPC protocols.
//
// Currently this means that it can be serialized with encoding/gob and
// subsequently re-inflated. It may later grow to include other serialization
// formats.
//
// Note that this loses information about the original objects used to
// construct the diagnostics, so e.g. the errwrap API will not work as
// expected on an error-wrapped Diagnostics that came from ForRPC.
func (diags Diagnostics) ForRPC() Diagnostics {
ret := make(Diagnostics, len(diags))
for i := range diags {
ret[i] = makeRPCFriendlyDiag(diags[i])
}
return ret
}

// Err flattens a diagnostics list into a single Go error, or to nil
// if the diagnostics list does not include any error-level diagnostics.
//
Expand Down
59 changes: 0 additions & 59 deletions pkg/terraform/tfdiags/rpc_friendly.go

This file was deleted.