File tree 1 file changed +39
-0
lines changed
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ package common
2
+
3
+ import (
4
+ "context"
5
+
6
+ "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
7
+ )
8
+
9
+ type ctxResourceDataKey struct {}
10
+ type ctxProviderMetaKey struct {}
11
+
12
+ // NewResourceLifeCycleHandleFuncContext 创建一个资源生命周期处理方法上下文
13
+ func NewResourceLifeCycleHandleFuncContext (
14
+ parent context.Context ,
15
+ logID string ,
16
+ d * schema.ResourceData ,
17
+ meta interface {},
18
+ ) context.Context {
19
+ ctx := context .WithValue (parent , LogIdKey , logID )
20
+ ctx = context .WithValue (ctx , ctxResourceDataKey {}, d )
21
+ ctx = context .WithValue (ctx , ctxProviderMetaKey {}, meta )
22
+ return ctx
23
+ }
24
+
25
+ // ResourceDataFromContext 从上下文获取资源数据
26
+ func ResourceDataFromContext (ctx context.Context ) * schema.ResourceData {
27
+ if d , ok := ctx .Value (ctxResourceDataKey {}).(* schema.ResourceData ); ok {
28
+ return d
29
+ }
30
+ return nil
31
+ }
32
+
33
+ // ProviderMetaFromContext 从上下文获取 provider meta
34
+ func ProviderMetaFromContext (ctx context.Context ) interface {} {
35
+ if meta , ok := ctx .Value (ctxProviderMetaKey {}).(ProviderMeta ); ok {
36
+ return meta
37
+ }
38
+ return nil
39
+ }
You can’t perform that action at this time.
0 commit comments