Skip to content

Commit

Permalink
Merge pull request #69 from cloud-ca/dedicated_group_id
Browse files Browse the repository at this point in the history
Dedicated groups in create instance
  • Loading branch information
franzpgarcia authored Feb 11, 2019
2 parents 75c3a73 + 0ed3204 commit beb925c
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 2 deletions.
33 changes: 33 additions & 0 deletions cloudca/resource_cloudca_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ func resourceCloudcaInstance() *schema.Resource {
Computed: true,
Description: "The IPv4 address of the instance. Must be within the network's CIDR and not collide with existing instances.",
},
"dedicated_group_id": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: "Id of the dedicated group into which the new instance will be created",
},
},
}
}
Expand Down Expand Up @@ -168,6 +174,10 @@ func resourceCloudcaInstanceCreate(d *schema.ResourceData, meta interface{}) err
instanceToCreate.RootVolumeSizeInGb = rootVolumeSizeInGb.(int)
}

if dedicatedGroupID, ok := d.GetOk("dedicated_group_id"); ok {
instanceToCreate.DedicatedGroupId = dedicatedGroupID.(string)
}

newInstance, err := ccaResources.Instances.Create(instanceToCreate)
if err != nil {
return fmt.Errorf("Error creating the new instance %s: %s", instanceToCreate.Name, err)
Expand Down Expand Up @@ -208,6 +218,11 @@ func resourceCloudcaInstanceRead(d *schema.ResourceData, meta interface{}) error
d.Set("network_id", instance.NetworkId)
d.Set("private_ip_id", instance.IpAddressId)
d.Set("private_ip", instance.IpAddress)
dID, dIDErr := getDedicatedGroupId(ccaResources, instance)
if dIDErr != nil {
return dIDErr
}
d.Set("dedicated_group_id", dID)

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

return "", fmt.Errorf("Template with name %s not found", name)
}


func getDedicatedGroupId(ccaRes cloudca.Resources, instance *cloudca.Instance) (string, error) {
dedicatedGroups, err := ccaRes.AffinityGroups.ListWithOptions(map[string]string{
"type": "ExplicitDedication",
})
if err != nil {
return "", err
}
for _, dedicatedGroup := range dedicatedGroups {
for _, affinityGroupId := range instance.AffinityGroupIds {
if strings.EqualFold(dedicatedGroup.Id, affinityGroupId) {
return dedicatedGroup.Id, nil
}
}
}
return "", nil
}
2 changes: 2 additions & 0 deletions doc/instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ resource "cloudca_instance" "my_instance" {
ssh_key_name = "my_ssh_key"
root_volume_size_in_gb = 100
private_ip = "10.2.1.124"
dedicated_group_id = "78fdce97-3a46-4b50-bca7-c70ef8449da8"
}
```

Expand All @@ -33,6 +34,7 @@ The following arguments are supported:
- [public_key](#public_key) - (Optional) Public key to attach to the instance. Mutually exclusive with ssh_key_name.
- [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.
- [private_ip](#private_ip) - (Optional) Instance's private IPv4 address.
- [dedicated_group_id](#dedicated_group_id) - (Optional) Dedicated group id in which the instance will be created

## Attribute Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/cloud-ca/terraform-provider-cloudca
require (
github.com/apparentlymart/go-cidr v1.0.0 // indirect
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/cloud-ca/go-cloudca v1.2.0
github.com/cloud-ca/go-cloudca v1.3.0
github.com/hashicorp/go-getter v1.0.3 // indirect
github.com/hashicorp/go-hclog v0.0.0-20190109152822-4783caec6f2e // indirect
github.com/hashicorp/go-plugin v0.0.0-20190129155509-362c99b11937 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ github.com/bsm/go-vlq v0.0.0-20150828105119-ec6e8d4f5f4e/go.mod h1:N+BjUcTjSxc2m
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
github.com/cloud-ca/go-cloudca v1.2.0 h1:215x34c2XUMxj9GV5gYH9JhqtabDysX2quXvNiKIgco=
github.com/cloud-ca/go-cloudca v1.2.0/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
github.com/cloud-ca/go-cloudca v1.2.1-0.20190211191729-cd925097c528 h1:DPBpPNdP0SD6InpeChFXPksAPK+3UQFQNY6vBua0QPc=
github.com/cloud-ca/go-cloudca v1.2.1-0.20190211191729-cd925097c528/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
github.com/cloud-ca/go-cloudca v1.3.0 h1:LhoCxu+Tna/OOoDbSD2adgwlA+WgKfUzzcHBcEu5akE=
github.com/cloud-ca/go-cloudca v1.3.0/go.mod h1:L8yDVtO6lmn2H50a6nMxYcGINgU6kVwpDeF/IxZVpsg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ github.com/bgentry/go-netrc/netrc
github.com/bgentry/speakeasy
# github.com/blang/semver v3.5.1+incompatible
github.com/blang/semver
# github.com/cloud-ca/go-cloudca v1.2.0
# github.com/cloud-ca/go-cloudca v1.3.0
github.com/cloud-ca/go-cloudca
github.com/cloud-ca/go-cloudca/api
github.com/cloud-ca/go-cloudca/configuration
Expand Down

0 comments on commit beb925c

Please sign in to comment.