本文整理汇总了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
}