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 fleet_workspace parameter #702

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ The following arguments are supported:
* `annotations` - (Optional/Computed) Annotations for the Cluster (map)
* `labels` - (Optional/Computed) Labels for the Cluster (map)
* `windows_prefered_cluster` - (Optional) Windows preferred cluster. Default: `false` (bool)
* `fleet_workspace` - (Optional/Computed) Fleet Workspace for the Cluster (string)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field is just available on rancher v2.5.x or above. It should be commented at docs.



#### `schedule_config`
Expand Down
1 change: 1 addition & 0 deletions rancher2/resource_rancher2_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const (
resource "` + testAccRancher2ClusterType + `" "foo" {
name = "foo"
description = "Terraform custom cluster acceptance test"
fleet_workspace = "fleet-custom"
rke_config {
network {
plugin = "canal"
Expand Down
7 changes: 7 additions & 0 deletions rancher2/schema_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,13 @@ func clusterFields() map[string]*schema.Schema {
Description: "Windows preferred cluster",
ForceNew: true,
},
"fleet_workspace": {
Type: schema.TypeString,
Optional: true,
Default: "fleet-default",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to fleet_workspace is a new argument on rancher2_cluster, i think'd be more secure for tfp upgrade, set this argument as Computed: true and removing default value.

Description: "Fleet Workspace for Cluster",
ForceNew: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default ForceNew is false, not required.

},
}

for k, v := range commonAnnotationLabelFields() {
Expand Down
8 changes: 8 additions & 0 deletions rancher2/structure_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@ func flattenCluster(d *schema.ResourceData, in *Cluster, clusterRegToken *manage
}

d.Set("windows_prefered_cluster", in.WindowsPreferedCluster)
err = d.Set("fleet_workspace", in.FleetWorkspaceName)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For setting string arguments, not required to check for error.

+	d.Set("fleet_workspace", in.FleetWorkspaceName)
-	err = d.Set("fleet_workspace", in.FleetWorkspaceName)
-	if err != nil {
-		return err
-	}


return nil
}
Expand Down Expand Up @@ -544,5 +548,9 @@ func expandCluster(in *schema.ResourceData) (*Cluster, error) {
obj.WindowsPreferedCluster = v
}

if v, ok := in.Get("fleet_workspace").(string); ok {
obj.FleetWorkspaceName = v
}

return obj, nil
}
20 changes: 20 additions & 0 deletions rancher2/structure_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func testCluster() {
}
testClusterConfAKS.Name = "test"
testClusterConfAKS.Description = "description"
testClusterConfAKS.FleetWorkspaceName = "fleet-custom"
testClusterConfAKS.Driver = clusterDriverAKS
testClusterConfAKS.AgentEnvVars = testClusterEnvVarsConf
testClusterConfAKS.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -241,12 +242,14 @@ func testCluster() {
"driver": clusterDriverAKS,
"aks_config": testClusterAKSConfigInterface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfEKS = &Cluster{
AmazonElasticContainerServiceConfig: testClusterEKSConfigConf,
}
testClusterConfEKS.Name = "test"
testClusterConfEKS.Description = "description"
testClusterConfEKS.FleetWorkspaceName = "fleet-custom"
testClusterConfEKS.Driver = clusterDriverEKS
testClusterConfEKS.AgentEnvVars = testClusterEnvVarsConf
testClusterConfEKS.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -268,11 +271,13 @@ func testCluster() {
"driver": clusterDriverEKS,
"eks_config": testClusterEKSConfigInterface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfEKSV2 = &Cluster{}
testClusterConfEKSV2.EKSConfig = testClusterEKSConfigV2Conf
testClusterConfEKSV2.Name = "test"
testClusterConfEKSV2.Description = "description"
testClusterConfEKSV2.FleetWorkspaceName = "fleet-custom"
testClusterConfEKSV2.Driver = clusterDriverEKSV2
testClusterConfEKSV2.AgentEnvVars = testClusterEnvVarsConf
testClusterConfEKSV2.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -294,12 +299,14 @@ func testCluster() {
"driver": clusterDriverEKSV2,
"eks_config_v2": testClusterEKSConfigV2Interface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfGKE = &Cluster{
GoogleKubernetesEngineConfig: testClusterGKEConfigConf,
}
testClusterConfGKE.Name = "test"
testClusterConfGKE.Description = "description"
testClusterConfGKE.FleetWorkspaceName = "fleet-custom"
testClusterConfGKE.Driver = clusterDriverGKE
testClusterConfGKE.AgentEnvVars = testClusterEnvVarsConf
testClusterConfGKE.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -321,10 +328,12 @@ func testCluster() {
"driver": clusterDriverGKE,
"gke_config": testClusterGKEConfigInterface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfK3S = &Cluster{}
testClusterConfK3S.Name = "test"
testClusterConfK3S.Description = "description"
testClusterConfK3S.FleetWorkspaceName = "fleet-custom"
testClusterConfK3S.K3sConfig = testClusterK3SConfigConf
testClusterConfK3S.Driver = clusterDriverK3S
testClusterConfK3S.AgentEnvVars = testClusterEnvVarsConf
Expand All @@ -350,11 +359,13 @@ func testCluster() {
"scheduled_cluster_scan": testClusterScheduledClusterScanInterface,
"system_project_id": "system_project_id",
"windows_prefered_cluster": false,
"fleet_workspace": "fleet-custom",
}
testClusterConfGKEV2 = &Cluster{}
testClusterConfGKEV2.GKEConfig = testClusterGKEConfigV2Conf
testClusterConfGKEV2.Name = "test"
testClusterConfGKEV2.Description = "description"
testClusterConfGKEV2.FleetWorkspaceName = "fleet-custom"
testClusterConfGKEV2.Driver = clusterDriverGKEV2
testClusterConfGKEV2.AgentEnvVars = testClusterEnvVarsConf
testClusterConfGKEV2.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -376,12 +387,14 @@ func testCluster() {
"driver": clusterDriverGKEV2,
"gke_config_v2": testClusterGKEConfigV2Interface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfOKE = &Cluster{
OracleKubernetesEngineConfig: testClusterOKEConfigConf,
}
testClusterConfOKE.Name = "test"
testClusterConfOKE.Description = "description"
testClusterConfOKE.FleetWorkspaceName = "fleet-custom"
testClusterConfOKE.Driver = clusterOKEKind
testClusterConfOKE.AgentEnvVars = testClusterEnvVarsConf
testClusterConfOKE.DefaultPodSecurityPolicyTemplateID = "restricted"
Expand All @@ -403,10 +416,12 @@ func testCluster() {
"driver": clusterOKEKind,
"oke_config": testClusterOKEConfigInterface,
"system_project_id": "system_project_id",
"fleet_workspace": "fleet-custom",
}
testClusterConfRKE = &Cluster{}
testClusterConfRKE.Name = "test"
testClusterConfRKE.Description = "description"
testClusterConfRKE.FleetWorkspaceName = "fleet-custom"
testClusterConfRKE.RancherKubernetesEngineConfig = testClusterRKEConfigConf
testClusterConfRKE.Driver = clusterDriverRKE
testClusterConfRKE.AgentEnvVars = testClusterEnvVarsConf
Expand All @@ -432,10 +447,12 @@ func testCluster() {
"scheduled_cluster_scan": testClusterScheduledClusterScanInterface,
"system_project_id": "system_project_id",
"windows_prefered_cluster": false,
"fleet_workspace": "fleet-custom",
}
testClusterConfRKE2 = &Cluster{}
testClusterConfRKE2.Name = "test"
testClusterConfRKE2.Description = "description"
testClusterConfRKE2.FleetWorkspaceName = "fleet-custom"
testClusterConfRKE2.Rke2Config = testClusterRKE2ConfigConf
testClusterConfRKE2.Driver = clusterDriverRKE2
testClusterConfRKE2.AgentEnvVars = testClusterEnvVarsConf
Expand All @@ -461,10 +478,12 @@ func testCluster() {
"scheduled_cluster_scan": testClusterScheduledClusterScanInterface,
"system_project_id": "system_project_id",
"windows_prefered_cluster": false,
"fleet_workspace": "fleet-custom",
}
testClusterConfTemplate = &Cluster{}
testClusterConfTemplate.Name = "test"
testClusterConfTemplate.Description = "description"
testClusterConfTemplate.FleetWorkspaceName = "fleet-custom"
testClusterConfTemplate.ClusterTemplateAnswers = testClusterAnswersConf
testClusterConfTemplate.ClusterTemplateID = "cluster_template_id"
testClusterConfTemplate.ClusterTemplateQuestions = testClusterQuestionsConf
Expand Down Expand Up @@ -499,6 +518,7 @@ func testCluster() {
"scheduled_cluster_scan": testClusterScheduledClusterScanInterface,
"system_project_id": "system_project_id",
"windows_prefered_cluster": false,
"fleet_workspace": "fleet-custom",
}
}

Expand Down