func()

in providers/tencentcloud/clb.go [87:158]


func (g *ClbGenerator) loadListener(client *clb.Client, loadBalancerID, resourceName string) error {
	request := clb.NewDescribeTargetsRequest()
	request.LoadBalancerId = &loadBalancerID
	response, err := client.DescribeTargets(request)
	if err != nil {
		return err
	}

	for _, listener := range response.Response.Listeners {
		resource := terraformutils.NewResource(
			loadBalancerID+"#"+*listener.ListenerId,
			*listener.ListenerId,
			"tencentcloud_clb_listener",
			"tencentcloud",
			map[string]string{
				"scheduler": "WRR",
			},
			[]string{},
			map[string]interface{}{},
		)
		resource.AdditionalFields["clb_id"] = "${tencentcloud_clb_instance." + resourceName + ".id}"
		g.Resources = append(g.Resources, resource)
		if len(listener.Targets) > 0 {
			attachmentResource := terraformutils.NewResource(
				"#"+*listener.ListenerId+"#"+loadBalancerID,
				*listener.ListenerId,
				"tencentcloud_clb_attachment",
				"tencentcloud",
				map[string]string{},
				[]string{},
				map[string]interface{}{},
			)
			attachmentResource.AdditionalFields["clb_id"] = "${tencentcloud_clb_instance." + resourceName + ".id}"
			attachmentResource.AdditionalFields["listener_id"] = "${tencentcloud_clb_listener." + resource.ResourceName + ".listener_id}"
			g.Resources = append(g.Resources, attachmentResource)
		}

		for _, rule := range listener.Rules {
			ruleResource := terraformutils.NewResource(
				loadBalancerID+"#"+*listener.ListenerId+"#"+*rule.LocationId,
				*rule.LocationId,
				"tencentcloud_clb_listener_rule",
				"tencentcloud",
				map[string]string{},
				[]string{},
				map[string]interface{}{},
			)
			ruleResource.AdditionalFields["clb_id"] = "${tencentcloud_clb_instance." + resourceName + ".id}"
			ruleResource.AdditionalFields["listener_id"] = "${tencentcloud_clb_listener." + resource.ResourceName + ".listener_id}"
			g.Resources = append(g.Resources, ruleResource)

			if len(rule.Targets) > 0 {
				attachmentResource := terraformutils.NewResource(
					*rule.LocationId+"#"+*listener.ListenerId+"#"+loadBalancerID,
					*rule.LocationId,
					"tencentcloud_clb_attachment",
					"tencentcloud",
					map[string]string{},
					[]string{},
					map[string]interface{}{},
				)
				attachmentResource.AdditionalFields["clb_id"] = "${tencentcloud_clb_instance." + resourceName + ".id}"
				attachmentResource.AdditionalFields["listener_id"] = "${tencentcloud_clb_listener." + resource.ResourceName + ".listener_id}"
				attachmentResource.AdditionalFields["rule_id"] = "${tencentcloud_clb_listener_rule." + ruleResource.ResourceName + ".rule_id}"
				g.Resources = append(g.Resources, attachmentResource)
			}
		}

	}

	return nil
}