Skip to content

Commit

Permalink
feat(ENG-1862): add cluster production field (#425)
Browse files Browse the repository at this point in the history
Ticket: ENG-1862
  • Loading branch information
benjaminch authored Sep 18, 2024
1 parent 3fcf1b4 commit 2107a03
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/data-sources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ data "qovery_cluster" "my_cluster" {
- `min_running_nodes` (Number) Minimum number of nodes running for the cluster. [NOTE: have to be set to 1 in case of K3S clusters, and not set for Karpenter-enabled clusters].
- Must be: `>= 1`.
- Default: `3`.
- `production` (Boolean) Specific flag to indicate that this cluster is a production one.
- `routing_table` (Attributes Set) List of routes of the cluster. (see [below for nested schema](#nestedatt--routing_table))
- `state` (String) State of the cluster.
- Can be: `DEPLOYED`, `STOPPED`.
Expand Down
1 change: 1 addition & 0 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ You can find complete examples within these repositories:
- `min_running_nodes` (Number) Minimum number of nodes running for the cluster. [NOTE: have to be set to 1 in case of K3S clusters, and not set for Karpenter-enabled clusters].
- Must be: `>= 1`.
- Default: `3`.
- `production` (Boolean) Specific flag to indicate that this cluster is a production one.
- `routing_table` (Attributes Set) List of routes of the cluster. (see [below for nested schema](#nestedatt--routing_table))
- `state` (String) State of the cluster.
- Can be: `DEPLOYED`, `STOPPED`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.29.0
github.com/pkg/errors v0.9.1
github.com/qovery/qovery-client-go v0.0.0-20240911090006-e50e357fd37b
github.com/qovery/qovery-client-go v0.0.0-20240913122611-18cdedd8b78a
github.com/schollz/progressbar/v3 v3.13.0
github.com/sethvargo/go-envconfig v0.9.0
github.com/stretchr/testify v1.9.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ github.com/qovery/qovery-client-go v0.0.0-20240906095121-caf9fd671ddc h1:7cH7cMO
github.com/qovery/qovery-client-go v0.0.0-20240906095121-caf9fd671ddc/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240911090006-e50e357fd37b h1:LG73JA4vQNCKzOmxT92NtNGZpymUdh/TNpBD3vAPwgo=
github.com/qovery/qovery-client-go v0.0.0-20240911090006-e50e357fd37b/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/qovery/qovery-client-go v0.0.0-20240913122611-18cdedd8b78a h1:jtwo96Q5xMkQCOjpPGwLlpmn1RxxxFIIx7DR/uykBfM=
github.com/qovery/qovery-client-go v0.0.0-20240913122611-18cdedd8b78a/go.mod h1:9eHj5a4EtXGIyfbvVL3HVYW9k7Xmiwi00OqHrP4dc10=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.3 h1:utMvzDsuh3suAEnhH0RdHmoPbU648o6CvXxTx4SBMOw=
github.com/rivo/uniseg v0.4.3/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
Expand Down
5 changes: 5 additions & 0 deletions qovery/data_source_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (r clusterDataSource) Schema(_ context.Context, _ datasource.SchemaRequest,
Optional: true,
Computed: true,
},
"production": schema.BoolAttribute{
Description: "Specific flag to indicate that this cluster is a production one.",
Optional: true,
Computed: true,
},
"instance_type": schema.StringAttribute{
Description: "Instance type of the cluster. I.e: For Aws `t3a.xlarge`, for Scaleway `DEV-L`, and not set for Karpenter-enabled clusters",
Optional: true,
Expand Down
15 changes: 12 additions & 3 deletions qovery/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import (
"context"
_ "embed"
"fmt"
"strings"

"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
"strings"

"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -24,8 +25,10 @@ import (
)

// Ensure provider defined types fully satisfy terraform framework interfaces.
var _ resource.ResourceWithConfigure = &clusterResource{}
var _ resource.ResourceWithImportState = clusterResource{}
var (
_ resource.ResourceWithConfigure = &clusterResource{}
_ resource.ResourceWithImportState = clusterResource{}
)

var (
// Cluster State
Expand Down Expand Up @@ -154,6 +157,12 @@ func (r clusterResource) Schema(_ context.Context, _ resource.SchemaRequest, res
validators.NewStringEnumValidator(clusterKubernetesModes),
},
},
"production": schema.BoolAttribute{
Description: "Specific flag to indicate that this cluster is a production one.",
Optional: true,
Computed: true,
Default: booldefault.StaticBool(false),
},
"instance_type": schema.StringAttribute{
Description: "Instance type of the cluster. I.e: For Aws `t3a.xlarge`, for Scaleway `DEV-L`, and not set for Karpenter-enabled clusters",
Optional: true,
Expand Down
3 changes: 3 additions & 0 deletions qovery/resource_cluster_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Cluster struct {
DiskSize types.Int64 `tfsdk:"disk_size"`
MinRunningNodes types.Int64 `tfsdk:"min_running_nodes"`
MaxRunningNodes types.Int64 `tfsdk:"max_running_nodes"`
Production types.Bool `tfsdk:"production"`
Features types.Object `tfsdk:"features"`
RoutingTables types.Set `tfsdk:"routing_table"`
State types.String `tfsdk:"state"`
Expand Down Expand Up @@ -163,6 +164,7 @@ func (c Cluster) toUpsertClusterRequest(state *Cluster) (*client.ClusterUpsertPa
DiskSize: ToInt64Pointer(c.DiskSize),
MinRunningNodes: ToInt32Pointer(c.MinRunningNodes),
MaxRunningNodes: ToInt32Pointer(c.MaxRunningNodes),
Production: ToBoolPointer(c.Production),
Features: features,
},
ClusterRoutingTable: routingTable.toUpsertRequest(),
Expand All @@ -188,6 +190,7 @@ func convertResponseToCluster(ctx context.Context, res *client.ClusterResponse,
DiskSize: FromInt32Pointer(res.ClusterResponse.DiskSize),
MinRunningNodes: FromInt32Pointer(res.ClusterResponse.MinRunningNodes),
MaxRunningNodes: FromInt32Pointer(res.ClusterResponse.MaxRunningNodes),
Production: FromBoolPointer(res.ClusterResponse.Production),
Features: fromQoveryClusterFeatures(res.ClusterResponse.Features),
RoutingTables: routingTable.toTerraformSet(ctx, initialPlan.RoutingTables),
State: fromClientEnumPointer(res.ClusterResponse.Status),
Expand Down
13 changes: 11 additions & 2 deletions qovery/resource_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func TestAcc_Cluster(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "3"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "10"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.vpc_subnet", "10.0.0.0/16"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "DEPLOYED"),
resource.TestCheckResourceAttr("qovery_cluster.test", "advanced_settings", "{ loki.log_retention_in_week = 1 }"),
Expand All @@ -69,6 +70,7 @@ func TestAcc_Cluster(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "3"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "10"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.vpc_subnet", "10.0.0.0/16"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "DEPLOYED"),
),
Expand All @@ -93,6 +95,7 @@ func TestAcc_Cluster(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "3"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "10"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.vpc_subnet", "10.0.0.0/16"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "STOPPED"),
),
Expand All @@ -118,6 +121,7 @@ func TestAcc_Cluster(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_LARGE"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "4"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "11"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.vpc_subnet", "10.0.0.0/16"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "DEPLOYED"),
),
Expand Down Expand Up @@ -151,6 +155,7 @@ func TestAcc_ClusterWithKubernetesMode(t *testing.T) {
"AWS",
"eu-west-3",
"T3A_SMALL",
true,
),
Check: resource.ComposeAggregateTestCheckFunc(
testAccQoveryClusterExists("qovery_cluster.test"),
Expand All @@ -163,6 +168,7 @@ func TestAcc_ClusterWithKubernetesMode(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MT3A_SMALLEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "1"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "1"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "true"),
resource.TestCheckNoResourceAttr("qovery_cluster.test", "features.vpc_subnet"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "DEPLOYED"),
),
Expand Down Expand Up @@ -213,6 +219,7 @@ func TestAcc_ClusterWithVpcPeering(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "3"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "10"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.vpc_subnet", "10.42.0.0/16"),
resource.TestCheckResourceAttr("qovery_cluster.test", "routing_table.0.description", "route-0"),
resource.TestCheckResourceAttr("qovery_cluster.test", "routing_table.0.destination", "172.30.0.0/16"),
Expand Down Expand Up @@ -253,6 +260,7 @@ func TestAcc_ClusterWithStaticIP(t *testing.T) {
resource.TestCheckResourceAttr("qovery_cluster.test", "instance_type", "T3A_MEDIUM"),
resource.TestCheckResourceAttr("qovery_cluster.test", "min_running_nodes", "3"),
resource.TestCheckResourceAttr("qovery_cluster.test", "max_running_nodes", "10"),
resource.TestCheckResourceAttr("qovery_cluster.test", "production", "false"),
resource.TestCheckResourceAttr("qovery_cluster.test", "features.static_ip", "true"),
resource.TestCheckResourceAttr("qovery_cluster.test", "state", "DEPLOYED"),
),
Expand Down Expand Up @@ -347,7 +355,7 @@ resource "qovery_cluster" "test" {
)
}

func testAccClusterDefaultK3SConfig(testName string, cloudProvider string, region string, instanceType string) string {
func testAccClusterDefaultK3SConfig(testName string, cloudProvider string, region string, instanceType string, production bool) string {
return fmt.Sprintf(`
resource "qovery_cluster" "test" {
credentials_id = "%s"
Expand All @@ -359,8 +367,9 @@ resource "qovery_cluster" "test" {
kubernetes_mode = "K3S"
min_running_nodes = 1
max_running_nodes = 1
production = %t
}
`, getTestAWSCredentialsID(), getTestOrganizationID(), generateTestName(testName), cloudProvider, region, instanceType,
`, getTestAWSCredentialsID(), getTestOrganizationID(), generateTestName(testName), cloudProvider, region, instanceType, production,
)
}

Expand Down

0 comments on commit 2107a03

Please sign in to comment.