Skip to content

Commit beb925c

Browse files
authored
Merge pull request #69 from cloud-ca/dedicated_group_id
Dedicated groups in create instance
2 parents 75c3a73 + 0ed3204 commit beb925c

File tree

9 files changed

+111
-2
lines changed

9 files changed

+111
-2
lines changed

cloudca/resource_cloudca_instance.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ func resourceCloudcaInstance() *schema.Resource {
105105
Computed: true,
106106
Description: "The IPv4 address of the instance. Must be within the network's CIDR and not collide with existing instances.",
107107
},
108+
"dedicated_group_id": {
109+
Type: schema.TypeString,
110+
Optional: true,
111+
ForceNew: true,
112+
Description: "Id of the dedicated group into which the new instance will be created",
113+
},
108114
},
109115
}
110116
}
@@ -168,6 +174,10 @@ func resourceCloudcaInstanceCreate(d *schema.ResourceData, meta interface{}) err
168174
instanceToCreate.RootVolumeSizeInGb = rootVolumeSizeInGb.(int)
169175
}
170176

177+
if dedicatedGroupID, ok := d.GetOk("dedicated_group_id"); ok {
178+
instanceToCreate.DedicatedGroupId = dedicatedGroupID.(string)
179+
}
180+
171181
newInstance, err := ccaResources.Instances.Create(instanceToCreate)
172182
if err != nil {
173183
return fmt.Errorf("Error creating the new instance %s: %s", instanceToCreate.Name, err)
@@ -208,6 +218,11 @@ func resourceCloudcaInstanceRead(d *schema.ResourceData, meta interface{}) error
208218
d.Set("network_id", instance.NetworkId)
209219
d.Set("private_ip_id", instance.IpAddressId)
210220
d.Set("private_ip", instance.IpAddress)
221+
dID, dIDErr := getDedicatedGroupId(ccaResources, instance)
222+
if dIDErr != nil {
223+
return dIDErr
224+
}
225+
d.Set("dedicated_group_id", dID)
211226

212227
return nil
213228
}
@@ -334,3 +349,21 @@ func retrieveTemplateID(ccaRes *cloudca.Resources, name string) (id string, err
334349

335350
return "", fmt.Errorf("Template with name %s not found", name)
336351
}
352+
353+
354+
func getDedicatedGroupId(ccaRes cloudca.Resources, instance *cloudca.Instance) (string, error) {
355+
dedicatedGroups, err := ccaRes.AffinityGroups.ListWithOptions(map[string]string{
356+
"type": "ExplicitDedication",
357+
})
358+
if err != nil {
359+
return "", err
360+
}
361+
for _, dedicatedGroup := range dedicatedGroups {
362+
for _, affinityGroupId := range instance.AffinityGroupIds {
363+
if strings.EqualFold(dedicatedGroup.Id, affinityGroupId) {
364+
return dedicatedGroup.Id, nil
365+
}
366+
}
367+
}
368+
return "", nil
369+
}

doc/instance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ resource "cloudca_instance" "my_instance" {
1414
ssh_key_name = "my_ssh_key"
1515
root_volume_size_in_gb = 100
1616
private_ip = "10.2.1.124"
17+
dedicated_group_id = "78fdce97-3a46-4b50-bca7-c70ef8449da8"
1718
}
1819
```
1920

@@ -33,6 +34,7 @@ The following arguments are supported:
3334
- [public_key](#public_key) - (Optional) Public key to attach to the instance. Mutually exclusive with ssh_key_name.
3435
- [root_volume_size_in_gb](#root_volume_size_in_gb) - (Optional) Size of the root volume of the instance. This only works for templates that allows root volume resize.
3536
- [private_ip](#private_ip) - (Optional) Instance's private IPv4 address.
37+
- [dedicated_group_id](#dedicated_group_id) - (Optional) Dedicated group id in which the instance will be created
3638

3739
## Attribute Reference
3840

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/cloud-ca/terraform-provider-cloudca
33
require (
44
github.com/apparentlymart/go-cidr v1.0.0 // indirect
55
github.com/blang/semver v3.5.1+incompatible // indirect
6-
github.com/cloud-ca/go-cloudca v1.2.0
6+
github.com/cloud-ca/go-cloudca v1.3.0
77
github.com/hashicorp/go-getter v1.0.3 // indirect
88
github.com/hashicorp/go-hclog v0.0.0-20190109152822-4783caec6f2e // indirect
99
github.com/hashicorp/go-plugin v0.0.0-20190129155509-362c99b11937 // indirect

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2m
1919
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
2020
github.com/cloud-ca/go-cloudca v1.2.0 h1:215x34c2XUMxj9GV5gYH9JhqtabDysX2quXvNiKIgco=
2121
github.com/cloud-ca/go-cloudca v1.2.0/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
22+
github.com/cloud-ca/go-cloudca v1.2.1-0.20190211191729-cd925097c528 h1:DPBpPNdP0SD6InpeChFXPksAPK+3UQFQNY6vBua0QPc=
23+
github.com/cloud-ca/go-cloudca v1.2.1-0.20190211191729-cd925097c528/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
24+
github.com/cloud-ca/go-cloudca v1.3.0 h1:LhoCxu+Tna/OOoDbSD2adgwlA+WgKfUzzcHBcEu5akE=
25+
github.com/cloud-ca/go-cloudca v1.3.0/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
2226
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2327
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2428
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=

vendor/github.com/cloud-ca/go-cloudca/services/cloudca/affinity_groups.go

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloud-ca/go-cloudca/services/cloudca/entity_type.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloud-ca/go-cloudca/services/cloudca/instance.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/cloud-ca/go-cloudca/services/cloudca/resources.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ github.com/bgentry/go-netrc/netrc
4646
github.com/bgentry/speakeasy
4747
# github.com/blang/semver v3.5.1+incompatible
4848
github.com/blang/semver
49-
# github.com/cloud-ca/go-cloudca v1.2.0
49+
# github.com/cloud-ca/go-cloudca v1.3.0
5050
github.com/cloud-ca/go-cloudca
5151
github.com/cloud-ca/go-cloudca/api
5252
github.com/cloud-ca/go-cloudca/configuration

0 commit comments

Comments
 (0)