本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation.DescribeStackResources方法的典型用法代碼示例。如果您正苦於以下問題:Golang CloudFormation.DescribeStackResources方法的具體用法?Golang CloudFormation.DescribeStackResources怎麽用?Golang CloudFormation.DescribeStackResources使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/aws/aws-sdk-go/service/cloudformation.CloudFormation
的用法示例。
在下文中一共展示了CloudFormation.DescribeStackResources方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: describeRackStacks
// describeRackStacks uses credentials to describe CF service, app and rack stacks that belong to the rack name and region
func describeRackStacks(rackName, distinctId string, CF *cloudformation.CloudFormation) (Stacks, error) {
res, err := CF.DescribeStacks(&cloudformation.DescribeStacksInput{})
if err != nil {
return Stacks{}, err
}
apps := []Stack{}
rack := []Stack{}
services := []Stack{}
for _, stack := range res.Stacks {
events := map[string]string{}
outputs := map[string]string{}
tags := map[string]string{}
for _, output := range stack.Outputs {
outputs[*output.OutputKey] = *output.OutputValue
}
for _, tag := range stack.Tags {
tags[*tag.Key] = *tag.Value
}
name := tags["Name"]
if name == "" {
name = *stack.StackName
}
buckets := []string{}
rres, err := CF.DescribeStackResources(&cloudformation.DescribeStackResourcesInput{
StackName: stack.StackId,
})
if err != nil {
return Stacks{}, err
}
for _, resource := range rres.StackResources {
if *resource.ResourceType == "AWS::S3::Bucket" {
if resource.PhysicalResourceId != nil {
buckets = append(buckets, *resource.PhysicalResourceId)
}
}
}
eres, err := CF.DescribeStackEvents(&cloudformation.DescribeStackEventsInput{
StackName: stack.StackId,
})
if err != nil {
return Stacks{}, err
}
for _, event := range eres.StackEvents {
if strings.HasSuffix(*event.ResourceStatus, "FAILED") {
events[*event.LogicalResourceId] = *event.ResourceStatusReason
}
}
s := Stack{
Name: name,
StackName: *stack.StackName,
Status: *stack.StackStatus,
Type: tags["Type"],
Buckets: buckets,
Events: events,
Outputs: outputs,
}
// collect stacks that are explicitly related to the rack
if tags["Rack"] == rackName {
switch tags["Type"] {
case "app":
apps = append(apps, s)
case "service":
services = append(services, s)
}
}
// collect stack that is explicitly the rack
if *stack.StackName == rackName && outputs["Dashboard"] != "" {
rack = append(rack, s)
}
}
return Stacks{
Apps: apps,
Rack: rack,
Services: services,
}, nil
}