Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
feat: Added Target Health Descriptions to Target Groups (#996)
Browse files Browse the repository at this point in the history
* feat: Added Target Health Descriptions to Target Groups

* remove migration files
  • Loading branch information
mlozoya2 authored Jun 6, 2022
1 parent bfba215 commit d1ffc37
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 0 deletions.
20 changes: 20 additions & 0 deletions client/mocks/mock_elbv2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ type ElbV2Client interface {
DescribeLoadBalancers(ctx context.Context, params *elbv2.DescribeLoadBalancersInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeLoadBalancersOutput, error)
DescribeLoadBalancerAttributes(ctx context.Context, params *elbv2.DescribeLoadBalancerAttributesInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeLoadBalancerAttributesOutput, error)
DescribeTargetGroups(ctx context.Context, params *elbv2.DescribeTargetGroupsInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeTargetGroupsOutput, error)
DescribeTargetHealth(ctx context.Context, params *elbv2.DescribeTargetHealthInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeTargetHealthOutput, error)
DescribeTags(ctx context.Context, params *elbv2.DescribeTagsInput, optFns ...func(*elbv2.Options)) (*elbv2.DescribeTagsOutput, error)
}

Expand Down
14 changes: 14 additions & 0 deletions docs/tables/aws_elbv2_target_group_target_health_descriptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Table: aws_elbv2_target_group_target_health_descriptions
Information about the health of a target.
## Columns
| Name | Type | Description |
| ------------- | ------------- | ----- |
|target_group_cq_id|uuid|Unique CloudQuery ID of aws_elbv2_target_groups table (FK)|
|health_check_port|text|The port to use to connect with the target.|
|target_id|text|The ID of the target.|
|target_availability_zone|text|An Availability Zone or all.|
|target_port|integer|The port on which the target is listening.|
|target_health_description|text|A description of the target health that provides additional details.|
|target_health_reason|text|The reason code. If the target state is healthy, a reason code is not provided.|
|target_health_state|text|The state of the target.|
70 changes: 70 additions & 0 deletions resources/services/elbv2/target_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,63 @@ func Elbv2TargetGroups() *schema.Table {
Type: schema.TypeString,
},
},
Relations: []*schema.Table{
{
Name: "aws_elbv2_target_group_target_health_descriptions",
Description: "Information about the health of a target.",
Resolver: resolveElbv2TargetGroupTargetHealthDescriptions,
IgnoreInTests: true,
Columns: []schema.Column{
{
Name: "target_group_cq_id",
Description: "Unique CloudQuery ID of aws_elbv2_target_groups table (FK)",
Type: schema.TypeUUID,
Resolver: schema.ParentIdResolver,
},
{
Name: "health_check_port",
Description: "The port to use to connect with the target.",
Type: schema.TypeString,
},
{
Name: "target_id",
Description: "The ID of the target.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Target.Id"),
},
{
Name: "target_availability_zone",
Description: "An Availability Zone or all.",
Type: schema.TypeString,
Resolver: schema.PathResolver("Target.AvailabilityZone"),
},
{
Name: "target_port",
Description: "The port on which the target is listening.",
Type: schema.TypeInt,
Resolver: schema.PathResolver("Target.Port"),
},
{
Name: "target_health_description",
Description: "A description of the target health that provides additional details.",
Type: schema.TypeString,
Resolver: schema.PathResolver("TargetHealth.Description"),
},
{
Name: "target_health_reason",
Description: "The reason code. If the target state is healthy, a reason code is not provided.",
Type: schema.TypeString,
Resolver: schema.PathResolver("TargetHealth.Reason"),
},
{
Name: "target_health_state",
Description: "The state of the target.",
Type: schema.TypeString,
Resolver: schema.PathResolver("TargetHealth.State"),
},
},
},
},
}
}

Expand Down Expand Up @@ -182,3 +239,16 @@ func resolveElbv2targetGroupTags(ctx context.Context, meta schema.ClientMeta, re
}
return diag.WrapError(resource.Set(c.Name, tags))
}

func resolveElbv2TargetGroupTargetHealthDescriptions(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
svc := meta.(*client.Client).Services().ELBv2
tg := parent.Item.(types.TargetGroup)
response, err := svc.DescribeTargetHealth(ctx, &elbv2.DescribeTargetHealthInput{
TargetGroupArn: tg.TargetGroupArn,
})
if err != nil {
return diag.WrapError(err)
}
res <- response.TargetHealthDescriptions
return nil
}
7 changes: 7 additions & 0 deletions resources/services/elbv2/target_groups_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ func buildElbv2TargetGroups(t *testing.T, ctrl *gomock.Controller) client.Servic
t.Fatal(err)
}
m.EXPECT().DescribeTags(gomock.Any(), gomock.Any(), gomock.Any()).Return(&tags, nil)

th := elasticloadbalancingv2.DescribeTargetHealthOutput{}
err = faker.FakeData(&th)
if err != nil {
t.Fatal(err)
}
m.EXPECT().DescribeTargetHealth(gomock.Any(), gomock.Any(), gomock.Any()).Return(&th, nil)
return client.Services{
ELBv2: m,
}
Expand Down

0 comments on commit d1ffc37

Please sign in to comment.