Skip to content

Commit

Permalink
Added CPU, RAM and SSD fields to Instance and Kubernetes module
Browse files Browse the repository at this point in the history
* Update the data sources instance, instances and kubernetes cluster, now you can filter by that fields
* Update the resources instance and kubernetes cluster
* Update the documentation
* Update the civogo lib to v0.2.12 to add the new filed

Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
  • Loading branch information
alejandrojnm committed Jul 7, 2020
1 parent 6e56ab4 commit d5eaef1
Show file tree
Hide file tree
Showing 15 changed files with 171 additions and 3 deletions.
15 changes: 15 additions & 0 deletions civo/datasource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func dataSourceInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"cpu_cores": {
Type: schema.TypeInt,
Computed: true,
},
"ram_mb": {
Type: schema.TypeInt,
Computed: true,
},
"disk_gb": {
Type: schema.TypeInt,
Computed: true,
},
"network_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -124,6 +136,9 @@ func dataSourceInstanceRead(d *schema.ResourceData, m interface{}) error {
d.Set("hostname", foundImage.Hostname)
d.Set("reverse_dns", foundImage.ReverseDNS)
d.Set("size", foundImage.Size)
d.Set("cpu_cores", foundImage.CPUCores)
d.Set("ram_mb", foundImage.RAMMegabytes)
d.Set("disk_gb", foundImage.DiskGigabytes)
d.Set("initial_user", foundImage.InitialUser)
d.Set("initial_password", foundImage.InitialPassword)
d.Set("sshkey_id", foundImage.SSHKey)
Expand Down
22 changes: 22 additions & 0 deletions civo/datasource_instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package civo

import (
"fmt"

"github.com/civo/civogo"
"github.com/civo/terraform-provider-civo/internal/datalist"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -27,6 +28,18 @@ func dataSourceInstances() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"cpu_cores": {
Type: schema.TypeInt,
Computed: true,
},
"ram_mb": {
Type: schema.TypeInt,
Computed: true,
},
"disk_gb": {
Type: schema.TypeInt,
Computed: true,
},
"network_id": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -92,6 +105,9 @@ func dataSourceInstances() *schema.Resource {
"private_ip",
"pseudo_ip",
"size",
"cpu_cores",
"ram_mb",
"disk_gb",
"template",
"created_at",
},
Expand All @@ -102,6 +118,9 @@ func dataSourceInstances() *schema.Resource {
"private_ip",
"pseudo_ip",
"size",
"cpu_cores",
"ram_mb",
"disk_gb",
"template",
"created_at",
},
Expand Down Expand Up @@ -139,6 +158,9 @@ func flattenDataSourceInstances(instance, m interface{}) (map[string]interface{}
flattenedInstance["hostname"] = i.Hostname
flattenedInstance["reverse_dns"] = i.ReverseDNS
flattenedInstance["size"] = i.Size
flattenedInstance["cpu_cores"] = i.CPUCores
flattenedInstance["ram_mb"] = i.RAMMegabytes
flattenedInstance["disk_gb"] = i.DiskGigabytes
flattenedInstance["network_id"] = i.NetworkID
flattenedInstance["template"] = i.TemplateID
flattenedInstance["initial_user"] = i.InitialUser
Expand Down
12 changes: 12 additions & 0 deletions civo/datasource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ func dataSourceInstanceSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"cpu_cores": {
Type: schema.TypeInt,
Computed: true,
},
"ram_mb": {
Type: schema.TypeInt,
Computed: true,
},
"disk_gb": {
Type: schema.TypeInt,
Computed: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down
48 changes: 48 additions & 0 deletions civo/import_dns_domain_record_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package civo

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)

func TestAccCivoDNSDomainRecord_importBasic(t *testing.T) {
resourceName := "civo_dns_domain_record.www"
var domainName = acctest.RandomWithPrefix("tf-test-record") + ".example"
var recordName = acctest.RandomWithPrefix("record")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckCivoDNSDomainNameRecordDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckCivoDNSDomainNameRecordConfigBasic(domainName, recordName),
},

{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: testAccDNSDomainNameRecordImportID(resourceName),
},
},
})
}

func testAccDNSDomainNameRecordImportID(n string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[n]
if !ok {
return "", fmt.Errorf("Not found: %s", n)
}

domainID := rs.Primary.Attributes["domain_id"]
id := rs.Primary.ID

return fmt.Sprintf("%s:%s", domainID, id), nil
}
}
15 changes: 15 additions & 0 deletions civo/resource_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,18 @@ func resourceInstance() *schema.Resource {
ValidateFunc: validation.StringIsNotEmpty,
},
// Computed resource
"cpu_cores": {
Type: schema.TypeInt,
Computed: true,
},
"ram_mb": {
Type: schema.TypeInt,
Computed: true,
},
"disk_gb": {
Type: schema.TypeInt,
Computed: true,
},
"initial_password": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -237,6 +249,9 @@ func resourceInstanceRead(d *schema.ResourceData, m interface{}) error {
d.Set("hostname", resp.Hostname)
d.Set("reverse_dns", resp.ReverseDNS)
d.Set("size", resp.Size)
d.Set("cpu_cores", resp.CPUCores)
d.Set("ram_mb", resp.RAMMegabytes)
d.Set("disk_gb", resp.DiskGigabytes)
d.Set("initial_user", resp.InitialUser)
d.Set("initial_password", resp.InitialPassword)
d.Set("sshkey_id", resp.SSHKey)
Expand Down
21 changes: 21 additions & 0 deletions civo/resource_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestAccCivoInstance_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
resource.TestCheckResourceAttrSet(resName, "public_ip"),
Expand Down Expand Up @@ -67,6 +70,9 @@ func TestAccCivoInstanceSize_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
resource.TestCheckResourceAttrSet(resName, "public_ip"),
Expand All @@ -83,6 +89,9 @@ func TestAccCivoInstanceSize_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.large"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "4"),
resource.TestCheckResourceAttr(resName, "ram_mb", "8192"),
resource.TestCheckResourceAttr(resName, "disk_gb", "100"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
resource.TestCheckResourceAttrSet(resName, "public_ip"),
Expand Down Expand Up @@ -114,6 +123,9 @@ func TestAccCivoInstanceNotes_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttr(resName, "notes", ""),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
Expand All @@ -131,6 +143,9 @@ func TestAccCivoInstanceNotes_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttr(resName, "notes", "the_test_notes"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
Expand Down Expand Up @@ -164,6 +179,9 @@ func TestAccCivoInstanceFirewall_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
resource.TestCheckResourceAttrSet(resName, "public_ip"),
Expand All @@ -181,6 +199,9 @@ func TestAccCivoInstanceFirewall_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "hostname", instanceHostname),
resource.TestCheckResourceAttr(resName, "size", "g2.xsmall"),
resource.TestCheckResourceAttr(resName, "initial_user", "civo"),
resource.TestCheckResourceAttr(resName, "cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "ram_mb", "1024"),
resource.TestCheckResourceAttr(resName, "disk_gb", "25"),
resource.TestCheckResourceAttrSet(resName, "firewall_id"),
resource.TestCheckResourceAttrSet(resName, "initial_password"),
resource.TestCheckResourceAttrSet(resName, "private_ip"),
Expand Down
15 changes: 15 additions & 0 deletions civo/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ func instanceSchema() *schema.Schema {
Type: schema.TypeString,
Computed: true,
},
"cpu_cores": {
Type: schema.TypeInt,
Computed: true,
},
"ram_mb": {
Type: schema.TypeInt,
Computed: true,
},
"disk_gb": {
Type: schema.TypeInt,
Computed: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -318,6 +330,9 @@ func flattenInstances(instances []civogo.KubernetesInstance) []interface{} {
rawInstance := map[string]interface{}{
"hostname": instance.Hostname,
"size": instance.Size,
"cpu_cores": instance.CPUCores,
"ram_mb": instance.RAMMegabytes,
"disk_gb": instance.DiskGigabytes,
"region": instance.Region,
"status": instance.Status,
"firewall_id": instance.FirewallID,
Expand Down
3 changes: 3 additions & 0 deletions civo/resource_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ func TestAccCivoKubernetesCluster_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "name", kubernetesClusterName),
resource.TestCheckResourceAttr(resName, "num_target_nodes", "2"),
resource.TestCheckResourceAttr(resName, "target_nodes_size", "g2.small"),
resource.TestCheckResourceAttr(resName, "instances.0.cpu_cores", "1"),
resource.TestCheckResourceAttr(resName, "instances.0.ram_mb", "2048"),
resource.TestCheckResourceAttr(resName, "instances.0.disk_gb", "25"),
// resource.TestCheckResourceAttrSet(resName, "instances"),
resource.TestCheckResourceAttrSet(resName, "kubeconfig"),
resource.TestCheckResourceAttrSet(resName, "api_endpoint"),
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/civo/terraform-provider-civo
require (
cloud.google.com/go v0.54.0 // indirect
github.com/aws/aws-sdk-go v1.29.22 // indirect
github.com/civo/civogo v0.2.11
github.com/civo/civogo v0.2.12
github.com/fatih/color v1.9.0 // indirect
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75
github.com/hashicorp/go-getter v1.4.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ github.com/civo/civogo v0.2.10 h1:hcX3hSEzPAmH+bNwcwAorYKcl4fe81vQEyk4zR+0URg=
github.com/civo/civogo v0.2.10/go.mod h1:SR0ZOhABfQHjgNQE3UyfX4gaYsrfslkPFRFMx5P29rg=
github.com/civo/civogo v0.2.11 h1:NBWf3048YQSxwgS0+nY+77fh8xCAACUkmL0pXPwYZlw=
github.com/civo/civogo v0.2.11/go.mod h1:SR0ZOhABfQHjgNQE3UyfX4gaYsrfslkPFRFMx5P29rg=
github.com/civo/civogo v0.2.12 h1:+Fx1of+LurR6xRUHUghvJfyi7jONkuZR8eYDHriCA74=
github.com/civo/civogo v0.2.12/go.mod h1:SR0ZOhABfQHjgNQE3UyfX4gaYsrfslkPFRFMx5P29rg=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
3 changes: 3 additions & 0 deletions website/docs/d/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ The following attributes are exported:
* `hostname` - The Instance hostname.
* `reverse_dns` - A fully qualified domain name.
* `size` - The name of the size.
* `cpu_cores` - Total cpu of the inatance.
* `ram_mb` - Total ram of the instance.
* `disk_gb` - The size of the disk.
* `public_ip_requiered` - This should be either false, true or `move_ip_from:intances_id`.
* `network_id` - This will be the ID of the network.
* `template` - The ID for the template to used to build the instance.
Expand Down
7 changes: 5 additions & 2 deletions website/docs/d/instances.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ data "civo_instances" "small-with-backups" {
`filter` supports the following arguments:

* `key` - (Required) Filter the Instances by this key. This may be one of '`id`, `hostname`, `public_ip`, `private_ip`,
`pseudo_ip`, `size`, `template` or `created_at`.
`pseudo_ip`, `size`, `cpu_cores`, `ram_mb`, `disk_gb`, `template` or `created_at`.

* `values` - (Required) A list of values to match against the `key` field. Only retrieves Instances
where the `key` field takes on one or more of the values provided here.

`sort` supports the following arguments:

* `key` - (Required) Sort the Instance by this key. This may be one of `id`, `hostname`, `public_ip`, `private_ip`,
`pseudo_ip`, `size`, `template` or `created_at`.
`pseudo_ip`, `size`, `cpu_cores`, `ram_mb`, `disk_gb`, `template` or `created_at`.

* `direction` - (Required) The sort direction. This may be either `asc` or `desc`.

Expand All @@ -101,6 +101,9 @@ data "civo_instances" "small-with-backups" {
* `hostname` - The Instance hostname.
* `reverse_dns` - A fully qualified domain name.
* `size` - The name of the size.
* `cpu_cores` - Total cpu of the inatance.
* `ram_mb` - Total ram of the instance.
* `disk_gb` - The size of the disk.
* `public_ip_requiered` - This should be either false, true or `move_ip_from:intances_id`.
* `network_id` - This will be the ID of the network.
* `template` - The ID for the template to used to build the instance.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/d/kubernetes_cluster.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ The following attributes are exported:
* `instances` - In addition to the arguments provided, these additional attributes about the cluster's default node instance are exported.
- `hostname` - The hostname of the instance.
- `size` - The size of the instance.
- `cpu_cores` - Total cpu of the inatance.
- `ram_mb` - Total ram of the instance
- `disk_gb` - The size of the disk.
- `region` - The region where instance are.
- `status` - The status of the instance.
- `created_at` - The date where the instances was created.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ The following attributes are exported:
* `hostname` - The Instance hostname.
* `reverse_dns` - A fully qualified domain name.
* `size` - The name of the size.
* `cpu_cores` - Total cpu of the inatance.
* `ram_mb` - Total ram of the instance.
* `disk_gb` - The size of the disk.
* `public_ip_requiered` - This should be either false, true or `move_ip_from:intances_id`.
* `network_id` - This will be the ID of the network.
* `template` - The ID for the template to used to build the instance.
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/kubernetes_cluster.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ In addition to the arguments listed above, the following additional attributes a
* `instances` - In addition to the arguments provided, these additional attributes about the cluster's default node instance are exported.
- `hostname` - The hostname of the instance.
- `size` - The size of the instance.
- `cpu_cores` - Total cpu of the inatance.
- `ram_mb` - Total ram of the instance.
- `disk_gb` - The size of the disk.
- `region` - The region where instance are.
- `status` - The status of the instance.
- `created_at` - The date where the instances was created.
Expand Down

0 comments on commit d5eaef1

Please sign in to comment.