Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the civo_size with the new format and add more examples #188

Merged
merged 1 commit into from
Oct 1, 2023
Merged
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
39 changes: 22 additions & 17 deletions civo/datasource_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Size struct {
Type string
CPU int
RAM int
GPU int
GPUType string
DisK int
Selectable bool
}
Expand Down Expand Up @@ -51,24 +53,15 @@ func getSizes(m interface{}, _ map[string]interface{}) ([]interface{}, error) {
continue
}

typeName := ""

switch {
case strings.Contains(v.Name, "db"):
typeName = "database"
case strings.Contains(v.Name, "kube") || strings.Contains(v.Name, "k3s"):
typeName = "kubernetes"
default:
typeName = "instance"
}

sizeList = append(sizeList, Size{
Name: v.Name,
Description: v.Description,
Type: typeName,
Type: strings.ToLower(v.Type),
CPU: v.CPUCores,
RAM: v.RAMMegabytes,
DisK: v.DiskGigabytes,
GPU: v.GPUCount,
GPUType: v.GPUType,
Selectable: v.Selectable,
})
}
Expand All @@ -90,6 +83,8 @@ func flattenSize(size, _ interface{}, _ map[string]interface{}) (map[string]inte
flattenedSize["cpu"] = s.CPU
flattenedSize["ram"] = s.RAM
flattenedSize["disk"] = s.DisK
flattenedSize["gpu"] = s.GPU
flattenedSize["gpu_type"] = s.GPUType
flattenedSize["description"] = s.Description
flattenedSize["selectable"] = s.Selectable

Expand All @@ -101,27 +96,37 @@ func sizeSchema() map[string]*schema.Schema {
"name": {
Type: schema.TypeString,
Computed: true,
Description: "The name of the instance size",
Description: "The name of the size",
},
"type": {
Type: schema.TypeString,
Computed: true,
Description: "A human name of the instance size",
Description: "A human name of the size",
},
"cpu": {
Type: schema.TypeInt,
Computed: true,
Description: "Total of CPU in the instance",
Description: "Total of CPU",
},
"ram": {
Type: schema.TypeInt,
Computed: true,
Description: "Total of RAM of the instance",
Description: "Total of RAM",
},
"disk": {
Type: schema.TypeInt,
Computed: true,
Description: "The instance size of SSD",
Description: "The size of SSD",
},
"gpu": {
Type: schema.TypeInt,
Computed: true,
Description: "Total of GPU",
},
"gpu_type": {
Type: schema.TypeString,
Computed: true,
Description: "GPU type",
},
"description": {
Type: schema.TypeString,
Expand Down
1 change: 0 additions & 1 deletion examples/data-sources/civo_size/data-source.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ data "civo_size" "small" {
key = "type"
values = ["instance"]
}

}

resource "civo_instance" "my-test-instance" {
Expand Down
11 changes: 11 additions & 0 deletions examples/data-sources/civo_size/database.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "civo_size" "dbxsmall" {
filter {
key = "name"
values = ["g3.db.xsmall"]
}

filter {
key = "type"
values = ["database"]
}
}
12 changes: 12 additions & 0 deletions examples/data-sources/civo_size/instance.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "civo_size" "small" {
filter {
key = "name"
values = ["g3.small"]
match_by = "re"
}

filter {
key = "type"
values = ["instance"]
}
}
11 changes: 11 additions & 0 deletions examples/data-sources/civo_size/kfaas.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "civo_size" "kfsmall" {
filter {
key = "name"
values = ["g3.kf.small"]
}

filter {
key = "type"
values = ["kfcluster"]
}
}
11 changes: 11 additions & 0 deletions examples/data-sources/civo_size/kubernetes.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
data "civo_size" "kxsmall" {
filter {
key = "name"
values = ["g3.k3s.xsmall"]
}

filter {
key = "type"
values = ["kubernetes"]
}
}
16 changes: 7 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ module github.com/civo/terraform-provider-civo

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/civo/civogo v0.3.42
github.com/go-logr/logr v1.2.4 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/civo/civogo v0.3.47
github.com/google/uuid v1.3.0
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1
github.com/hashicorp/yamux v0.0.0-20211028200310-0bc27b27de87 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/oklog/run v1.1.0 // indirect
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/vmihailenco/tagparser v0.1.2 // indirect
golang.org/x/crypto v0.7.0
golang.org/x/net v0.10.0 // indirect
golang.org/x/crypto v0.13.0
golang.org/x/net v0.15.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220715211116-798f69b842b9 // indirect
k8s.io/api v0.27.2 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/utils v0.0.0-20230505201702-9f6742963106 // indirect
k8s.io/api v0.28.2 // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
)

go 1.16
Loading
Loading