-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
manu-equinix
commented
Dec 8, 2023
- This PR adds a new provider to manage an equinix network resource
- Usage is documented on the examples folder
- provider name: equinix_fabric_network
EVPLAN, EPLAN, IPWAN
equinix/fabric_mapping_helper.go
Outdated
@@ -438,6 +437,25 @@ func operationToTerra(operation *v4.ConnectionOperation) *schema.Set { | |||
return operationSet | |||
} | |||
|
|||
func networkOperationToTerra(operation *v4.NetworkOperation) *schema.Set { |
There was a problem hiding this comment.
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(...)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
There was a problem hiding this 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.
equinix/fabric_mapping_helper.go
Outdated
@@ -438,6 +437,25 @@ func operationToTerra(operation *v4.ConnectionOperation) *schema.Set { | |||
return operationSet | |||
} | |||
|
|||
func networkOperationToTerra(operation *v4.NetworkOperation) *schema.Set { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Schema updates required.
equinix/fabric_network_schema.go
Outdated
Required: true, | ||
Description: "Fabric Network scope", | ||
}, | ||
"equinix_asn": { |
There was a problem hiding this comment.
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.
equinix/fabric_network_schema.go
Outdated
ValidateFunc: validation.StringInSlice([]string{"IPWAN", "EPLAN", "EVPLAN"}, true), | ||
Description: "Supported Network types - EVPLAN, EPLAN, IPWAN", | ||
}, | ||
"location": { |
There was a problem hiding this comment.
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
equinix/fabric_network_schema.go
Outdated
Schema: createLocationSch(), | ||
}, | ||
}, | ||
"project": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computed+Optional
equinix/fabric_network_schema.go
Outdated
Schema: createNetworkProjectSch(), | ||
}, | ||
}, | ||
"operation": { |
There was a problem hiding this comment.
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
equinix/fabric_network_schema.go
Outdated
Schema: createNetworkOperationSch(), | ||
}, | ||
}, | ||
"change": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computed only
equinix/fabric_network_schema.go
Outdated
} | ||
} | ||
|
||
func createNetworkResourceSchema() map[string]*schema.Schema { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
@manu-equinix @srushti-patl @thogarty Has this already been merged as #553? Anything remaining to incorporate from this PR? |
@displague yes, this was already merged in the other PR. I'll close this one. |
Closing because it's a redundant effort that was already cleaned up. |