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

Add support for public ip node pool #184

Merged
merged 1 commit into from
Jul 24, 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
14 changes: 10 additions & 4 deletions civo/datasource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func dataSourcenodePoolSchema() *schema.Schema {
Description: "A list of the instance in the pool",
Elem: &schema.Schema{Type: schema.TypeString},
},
"public_ip_node_pool": {
Type: schema.TypeBool,
Computed: true,
Description: "Node pool belongs to the public ip node pool",
},
},
},
}
Expand Down Expand Up @@ -246,10 +251,11 @@ func flattenDataSourceNodePool(cluster *civogo.KubernetesCluster) []interface{}
poolInstanceNames = append(poolInstanceNames, pool.InstanceNames...)

rawPool := map[string]interface{}{
"label": pool.ID,
"node_count": pool.Count,
"size": pool.Size,
"instance_names": poolInstanceNames,
"label": pool.ID,
"node_count": pool.Count,
"size": pool.Size,
"instance_names": poolInstanceNames,
"public_ip_node_pool": pool.PublicIPNodePool,
}
flattenedPool = append(flattenedPool, rawPool)
}
Expand Down
20 changes: 16 additions & 4 deletions civo/resource_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,12 @@ func nodePoolSchema() *schema.Schema {
Elem: &schema.Schema{Type: schema.TypeString},
Description: "Instance names in the nodepool",
},
"public_ip_node_pool": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Node pool belongs to the public ip node pool",
},
},
},
}
Expand Down Expand Up @@ -495,10 +501,11 @@ func flattenNodePool(cluster *civogo.KubernetesCluster) []interface{} {
poolInstanceNames = append(poolInstanceNames, cluster.Pools[0].InstanceNames...)

rawPool := map[string]interface{}{
"label": cluster.Pools[0].ID,
"node_count": cluster.Pools[0].Count,
"size": cluster.Pools[0].Size,
"instance_names": poolInstanceNames,
"label": cluster.Pools[0].ID,
"node_count": cluster.Pools[0].Count,
"size": cluster.Pools[0].Size,
"instance_names": poolInstanceNames,
"public_ip_node_pool": cluster.Pools[0].PublicIPNodePool,
}

flattenedPool = append(flattenedPool, rawPool)
Expand Down Expand Up @@ -543,6 +550,11 @@ func expandNodePools(nodePools []interface{}) []civogo.KubernetesClusterPoolConf
Size: pool["size"].(string),
Count: pool["node_count"].(int),
}

if pool["public_ip_node_pool"].(bool) {
cr.PublicIPNodePool = pool["public_ip_node_pool"].(bool)
}

expandedNodePools = append(expandedNodePools, cr)
}

Expand Down
21 changes: 20 additions & 1 deletion civo/resource_kubernetes_cluster_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func resourceKubernetesClusterNodePool() *schema.Resource {
},
Description: "Instance names in the nodepool",
},
"public_ip_node_pool": {
Type: schema.TypeBool,
Optional: true,
Computed: true,
Description: "Node pool belongs to the public ip node pool",
},
},
CreateContext: resourceKubernetesClusterNodePoolCreate,
ReadContext: resourceKubernetesClusterNodePoolRead,
Expand Down Expand Up @@ -129,7 +135,13 @@ func resourceKubernetesClusterNodePoolCreate(ctx context.Context, d *schema.Reso
newPool = append(newPool, civogo.KubernetesClusterPoolConfig{ID: v.ID, Count: v.Count, Size: v.Size})
}

newPool = append(newPool, civogo.KubernetesClusterPoolConfig{ID: nodePoolLabel, Count: count, Size: size})
pool := civogo.KubernetesClusterPoolConfig{ID: nodePoolLabel, Count: count, Size: size}

if value, ok := d.GetOk("public_ip_node_pool"); ok {
pool.PublicIPNodePool = value.(bool)
}

newPool = append(newPool, pool)

log.Printf("[INFO] configuring kubernetes cluster %s to add pool %s", getKubernetesCluster.ID, nodePoolLabel)
config := &civogo.KubernetesClusterConfig{
Expand Down Expand Up @@ -184,6 +196,10 @@ func resourceKubernetesClusterNodePoolRead(_ context.Context, d *schema.Resource
d.Set("node_count", resp.Pools[poolIndex].Count)
d.Set("size", resp.Pools[poolIndex].Size)

if resp.Pools[poolIndex].PublicIPNodePool {
d.Set("public_ip_node_pool", resp.Pools[poolIndex].PublicIPNodePool)
}

poolInstanceNames := make([]string, 0)
poolInstanceNames = append(poolInstanceNames, resp.Pools[poolIndex].InstanceNames...)

Expand Down Expand Up @@ -321,6 +337,9 @@ func resourceKubernetesClusterNodePoolImport(d *schema.ResourceData, m interface
d.Set("node_count", v.Count)
d.Set("size", v.Size)
d.Set("region", currentRegionCode)
if v.PublicIPNodePool {
d.Set("public_ip_node_pool", v.PublicIPNodePool)
}
}
}
}
Expand Down
46 changes: 23 additions & 23 deletions examples/data-sources/civo_database_version/data-source.tf
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
# Example for mysql
data civo_database_version "mysql" {
data "civo_database_version" "mysql" {
filter {
key = "engine"
values = ["mysql"]
}
key = "engine"
values = ["mysql"]
}
}

# Example for postgresql
data civo_database_version "postgresql" {
data "civo_database_version" "postgresql" {
filter {
key = "engine"
values = ["postgresql"]
}
key = "engine"
values = ["postgresql"]
}
}

data "civo_size" "small" {
filter {
key = "name"
values = ["db.small"]
match_by = "re"
}
filter {
key = "type"
values = ["database"]
}
filter {
key = "name"
values = ["db.small"]
match_by = "re"
}
filter {
key = "type"
values = ["database"]
}
}

# To use this data source, make sure you have a database cluster created.
resource "civo_database" "custom_database" {
name = "custom_database"
size = element(data.civo_size.small.sizes, 0).name
nodes = 2
engine = element(data.civo_database_version.mysql.versions, 0).engine
version = element(data.civo_database_version.mysql.versions, 0).version
}
name = "custom_database"
size = element(data.civo_size.small.sizes, 0).name
nodes = 2
engine = element(data.civo_database_version.mysql.versions, 0).engine
version = element(data.civo_database_version.mysql.versions, 0).version
}
38 changes: 19 additions & 19 deletions examples/resources/civo_database/resource.tf
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
data "civo_size" "small" {
filter {
key = "name"
values = ["db.small"]
match_by = "re"
}
filter {
key = "type"
values = ["database"]
}
filter {
key = "name"
values = ["db.small"]
match_by = "re"
}
filter {
key = "type"
values = ["database"]
}
}

data civo_database_version "mysql" {
data "civo_database_version" "mysql" {
filter {
key = "engine"
values = ["mysql"]
}
key = "engine"
values = ["mysql"]
}
}

resource "civo_database" "custom_database" {
name = "custom_database"
size = element(data.civo_size.small.sizes, 0).name
nodes = 2
engine = element(data.civo_database_version.mysql.versions, 0).engine
version = element(data.civo_database_version.mysql.versions, 0).version
}
name = "custom_database"
size = element(data.civo_size.small.sizes, 0).name
nodes = 2
engine = element(data.civo_database_version.mysql.versions, 0).engine
version = element(data.civo_database_version.mysql.versions, 0).version
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/civo/terraform-provider-civo

require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/civo/civogo v0.3.36
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/google/uuid v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XL
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/civo/civogo v0.3.36 h1:hewtVJ0aA7/K2o15STFaX3mIio1iNQPrrOjdadhraO0=
github.com/civo/civogo v0.3.36/go.mod h1:ovGwXtszFiTsVq1OgKG9CtE8q8TPm+4bwE13KuJBr9E=
github.com/civo/civogo v0.3.42 h1:+9W/EFGtk37l0WzD/evktrGbqXE6/MM4TtHuJ5hnPd0=
github.com/civo/civogo v0.3.42/go.mod h1:54lv/FOf7gh6wE9ZwVdw4yBehk8V1CvU9aWa4v6dvW0=
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/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand Down
Loading