Skip to content

Commit

Permalink
feature: output workload prefixed attributes
Browse files Browse the repository at this point in the history
Fix #27761.
  • Loading branch information
sheeeng committed Oct 25, 2024
1 parent a9f1b17 commit b46e752
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
45 changes: 45 additions & 0 deletions internal/services/containers/kubernetes_cluster_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,28 @@ func dataSourceKubernetesCluster() *pluginsdk.Resource {
},
},

"workload_autoscaler_profile": {
Type: pluginsdk.TypeList,
Computed: true,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
keda_enabled: {

Check failure on line 722 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: keda_enabled

Check failure on line 722 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: keda_enabled

Check failure on line 722 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: keda_enabled
Type: pluginsdk.TypeBool,
Computed: true,
},
vertical_pod_autoscaler_enabled : {

Check failure on line 726 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: vertical_pod_autoscaler_enabled

Check failure on line 726 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: vertical_pod_autoscaler_enabled

Check failure on line 726 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: vertical_pod_autoscaler_enabled
Type: pluginsdk.TypeBool,
Computed: true,
},
},
},
},

"workload_autoscaler_enabled": {
Type: pluginsdk.TypeBool,
Computed: true,
},

"tags": commonschema.TagsDataSource(),
},
}
Expand Down Expand Up @@ -973,6 +995,16 @@ func dataSourceKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{}
return fmt.Errorf("setting `kube_config`: %+v", err)
}

workloadAutoscalerProfile := flattenKubernetesClusterDataSourceWorkloadAutoscalerProfile(props.WorkloadAutoscalerProfile)

Check failure on line 998 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: props

Check failure on line 998 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: props

Check failure on line 998 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: props
if err := d.Set("workload_autoscaler_profile", workloadAutoscalerProfile); err != nil {
return fmt.Errorf("setting `workload_autoscaler_profile`: %+v", err)
}

workloadAutoscalerEnabled := false

Check failure on line 1003 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

workloadAutoscalerEnabled declared and not used

Check failure on line 1003 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

workloadAutoscalerEnabled declared and not used

Check failure on line 1003 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

workloadAutoscalerEnabled declared and not used
if props.WorkloadIdentity != nil {

Check failure on line 1004 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: props

Check failure on line 1004 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: props

Check failure on line 1004 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: props
workloadAutoscalerEnabled = *props.WorkloadIdentity

Check failure on line 1005 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: props

Check failure on line 1005 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: props

Check failure on line 1005 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: props
}

d.Set("tags", tags.Flatten(model.Tags))
}

Expand Down Expand Up @@ -1561,3 +1593,16 @@ func flattenKubernetesClusterDataSourceUpgradeSettings(input *managedclusters.Ag

return []interface{}{values}
}

func flattenKubernetesClusterDataSourceWorkloadAutoscalerProfile(input *managedclusters.ManagedClusterPropertiesWorkloadAutoscalerProfile) []interface{} {

Check failure on line 1597 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: managedclusters.ManagedClusterPropertiesWorkloadAutoscalerProfile

Check failure on line 1597 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: managedclusters.ManagedClusterPropertiesWorkloadAutoscalerProfile

Check failure on line 1597 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: managedclusters.ManagedClusterPropertiesWorkloadAutoscalerProfile

Check failure on line 1597 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: managedclusters.ManagedClusterPropertiesWorkloadAutoscalerProfile
values := make(map[string]interface{})

if input == nil {
return []interface{}{values}
}

values[keda_enabled] = input.KedaEnabled

Check failure on line 1604 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: keda_enabled

Check failure on line 1604 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: keda_enabled

Check failure on line 1604 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: keda_enabled
values[vertical_pod_autoscaler_enabled] = input.VerticalPodAutoscalerEnabled

Check failure on line 1605 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / document-lint

undefined: vertical_pod_autoscaler_enabled

Check failure on line 1605 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / tflint

undefined: vertical_pod_autoscaler_enabled

Check failure on line 1605 in internal/services/containers/kubernetes_cluster_data_source.go

View workflow job for this annotation

GitHub Actions / compatibility-32bit-test

undefined: vertical_pod_autoscaler_enabled

return []interface{}{values}
}
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,42 @@ func TestAccDataSourceKubernetesCluster_serviceMeshRevisions(t *testing.T) {
})
}

func TestFlattenKubernetesClusterDataSourceWorkloadAutoscalerProfile(t *testing.T) {
input := &containerservice.ManagedClusterPropertiesWorkloadAutoscalerProfile{
KedaEnabled: to.BoolPtr(true),
VerticalPodAutoscalerEnabled: to.BoolPtr(false),
}

expected := []interface{}{
map[string]interface{}{
"keda_enabled": true,
"vertical_pod_autoscaler_enabled": false,
},
}

output := flattenKubernetesClusterDataSourceWorkloadAutoscalerProfile(input)
assert.Equal(t, expected, output)
}

func TestFlattenKubernetesClusterDataSourceWorkloadAutoscalerProfile_WorkflowIdentityEnabled(t *testing.T) {
input := &containerservice.ManagedClusterPropertiesWorkloadAutoscalerProfile{
WorkflowIdentityEnabled: to.BoolPtr(true),
}

expected := []interface{}{
map[string]interface{}{
"workflow_identity_enabled": true,
},
}

output := flattenKubernetesClusterDataSourceWorkloadAutoscalerProfile(input)
assert.Equal(t, expected, output)
}

func to.BoolPtr(value bool) *bool {

Check failure on line 713 in internal/services/containers/kubernetes_cluster_data_source_test.go

View workflow job for this annotation

GitHub Actions / test

expected '(', found '.'
return &value
}

func (KubernetesClusterDataSource) basicConfig(data acceptance.TestData) string {
return fmt.Sprintf(`
%s
Expand Down

0 comments on commit b46e752

Please sign in to comment.