Example #1
0
func resources(name string) {
	cf := cloudformation.NewFromEnv()
	ec2Client := ec2.NewFromEnv()
	elbClient := elb.NewFromEnv()

	resources, err := cf.DescribeStackResources(
		cloudformation.DescribeStackResourcesParameters{
			StackName: name,
		},
	)
	if err != nil {
		fatal(err)
	}

	stub := make(map[string]map[string]interface{})

	for _, resource := range resources.DescribeStackResourcesResult.StackResources {
		typeSegments := strings.Split(resource.ResourceType, "::")
		typeBase := typeSegments[len(typeSegments)-1]

		byType, found := stub[typeBase]
		if !found {
			byType = make(map[string]interface{})
			stub[typeBase] = byType
		}

		cleanName := strings.Replace(resource.LogicalResourceId, typeBase, "", 1)
		if cleanName == "" {
			cleanName = resource.LogicalResourceId
		}

		byType[cleanName] = resource.PhysicalResourceId
	}

	err = grabSecurityGroupNames(stub, ec2Client)
	if err != nil {
		fatal(err)
	}

	err = grabSubnetInfo(stub, ec2Client)
	if err != nil {
		fatal(err)
	}

	err = grabLoadBalancerDNSNames(stub, elbClient)
	if err != nil {
		fatal(err)
	}

	err = candiedyaml.NewEncoder(os.Stdout).Encode(map[string]interface{}{
		"Region":          ec2Client.Client.Region,
		"AccessKeyID":     ec2Client.Client.Key,
		"SecretAccessKey": ec2Client.Client.Secret,
		"Resources":       stub,
	})
	if err != nil {
		fatal(err)
	}
}
Example #2
0
File: ec2.go Project: vito/gocloud
func client() *ec2.Client {
	return ec2.NewFromEnv()
}