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: Metros Data Source Development #842

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open

feat: Metros Data Source Development #842

wants to merge 14 commits into from

Conversation

d-bhola
Copy link
Contributor

@d-bhola d-bhola commented Jan 17, 2025

Addition of two data sources in Terraform Provider:

  1. Get Metro By Code /fabric/v4/metros/{metroCode}

    • Data Source Read Method - datasources_metro_code.go
  2. GET all Metros /fabric/v4/metros

    • Data Source Read Method - datasources_metros.go

Data Source Schema Addition

  • datasources_schema.go (same for both data sources)

Model Translation and Data Setting

  • models.go (same for both data sources)

Acceptance Tests

  • datasources_test.go

Documentation

  • fabric_metro.md
  • fabric_metros.md

@d-bhola d-bhola changed the title CXF 106630: Metros Data Source Development feat: Metros Data Source Development Jan 28, 2025
@d-bhola d-bhola marked this pull request as ready for review January 29, 2025 00:30
@d-bhola d-bhola requested review from a team as code owners January 29, 2025 00:30
@d-bhola
Copy link
Contributor Author

d-bhola commented Feb 3, 2025

@thogarty and @ctreatma - I did a rebase now. This PR is ready for review again.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 0.61350% with 324 lines in your changes missing coverage. Please review.

Project coverage is 49.23%. Comparing base (c71308e) to head (0972c17).
Report is 25 commits behind head on main.

Files with missing lines Patch % Lines
internal/resources/fabric/metro/models.go 0.00% 125 Missing ⚠️
...ernal/resources/fabric/metro/datasources_schema.go 0.00% 122 Missing ⚠️
...ernal/resources/fabric/metro/datasources_metros.go 0.00% 47 Missing ⚠️
...l/resources/fabric/metro/datasources_metro_code.go 0.00% 30 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##             main     #842       +/-   ##
===========================================
+ Coverage   36.13%   49.23%   +13.09%     
===========================================
  Files         184      191        +7     
  Lines       24491    25172      +681     
===========================================
+ Hits         8850    12393     +3543     
+ Misses      15480    12371     -3109     
- Partials      161      408      +247     

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

return fmt.Sprintf(`

data "equinix_fabric_metro" "metro" {
metro_code = "%[1]s"
Copy link
Contributor

Choose a reason for hiding this comment

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

info: the [1] is used when you want to repeat parameters in Sprintf. Otherwise you can omit because it will automatically pick them up in the order they are given after the formatted string.

No change necessary. Just an educational comment.

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.

Only parseMetro needs to be updated because there are multiple if blocks that aren't adding any value.

The rest of the comments should just be taken as education and you should avoid changing them to keep your PR review response as straight forward as possible.

Thanks for adding in the metros, @d-bhola !

*name = types.StringValue(metro.GetName())
}

if equinixAsn != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

These are not doing what you think they're doing. The models themselves are being checked before assignment. You should be checking the values that are being given from metro here. It's essentially an empty if check. You can remove any if boundary like this and just move their contents into the root of the method scope if the data source was working with this code.

connMetros := make([]ConnectedMetroModel, len(connectedMetros))
for i, metro := range connectedMetros {
connMetros[i] = ConnectedMetroModel{}
if metro.Href != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should resist checking the pointers and instead go for checking for empty strings. So if metro.GetHref() != "" {...

It might work here, so no need to change, but make certain you understand your changes and aren't just getting lucky with the side effects of the code you are writing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants