Beispiel #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)
	}
}
Beispiel #2
0
func elbListLoadBalancers() error {
	elbClient := elb.NewFromEnv()
	log.Print("describing load balancers")
	lbs, e := elbClient.DescribeLoadBalancers()
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	table.Add("Name", "DnsName", "Instances")
	for _, lb := range lbs {
		table.Add(
			lb.LoadBalancerName,
			lb.DNSName,
			strings.Join(lb.Instances, ", "),
		)
	}
	fmt.Print(table)
	return nil
}
Beispiel #3
0
func (a *elbDescribeLoadBalancer) Run() error {
	elbClient := elb.NewFromEnv()
	states, e := elbClient.DescribeInstanceHealth(a.Name)
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, state := range states {
		stateString := ""
		if state.State == "InService" {
			stateString = gocli.Green(state.State)
		} else {
			stateString = gocli.Red(state.State)
		}
		table.Add(state.InstanceId, stateString)
	}
	fmt.Println(table)
	return nil
}
Beispiel #4
0
func (a *elbDeregisterInstances) Run() error {
	return elb.NewFromEnv().DeregisterInstancesWithLoadBalancer(a.LbId, a.InstanceIds)
}