-
Notifications
You must be signed in to change notification settings - Fork 85
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
[WIP] Add support for Edge transport nodes which were created externally #1473
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,6 +97,13 @@ func resourceNsxtEdgeTransportNode() *schema.Resource { | |
"description": getDescriptionSchema(), | ||
"display_name": getDisplayNameSchema(), | ||
"tag": getTagsSchema(), | ||
"node_id": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Description: "Unique Id of the fabric node", | ||
ConflictsWith: []string{"ip_addresses", "fqdn", "deployment_config", "external_id"}, | ||
}, | ||
"failure_domain": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
|
@@ -671,43 +678,56 @@ func getTransportNodeFromSchema(d *schema.ResourceData, m interface{}) (*mpmodel | |
description := d.Get("description").(string) | ||
displayName := d.Get("display_name").(string) | ||
tags := getMPTagsFromSchema(d) | ||
nodeID := d.Get("node_id").(string) | ||
failureDomain := d.Get("failure_domain").(string) | ||
hostSwitchSpec, err := getHostSwitchSpecFromSchema(d, m, nodeTypeEdge) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create Transport Node: %v", err) | ||
} | ||
|
||
converter := bindings.NewTypeConverter() | ||
var dataValue data.DataValue | ||
var errs []error | ||
var nodeDeploymentInfo *data.StructValue | ||
if nodeID == "" { | ||
/* | ||
node_id attribute conflicts with node_deployment_info. As node_deployment_info is a complex object which has | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please clarify - even when specifying There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The resource has no |
||
attributes with default values, this schema property will always have values - therefore there is no simple way | ||
to enforce this conflict within the provider (e.g check if node_id and node_deployment_info have values, then | ||
fail. | ||
So the provider will ignore node_deployment_info properties when node_id has a value - which would mean that | ||
this edge appliance was created externally. | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be helpful to also add a log statement here for debugging purposes. e.g: "nodeID not specified, will deploy edge using values in deploymentConfig" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
log.Printf("node_id not specified, will deploy edge using values in deploymentConfig") | ||
converter := bindings.NewTypeConverter() | ||
var dataValue data.DataValue | ||
var errs []error | ||
|
||
externalID := d.Get("external_id").(string) | ||
fqdn := d.Get("fqdn").(string) | ||
ipAddresses := interfaceListToStringList(d.Get("ip_addresses").([]interface{})) | ||
externalID := d.Get("external_id").(string) | ||
fqdn := d.Get("fqdn").(string) | ||
ipAddresses := interfaceListToStringList(d.Get("ip_addresses").([]interface{})) | ||
|
||
deploymentConfig, err := getEdgeNodeDeploymentConfigFromSchema(d.Get("deployment_config")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nodeSettings, err := getEdgeNodeSettingsFromSchema(d.Get("node_settings")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
node := mpmodel.EdgeNode{ | ||
ExternalId: &externalID, | ||
Fqdn: &fqdn, | ||
IpAddresses: ipAddresses, | ||
DeploymentConfig: deploymentConfig, | ||
NodeSettings: nodeSettings, | ||
ResourceType: mpmodel.EdgeNode__TYPE_IDENTIFIER, | ||
} | ||
dataValue, errs = converter.ConvertToVapi(node, mpmodel.EdgeNodeBindingType()) | ||
deploymentConfig, err := getEdgeNodeDeploymentConfigFromSchema(d.Get("deployment_config")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
nodeSettings, err := getEdgeNodeSettingsFromSchema(d.Get("node_settings")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
node := mpmodel.EdgeNode{ | ||
ExternalId: &externalID, | ||
Fqdn: &fqdn, | ||
IpAddresses: ipAddresses, | ||
DeploymentConfig: deploymentConfig, | ||
NodeSettings: nodeSettings, | ||
ResourceType: mpmodel.EdgeNode__TYPE_IDENTIFIER, | ||
} | ||
dataValue, errs = converter.ConvertToVapi(node, mpmodel.EdgeNodeBindingType()) | ||
|
||
if errs != nil { | ||
log.Printf("Failed to convert node object, errors are %v", errs) | ||
return nil, errs[0] | ||
if errs != nil { | ||
log.Printf("Failed to convert node object, errors are %v", errs) | ||
return nil, errs[0] | ||
} | ||
nodeDeploymentInfo = dataValue.(*data.StructValue) | ||
} | ||
nodeDeploymentInfo := dataValue.(*data.StructValue) | ||
|
||
obj := mpmodel.TransportNode{ | ||
Description: &description, | ||
|
@@ -725,6 +745,29 @@ func resourceNsxtEdgeTransportNodeCreate(d *schema.ResourceData, m interface{}) | |
connector := getPolicyConnector(m) | ||
client := nsx.NewTransportNodesClient(connector) | ||
|
||
nodeID := d.Get("node_id").(string) | ||
if nodeID != "" { | ||
obj, err := client.Get(nodeID) | ||
if err != nil { | ||
return handleCreateError("TransportNode", nodeID, err) | ||
} | ||
// Set node_id, revision and computed values in schema | ||
d.Set("failure_domain", obj.FailureDomainId) | ||
|
||
converter := bindings.NewTypeConverter() | ||
base, errs := converter.ConvertToGolang(obj.NodeDeploymentInfo, mpmodel.EdgeNodeBindingType()) | ||
if errs != nil { | ||
return handleReadError(d, "TransportNode", nodeID, errs[0]) | ||
} | ||
node := base.(mpmodel.EdgeNode) | ||
d.Set("external_id", node.ExternalId) | ||
d.Set("fqdn", node.Fqdn) | ||
d.Set("ip_addresses", node.IpAddresses) | ||
|
||
d.SetId(nodeID) | ||
return resourceNsxtEdgeTransportNodeUpdate(d, m) | ||
} | ||
|
||
obj, err := getTransportNodeFromSchema(d, m) | ||
if err != nil { | ||
return err | ||
|
@@ -1236,6 +1279,7 @@ func resourceNsxtEdgeTransportNodeRead(d *schema.ResourceData, m interface{}) er | |
d.Set("description", obj.Description) | ||
d.Set("display_name", obj.DisplayName) | ||
setMPTagsInSchema(d, obj.Tags) | ||
d.Set("node_id", obj.NodeId) | ||
d.Set("failure_domain", obj.FailureDomainId) | ||
|
||
if obj.HostSwitchSpec != nil { | ||
|
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 is probably a bad idea, but I'll suggest it anyway.
As this resource is not generated, we do not have to fully respect the NSX API schema.
Perhaps we can move node_id in deployment_config and specify that it conflictsWith vm_deployment_config?
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.
deployment_config
block contains stuff which is related to the Edge VM deployment: also attributes which are outside thevm_deployment_config
block is related, e.gform_factor
. Alsonode_user_settings
is related.And as these are required for a non-pre-deployed, we'll have to change those to optional for pre-deployed edges.
In fact I think that it's a good idea to mark
deployment_config
andnode_id
as conflicting.