-
Notifications
You must be signed in to change notification settings - Fork 9.3k
/
Copy pathconns.go
77 lines (62 loc) · 2.4 KB
/
conns.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package conns
import (
"context"
"github.com/hashicorp/terraform-provider-aws/internal/types"
)
// ServicePackage is the minimal interface exported from each AWS service package.
// Its methods return the Plugin SDK and Framework resources and data sources implemented in the package.
type ServicePackage interface {
FrameworkDataSources(context.Context) []*types.ServicePackageFrameworkDataSource
FrameworkResources(context.Context) []*types.ServicePackageFrameworkResource
SDKDataSources(context.Context) []*types.ServicePackageSDKDataSource
SDKResources(context.Context) []*types.ServicePackageSDKResource
ServicePackageName() string
}
// ServicePackageWithEphemeralResources is an interface that extends ServicePackage with ephemeral resources.
// Ephemeral resources are resources that are not part of the Terraform state, but are used to create other resources.
type ServicePackageWithEphemeralResources interface {
ServicePackage
EphemeralResources(context.Context) []*types.ServicePackageEphemeralResource
}
type (
contextKeyType int
)
var (
contextKey contextKeyType
)
// InContext represents the resource information kept in Context.
type InContext struct {
IsDataSource bool // Data source?
IsEphemeralResource bool // Ephemeral resource?
ResourceName string // Friendly resource name, e.g. "Subnet"
ServicePackageName string // Canonical name defined as a constant in names package
}
func NewDataSourceContext(ctx context.Context, servicePackageName, resourceName string) context.Context {
v := InContext{
IsDataSource: true,
ResourceName: resourceName,
ServicePackageName: servicePackageName,
}
return context.WithValue(ctx, contextKey, &v)
}
func NewEphemeralResourceContext(ctx context.Context, servicePackageName, resourceName string) context.Context {
v := InContext{
IsEphemeralResource: true,
ResourceName: resourceName,
ServicePackageName: servicePackageName,
}
return context.WithValue(ctx, contextKey, &v)
}
func NewResourceContext(ctx context.Context, servicePackageName, resourceName string) context.Context {
v := InContext{
ResourceName: resourceName,
ServicePackageName: servicePackageName,
}
return context.WithValue(ctx, contextKey, &v)
}
func FromContext(ctx context.Context) (*InContext, bool) {
v, ok := ctx.Value(contextKey).(*InContext)
return v, ok
}