-
Notifications
You must be signed in to change notification settings - Fork 113
/
common.go
59 lines (51 loc) · 1.61 KB
/
common.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
/*
Copyright 2021 Upbound Inc.
*/
package common
import (
"github.com/crossplane/crossplane-runtime/pkg/fieldpath"
"github.com/crossplane/crossplane-runtime/pkg/reference"
xpresource "github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/upbound/upjet/pkg/resource"
)
const (
// SelfPackagePath is the golang path for this package.
SelfPackagePath = "github.com/upbound/provider-aws/config/common"
// PathARNExtractor is the golang path to ARNExtractor function
// in this package.
PathARNExtractor = SelfPackagePath + ".ARNExtractor()"
// PathTerraformIDExtractor is the golang path to TerraformID extractor
// function in this package.
PathTerraformIDExtractor = SelfPackagePath + ".TerraformID()"
// VersionV1Beta1 is used for resources that meet the v1beta1 criteria
// here: https://github.com/upbound/arch/pull/33
VersionV1Beta1 = "v1beta1"
)
// ARNExtractor extracts ARN of the resources from "status.atProvider.arn" which
// is quite common among all AWS resources.
func ARNExtractor() reference.ExtractValueFn {
return func(mg xpresource.Managed) string {
paved, err := fieldpath.PaveObject(mg)
if err != nil {
// todo(hasan): should we log this error?
return ""
}
r, err := paved.GetString("status.atProvider.arn")
if err != nil {
// todo(hasan): should we log this error?
return ""
}
return r
}
}
// TerraformID returns the Terraform ID string of the resource without any
// manipulation.
func TerraformID() reference.ExtractValueFn {
return func(mr xpresource.Managed) string {
tr, ok := mr.(resource.Terraformed)
if !ok {
return ""
}
return tr.GetID()
}
}