-
Notifications
You must be signed in to change notification settings - Fork 35
Fetch machine details #45
base: master
Are you sure you want to change the base?
Conversation
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.
It would be really useful to have an example blueprint in this review. It would also be good to add comments in the code about the structure of the template retrieved from the catalog item. This would make it much easier to read the review and to check for assumptions.
I grabbed actions.go and resource.go from Viraj's pull request and re-ran dep, re-compiled, re-installed, re-ran Thanks. Update: I added the examples for completeness. No change. Update 2: I pulled the entire branch and built that. No change. It doesn't work at all, even when providing the empty ip_address var I later found in an example file. |
Any help here?? How do I get this working? Thanks. |
Viraj is on a personal time off for this week. He should be able to get to this shortly. I have not had a chance to play with this pull request yet. I will start trying this change (as well as reviewing it) shortly. |
Thank you, @raghavav. |
Is there an update on this PR? Thanks. |
Working on it. |
vrealize/resource.go
Outdated
|
||
"encoding/json" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
//ResourceViewsTemplate - is used to store information | ||
//related to resource template information. | ||
type ResourceViewsTemplate struct { |
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.
Rename this type. It is not a 'template'.
It is just 'Resource' or 'ResourceView'.
i know the same change is happening in PR #27. I think it is worth pulling that rename change here.
vrealize/resource.go
Outdated
usedConfigKeys = append(usedConfigKeys, configKey) | ||
} else { | ||
log.Printf("%s was not replaced", configKey) | ||
if resourceConfiguration[configKey] != nil && resourceConfiguration[configKey] != "" { |
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.
Not worth the additional indent here.
Just use
if resourceConfiguration[configKey] == nil || resourceConfiguration[configKey] == "" {
break;
}
Better yet, create an 'isEmpty(string) boolean utility function. There you can also check for other types of empty strings. That function will likely need to be reused in other places too.
vrealize/resource.go
Outdated
@@ -394,6 +396,135 @@ func updateResource(d *schema.ResourceData, meta interface{}) error { | |||
return nil | |||
} | |||
|
|||
func fetchResourceFieldsValues(d *schema.ResourceData, meta interface{}) error { | |||
//Get requester machine ID from schema.dataresource | |||
requestMachineID := 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.
Rename field to 'catalogRequestId'.
vrealize/resource.go
Outdated
//Get client handle | ||
client := meta.(*APIClient) | ||
//Fetch resource details from vRA | ||
templateResources, errTemplate := client.GetResourceViews(requestMachineID) |
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.
not 'remplateResources'.
Call it 'resourceView'
vrealize/resource.go
Outdated
"{com.vmware.csp.component.iaas.proxy.provider@resource.action.name.machine.Reconfigure}" | ||
|
||
//Read vRA resource content one by one | ||
for item := range templateResources.Content { |
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.
for index, component := range templateResources.Content
vrealize/resource.go
Outdated
@@ -394,6 +396,135 @@ func updateResource(d *schema.ResourceData, meta interface{}) error { | |||
return nil | |||
} | |||
|
|||
func fetchResourceFieldsValues(d *schema.ResourceData, meta interface{}) error { | |||
//Get requester machine ID from schema.dataresource |
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.
PR #27 has an implementation of this same method. Can you please rationalize the two PRs? I am not sure which one you want to go forward with.
I will put in some review comments here, but I think the two look different and you have to decide which way you want to go. In my opinion it is best to go with the version in PR #27.
vrealize/resource.go
Outdated
//Iterate over TF resource > resource_configuration | ||
for configKey := range resourceConfiguration { | ||
//Check if any TF resource > resource_configuration is empty or null | ||
if resourceConfiguration[configKey] == nil || resourceConfiguration[configKey] == "" { |
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 clearly an opportunity here to use that 'isEmpty(string) boolean' utility function that I mentioned earlier in this review.
vrealize/resource.go
Outdated
//Check if any TF resource > resource_configuration is empty or null | ||
if resourceConfiguration[configKey] == nil || resourceConfiguration[configKey] == "" { | ||
//Compare vRA child resource and TF resource > resource_configuration names | ||
if strings.Contains(configKey, componentName+".") { |
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.
Should be using HasPrefix and TrimPrefix functions as mentioned in the reviews in PR #55
vrealize/resource.go
Outdated
if returnValue != nil { | ||
//If value returned from getTemplateValue is in float64 format then | ||
//convert it in string format | ||
if reflect.ValueOf(returnValue).Kind() == reflect.Float64 { |
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.
As mentioned in the review in PR #27, please fold all this type conversions directly into the getTemplateValue function. That function can return a string instead of returning an interface{}.
Also, I like the idea of that function telling you if a value has changed.
//If value type is map then set recursive call which will fiend field in one level down of map interface | ||
if reflect.ValueOf(templateInterface[i]).Kind() == reflect.Map { | ||
template, _ := templateInterface[i].(map[string]interface{}) | ||
returnValue := getTemplateValue(template, field) |
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.
As I said in the review for PR #27, I am not sure what the use-case is for this kind of a recursive retrieval from multiple levels of a map. I think it is not necessary or even a good idea.
Signed-off-by: Viraj Indasrao <[email protected]>
got vet Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Minor fixes Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
@virajindasrao, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding
|
Signed-off-by: Viraj Indasrao <[email protected]>
got vet Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Minor fixes Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
2e463f4
to
7bd4d8f
Compare
@virajindasrao, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding
|
…-details Signed-off-by: Viraj Indasrao <[email protected]>
6dc3544
to
a94dc77
Compare
Signed-off-by: Viraj Indasrao <[email protected]>
b1d0298
to
ca55172
Compare
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
Signed-off-by: Viraj Indasrao <[email protected]>
This now works for me using the master branch, passing the empty
Thanks. UPDATE: Spoke too soon. It worked once. See #17. 😦 |
Signed-off-by: Viraj Indasrao <[email protected]>
@@ -274,12 +275,17 @@ func createResource(d *schema.ResourceData, meta interface{}) error { | |||
//Update request template field values with values from user configuration. | |||
resourceConfiguration, _ := d.Get("resource_configuration").(map[string]interface{}) | |||
for configKey, configValue := range resourceConfiguration { | |||
if len(configValue.(string)) == 0 { | |||
break |
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 should be a continue
instead of break
.
This code will allow a user to update terraform configuration at deployment level after deployment succeed. To get field values of deployment, a user has to keep resource_configuration value equals to an empty string.
After request success, details will be fetched on
terraform refresh
.Signed-off-by: Viraj Indasrao [email protected]