-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stacks: add deferred actions to plugin protocol
Co-authored-by: Matej Risek <[email protected]>
- Loading branch information
1 parent
e650c03
commit 54e5a6e
Showing
9 changed files
with
278 additions
and
6 deletions.
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,34 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package convert | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/internal/providers" | ||
proto "github.com/hashicorp/terraform/internal/tfplugin5" | ||
) | ||
|
||
// ProtoToDeferred translates a proto.Deferred to a providers.Deferred. | ||
func ProtoToDeferred(d *proto.Deferred) *providers.Deferred { | ||
if d == nil { | ||
return nil | ||
} | ||
|
||
var reason int32 | ||
switch d.Reason { | ||
case proto.Deferred_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_UNKNOWN | ||
case proto.Deferred_RESOURCE_CONFIG_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_RESOURCE_CONFIG_UNKNOWN | ||
case proto.Deferred_PROVIDER_CONFIG_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_PROVIDER_CONFIG_UNKNOWN | ||
case proto.Deferred_ABSENT_PREREQ: | ||
reason = providers.DEFERRED_REASON_ABSENT_PREREQ | ||
default: | ||
reason = providers.DEFERRED_REASON_UNKNOWN | ||
} | ||
|
||
return &providers.Deferred{ | ||
Reason: reason, | ||
} | ||
} |
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,56 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package convert | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/internal/providers" | ||
proto "github.com/hashicorp/terraform/internal/tfplugin5" | ||
) | ||
|
||
func TestProtoDeferred(t *testing.T) { | ||
testCases := []struct { | ||
reason proto.Deferred_Reason | ||
expected int32 | ||
}{ | ||
{ | ||
reason: proto.Deferred_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_RESOURCE_CONFIG_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_RESOURCE_CONFIG_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_PROVIDER_CONFIG_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_PROVIDER_CONFIG_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_ABSENT_PREREQ, | ||
expected: providers.DEFERRED_REASON_ABSENT_PREREQ, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("deferred reason %q", tc.reason.String()), func(t *testing.T) { | ||
d := &proto.Deferred{ | ||
Reason: tc.reason, | ||
} | ||
|
||
deferred := ProtoToDeferred(d) | ||
if deferred.Reason != tc.expected { | ||
t.Fatalf("expected %d, got %d", tc.expected, deferred.Reason) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestProtoDeferred_Nil(t *testing.T) { | ||
deferred := ProtoToDeferred(nil) | ||
if deferred != nil { | ||
t.Fatalf("expected nil, got %v", deferred) | ||
} | ||
} |
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
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
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,34 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package convert | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/internal/providers" | ||
proto "github.com/hashicorp/terraform/internal/tfplugin6" | ||
) | ||
|
||
// ProtoToDeferred translates a proto.Deferred to a providers.Deferred. | ||
func ProtoToDeferred(d *proto.Deferred) *providers.Deferred { | ||
if d == nil { | ||
return nil | ||
} | ||
|
||
var reason int32 | ||
switch d.Reason { | ||
case proto.Deferred_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_UNKNOWN | ||
case proto.Deferred_RESOURCE_CONFIG_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_RESOURCE_CONFIG_UNKNOWN | ||
case proto.Deferred_PROVIDER_CONFIG_UNKNOWN: | ||
reason = providers.DEFERRED_REASON_PROVIDER_CONFIG_UNKNOWN | ||
case proto.Deferred_ABSENT_PREREQ: | ||
reason = providers.DEFERRED_REASON_ABSENT_PREREQ | ||
default: | ||
reason = providers.DEFERRED_REASON_UNKNOWN | ||
} | ||
|
||
return &providers.Deferred{ | ||
Reason: reason, | ||
} | ||
} |
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,56 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: BUSL-1.1 | ||
|
||
package convert | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/internal/providers" | ||
proto "github.com/hashicorp/terraform/internal/tfplugin6" | ||
) | ||
|
||
func TestProtoDeferred(t *testing.T) { | ||
testCases := []struct { | ||
reason proto.Deferred_Reason | ||
expected int32 | ||
}{ | ||
{ | ||
reason: proto.Deferred_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_RESOURCE_CONFIG_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_RESOURCE_CONFIG_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_PROVIDER_CONFIG_UNKNOWN, | ||
expected: providers.DEFERRED_REASON_PROVIDER_CONFIG_UNKNOWN, | ||
}, | ||
{ | ||
reason: proto.Deferred_ABSENT_PREREQ, | ||
expected: providers.DEFERRED_REASON_ABSENT_PREREQ, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(fmt.Sprintf("deferred reason %q", tc.reason.String()), func(t *testing.T) { | ||
d := &proto.Deferred{ | ||
Reason: tc.reason, | ||
} | ||
|
||
deferred := ProtoToDeferred(d) | ||
if deferred.Reason != tc.expected { | ||
t.Fatalf("expected %d, got %d", tc.expected, deferred.Reason) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestProtoDeferred_Nil(t *testing.T) { | ||
deferred := ProtoToDeferred(nil) | ||
if deferred != nil { | ||
t.Fatalf("expected nil, got %v", deferred) | ||
} | ||
} |
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
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
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