-
Notifications
You must be signed in to change notification settings - Fork 532
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added multiple target nodes instead of a single node. (#766)
* added data_ha_group.go to fetch HA Groups * renamed variable in data ha group file * added the possibility to add a node with a set of possible nodes (high availability) * minor code fixes --------- Co-authored-by: Pascal Kutscha <[email protected]>
- Loading branch information
Showing
4 changed files
with
153 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package proxmox | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/Telmate/proxmox-api-go/proxmox" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func DataHAGroup() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataReadHAGroup, | ||
Schema: map[string]*schema.Schema{ | ||
"group_name": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"nodes": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
}, | ||
"type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"restricted": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"nofailback": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"comment": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataReadHAGroup(data *schema.ResourceData, meta interface{}) (err error) { | ||
pconf := meta.(*providerConfiguration) | ||
lock := pmParallelBegin(pconf) | ||
defer lock.unlock() | ||
|
||
client := pconf.Client | ||
|
||
var group *proxmox.HAGroup | ||
group, err = client.GetHAGroupByName(data.Get("group_name").(string)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
nodes := group.Nodes | ||
sort.Strings(nodes) | ||
|
||
data.SetId(group.Group) | ||
_ = data.Set("nodes", nodes) | ||
_ = data.Set("type", group.Type) | ||
_ = data.Set("restricted", group.Restricted) | ||
_ = data.Set("nofailback", group.NoFailback) | ||
_ = data.Set("comment", group.Comment) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters