Skip to content
This repository has been archived by the owner on Nov 20, 2020. It is now read-only.

get out machine name #20

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ website/node_modules
*.test
*.iml
*.diff
.vscode/
tmp
terraform-provider-vra7*
test.sh
Expand Down
48 changes: 47 additions & 1 deletion vrealize/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import (
//related to resource template information.
type ResourceViewsTemplate struct {
Content []struct {
ResourceType string `json:"resourceType"`
ResourceID string `json:"resourceId"`
RequestState string `json:"requestState"`
Links []struct {
Name string `json:"name"`
Data struct {
IPAddress string `json:"ip_address"`
} `json:"data"`
Links []struct {
Href string `json:"href"`
Rel string `json:"rel"`
} `json:"links"`
Expand Down Expand Up @@ -68,6 +73,7 @@ type RequestMachineResponse struct {
RequestedItemDescription string `json:"requestedItemDescription"`
Components string `json:"components"`
StateName string `json:"stateName"`
Name string `json:"name"`

CatalogItemProviderBinding struct {
BindingID string `json:"bindingId"`
Expand Down Expand Up @@ -111,6 +117,21 @@ func setResourceSchema() map[string]*schema.Schema {
Computed: true,
Optional: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"ip_address": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"resource_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
},
"request_status": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -300,6 +321,31 @@ func readResource(d *schema.ResourceData, meta interface{}) error {
if resourceTemplate.Phase == "FAILED" {
d.Set("failed_message", resourceTemplate.RequestCompletion.CompletionDetails)
}
//If request is successful then set the machine name
if resourceTemplate.Phase == "SUCCESSFUL" {
//Get resource view
resourceView, errTemplate := client.GetResourceViews(requestMachineID)
//Raise an exception if error occured while fetching resourceview
if errTemplate != nil {
return fmt.Errorf("Resource view failed to load: %v", errTemplate)
}

// Iterate through the resourceView map
d.Set("resource_type", "")
d.Set("name", "")
for _, i := range resourceView.Content {
d.Set("resource_type", i.ResourceType)
// set the name only if its a virtual machine
if i.ResourceType == "Infrastructure.Virtual" {
d.Set("name", i.Name)
d.Set("ip_address", i.Data.IPAddress)
d.SetConnInfo(map[string]string{
"host": i.Data.IPAddress,
})
}
}

}
return nil
}

Expand Down