Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding Route Aggregation Rule and Connection Route Aggregation Data Sources and Resources #860

Merged
merged 6 commits into from
Feb 28, 2025

Conversation

srushti-patl
Copy link
Contributor

  • fabric_route_aggregation_rule Data Sources and Resource added
  • fabric_route_aggregation_rules Data Sources and Resource added
  • Documentation and Acceptance Tests added for above resources and data sources

Copy link

codecov bot commented Feb 18, 2025

Codecov Report

Attention: Patch coverage is 68.30189% with 336 lines in your changes missing coverage. Please review.

Project coverage is 65.37%. Comparing base (a5bf346) to head (e81fc08).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
...rces/fabric/connectionrouteaggregation/resource.go 7.24% 128 Missing ⚠️
.../resources/fabric/routeaggregationrule/resource.go 61.22% 56 Missing and 20 partials ⚠️
...ources/fabric/connectionrouteaggregation/models.go 0.00% 51 Missing ⚠️
...tion/datasource_by_connectionRouteAggregationId.go 30.30% 23 Missing ⚠️
...tion/datasource_all_connectionRouteAggregations.go 31.25% 22 Missing ⚠️
...gationrule/datasource_all_routeAggregationRules.go 64.00% 13 Missing and 5 partials ⚠️
...gationrule/datasource_by_routeAggregationRuleId.go 66.66% 8 Missing and 3 partials ⚠️
...al/resources/fabric/routeaggregationrule/models.go 91.46% 5 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #860       +/-   ##
===========================================
+ Coverage   32.63%   65.37%   +32.74%     
===========================================
  Files         205      217       +12     
  Lines       26607    27667     +1060     
===========================================
+ Hits         8682    18087     +9405     
+ Misses      17778     8694     -9084     
- Partials      147      886      +739     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thogarty thogarty added the area/resources/fabric Issues related to Fabric and ECX APIs label Feb 20, 2025
@srushti-patl srushti-patl force-pushed the CXF-106516-Route-Aggregation-Rule-Connection branch from 507dcc4 to 5151372 Compare February 25, 2025 23:25
Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes requested

}

// Handle specific API error messages
var apiErr *fabricv4.GenericOpenAPIError
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error handling likely is redundant and not necessary. There also should be an easier way to get the errorCode back from the err.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See

_, err := client.CloudRoutersApi.DeleteCloudRouterByUuid(ctx, d.Id()).Execute()
if err != nil {
if genericError, ok := err.(*fabricv4.GenericOpenAPIError); ok {
if fabricErrs, ok := genericError.Model().([]fabricv4.Error); ok {
// EQ-3040055 = There is an existing update in REQUESTED state
if equinix_errors.HasErrorCode(fabricErrs, "EQ-3040055") {
return diags
}
}
}
return diag.FromErr(equinix_errors.FormatFabricError(err))
}
for an example of how to simplify this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should still double check for the necessity of this though. It doesn't seem like it should be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fetch the errorCode and I have updated the method based on the above example


newPrefix, oldPrefix := plan.Prefix.ValueString(), state.Prefix.ValueString()

if newPrefix == oldPrefix {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our lack of plan modification here is going to cause this warning to be triggered every time this happens. Prepare for an update if issues arise.

createWaiter := getCreateUpdateWaiter(ctx, client, routeAggregationID, routeAggregationRule.GetUuid(), createTimeout)
routeAggregationRuleChecked, err := createWaiter.WaitForStateContext(ctx)
if err != nil {
resp.Diagnostics.AddError(fmt.Sprintf("Failed creating Route Aggregation %s", routeAggregationRule.GetUuid()), err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: rule missing from error message

routeAggregationId := rs.Primary.Attributes["route_aggregation_id"]
connectionId := rs.Primary.Attributes["connection_id"]

if connectionRouteAggregation, _, err := client.RouteAggregationsApi.GetConnectionRouteAggregationByUuid(ctx, routeAggregationId, connectionId).Execute(); err == nil &&
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is better for a test check delete method.

// deletedMarker is a terraform-provider-only value that is used by the waiter
// to indicate that the resource appears to be deleted successfully based on
// status code or specific error code
deletedMarker := "tf-marker-for-deleted-route-aggregation-rule"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should be connection route aggregation string instead

Update: true,
Delete: true,
}),
"route_aggregation_id": schema.StringAttribute{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this changes it should force a new resource. Same with connection_id

Description: "UUID of the Route Aggregation to apply this Rule to",
Required: true,
},
"connection_id": schema.StringAttribute{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should force a new resource if updated

Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just need to update the delete checks and then it's good to go 👍

deletedMarker,
},
Refresh: func() (interface{}, string, error) {
routeAggregationRule, resp, err := client.RouteAggregationRulesApi.GetRouteAggregationRuleByUuid(ctx, routeAggregationID, id).Execute()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need resp here.

Refresh: func() (interface{}, string, error) {
routeAggregationRule, resp, err := client.RouteAggregationRulesApi.GetRouteAggregationRuleByUuid(ctx, routeAggregationID, id).Execute()
if err != nil {
if resp != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can remove resp check. Also, you should add the check for 404 status check back into this if statement and the one for resource_test.go. The simplification was about the conversion to GenericOpenAPIError and not about the status codes. Those were good and important checks.

Copy link
Contributor

@thogarty thogarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Ship it.

@srushti-patl srushti-patl merged commit 6a231ed into main Feb 28, 2025
11 of 14 checks passed
@srushti-patl srushti-patl deleted the CXF-106516-Route-Aggregation-Rule-Connection branch February 28, 2025 00:27
Copy link

This PR is included in version 3.3.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/resources/fabric Issues related to Fabric and ECX APIs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants