Skip to content

Commit

Permalink
Add fleet_workspace parameter
Browse files Browse the repository at this point in the history
This closes rancher/rancher rancher#502 by adding a new parameter that allows
setting of the FleetWorkspaceName value.

Signed-off-by: Stephen Gran <[email protected]>
  • Loading branch information
Stephen Gran committed Jul 15, 2021
1 parent c624906 commit 6e2c0da
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
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)


#### `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",
Description: "Fleet Workspace for Cluster",
ForceNew: false,
},
}

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
}

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

0 comments on commit 6e2c0da

Please sign in to comment.