forked from awslabs/goformation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fnimportvalue.go
46 lines (38 loc) · 1.26 KB
/
fnimportvalue.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
package intrinsics
import (
"context"
"fmt"
acfn "github.com/aws/aws-sdk-go-v2/service/cloudformation"
"github.com/drmmarsunited/goformation/v7/cloudformation/utils"
)
// FnImportValue is now implemented and will return a value if found, and returns "dummyvalue if not found.
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html
func FnImportValue(name string, input interface{}, template interface{}) interface{} {
// { "Fn::ImportValue" : sharedValueToImport }
// Set up the AWS helper
awsHelper, err := utils.NewAwsHelper()
if err != nil {
return "dummyvalue"
}
// Set up CloudFormation client
cfnClient := acfn.NewFromConfig(awsHelper.Cfg)
// List CloudFormation exports for region
paginator := acfn.NewListExportsPaginator(cfnClient, nil)
for paginator.HasMorePages() {
output, err := paginator.NextPage(context.TODO())
if err != nil {
fmt.Printf("Could not get list of paged CFN exports: %s\n", err.Error())
return "dummyvalue"
}
// Parse through exports for matching name
if name, ok := input.(string); ok {
for _, e := range output.Exports {
if *e.Name == name {
return *e.Value
}
}
}
}
// Return dummy value if no matches were found
return "dummyvalue"
}