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: Add equinix_fabric_network terraform provider #482

Closed

Conversation

manu-equinix
Copy link
Contributor

  • This PR adds a new provider to manage an equinix network resource
  • Usage is documented on the examples folder
  • provider name: equinix_fabric_network

@manu-equinix manu-equinix requested a review from thogarty December 8, 2023 20:58
@manu-equinix manu-equinix changed the title Add equinix_fabric_network terraform provider feat: Add equinix_fabric_network terraform provider Dec 8, 2023
@@ -438,6 +437,25 @@ func operationToTerra(operation *v4.ConnectionOperation) *schema.Set {
return operationSet
}

func networkOperationToTerra(operation *v4.NetworkOperation) *schema.Set {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a large refactor in progress to enable us to gradually migrate the provider from the deprecated terraform-plugin-sdk to its replacement, terraform-plugin-framework. One thing we've found during that refactor is that shared, private functions like this make it more difficult to refactor resources & data sources from the SDK to the framework.

Instead of adding new helpers to this file, I recommend creating a new package & code file under the internal directory. For example, you could define this function as NetworkOperationToTerra in the file internal/mapping/fabric.go, specifying package mapping at the top of that file; then in files that use this helper you would need to import github.com/equinix/terraform-provider-equinix/internal/mapping, and you would call the function as mapping.NetworkOperationToTerra(...).

Copy link
Contributor

Choose a reason for hiding this comment

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

+1

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.

I haven't been able to get to the schema yet, but I've requested some changes as well as agreeing with Charles' comment.

@@ -438,6 +437,25 @@ func operationToTerra(operation *v4.ConnectionOperation) *schema.Set {
return operationSet
}

func networkOperationToTerra(operation *v4.NetworkOperation) *schema.Set {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -0,0 +1,34 @@
# ECX Fabric network CRUD operations
Copy link
Contributor

Choose a reason for hiding this comment

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

We're no longer adding to the examples in the Provider repo. Add example usage with values from tfvars.example directly on the resource to the documentation.

Additionally, docs/ need to be added for the resource and data source with including example usage. You can use this doc as a reference for example usage: https://github.com/equinix/terraform-provider-equinix/blob/main/docs/resources/equinix_ecx_l2_connection.md

The addition to examples directory is not needed.


fabricNetwork, _, err := client.NetworksApi.CreateNetwork(ctx, createRequest)
if err != nil {
return diag.FromErr(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

All error responses from Fabric Go SDK need to be updated to follow our error output pattern. Use this for reference: #449

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, got it. I see that the main branch was updated with this code just a couple of hours ago after my PR was out. Let me check if I can rebase on latest changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

All good! There's no way you could have known. Just wanted to make sure that now we have it we keep up with it. :)

return diag.FromErr(err)
}
updates := []v4.NetworkChangeOperation{update}
_, res, err := client.NetworksApi.UpdateNetworkByUuid(ctx, updates, d.Id())
Copy link
Contributor

Choose a reason for hiding this comment

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

res from Fabric_Go SDK should be left out of errors. It will only show the headers of the request and doesn't provide value to the end user. Just clutters the error output. Please follow the pattern set for error output on Fabric Resources defined here: #449

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.

Schema updates required.

Required: true,
Description: "Fabric Network scope",
},
"equinix_asn": {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this value equinix_asn in the schema for Network: https://app.swaggerhub.com/apis/equinix-api/fabric/4.11#/Networks/createNetwork

It should be removed if it's not there.

ValidateFunc: validation.StringInSlice([]string{"IPWAN", "EPLAN", "EVPLAN"}, true),
Description: "Supported Network types - EVPLAN, EPLAN, IPWAN",
},
"location": {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the value can be input into the schema or returned from the API response, then it needs to have Optional and Computed set to true.

Reference for what behaviors to include is explained in detail here: https://equinixjira.atlassian.net/wiki/spaces/IC/pages/145918564397/Terraform+Schema+Standards

Schema: createLocationSch(),
},
},
"project": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Computed+Optional

Schema: createNetworkProjectSch(),
},
},
"operation": {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no operation in the PostRequest body. This should just be Computed

Schema: createNetworkOperationSch(),
},
},
"change": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Computed only

}
}

func createNetworkResourceSchema() map[string]*schema.Schema {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please review the schema. Some values from the response are left out.

}
}

func readNetworkResourceSchema() map[string]*schema.Schema {
Copy link
Contributor

Choose a reason for hiding this comment

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

This schema is more correct for what the create should have been. Though the behaviors on create will be different. Double check that it matches and I'll review again.

@displague
Copy link
Member

displague commented Feb 22, 2024

@manu-equinix @srushti-patl @thogarty Has this already been merged as #553? Anything remaining to incorporate from this PR?

@thogarty
Copy link
Contributor

@displague yes, this was already merged in the other PR. I'll close this one.

@thogarty
Copy link
Contributor

Closing because it's a redundant effort that was already cleaned up.

@thogarty thogarty closed this Feb 22, 2024
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.

6 participants