Skip to content

Commit 9f7577f

Browse files
simplify data_source schema
1 parent fadf044 commit 9f7577f

4 files changed

+17
-45
lines changed

docs/resources/persistent_volume_claim_v1.md

+2-12
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,7 @@ Optional:
7171
### Nested Schema for `spec.data_source`
7272

7373
Optional:
74-
75-
- `persistent_volume_claim` (Block List, Max: 1) Details of the source PersistentVolumeClaim. (see [below for nested schema](#nestedblock--spec--data_source--persistent_volume_claim))
76-
77-
<a id="nestedblock--spec--data_source--persistent_volume_claim"></a>
78-
### Nested Schema for `spec.data_source.persistent_volume_claim`
79-
80-
Required:
81-
82-
- `claim_name` (String) The name of the source PersistentVolumeClaim.
74+
- `name` (String) The name of the source PersistentVolumeClaim.
8375

8476
<a id="nestedblock--spec--selector"></a>
8577
### Nested Schema for `spec.selector`
@@ -158,9 +150,7 @@ resource "kubernetes_persistent_volume_claim_v1" "example_clone" {
158150
}
159151
}
160152
data_source {
161-
persistent_volume_claim {
162-
claim_name = "example-source-pvc"
163-
}
153+
name = "example-source-pvc"
164154
}
165155
}
166156
}

kubernetes/resource_kubernetes_persistent_volume_claim_v1_test.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ func TestAccKubernetesPersistentVolumeClaimV1_dataSource(t *testing.T) {
589589
Check: resource.ComposeAggregateTestCheckFunc(
590590
testAccCheckKubernetesPersistentVolumeClaimV1Exists(resourceName, &conf),
591591
resource.TestCheckResourceAttr(resourceName, "metadata.0.name", clonedPVC),
592-
resource.TestCheckResourceAttr(resourceName, "spec.0.data_source.0.persistent_volume_claim.0.claim_name", originalPVC),
592+
resource.TestCheckResourceAttr(resourceName, "spec.0.data_source.0.name", originalPVC),
593593
),
594594
},
595595
},
@@ -1055,9 +1055,7 @@ func testAccKubernetesPersistentVolumeClaimV1Config_dataSourceClone(sourceName,
10551055
}
10561056
10571057
data_source {
1058-
persistent_volume_claim {
1059-
claim_name = "%s"
1060-
}
1058+
name = "%s"
10611059
}
10621060
}
10631061

kubernetes/schema_persistent_volume_claim.go

+3-13
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,10 @@ func persistentVolumeClaimSpecFields() map[string]*schema.Schema {
7373
MaxItems: 1,
7474
Elem: &schema.Resource{
7575
Schema: map[string]*schema.Schema{
76-
"persistent_volume_claim": {
77-
Type: schema.TypeList,
78-
Description: "Details of the source PersistentVolumeClaim.",
76+
"name": {
77+
Type: schema.TypeString,
78+
Description: "The name of the source PersistentVolumeClaim.",
7979
Required: true,
80-
MaxItems: 1,
81-
Elem: &schema.Resource{
82-
Schema: map[string]*schema.Schema{
83-
"claim_name": {
84-
Type: schema.TypeString,
85-
Description: "The name of the source PersistentVolumeClaim.",
86-
Required: true,
87-
},
88-
},
89-
},
9080
},
9181
},
9282
},

kubernetes/structure_persistent_volume_claim.go

+10-16
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,12 @@ func flattenPersistentVolumeClaimSpec(in corev1.PersistentVolumeClaimSpec) []int
2929
if in.VolumeMode != nil {
3030
att["volume_mode"] = in.VolumeMode
3131
}
32-
if in.DataSource != nil {
33-
dataSource := make(map[string]interface{})
34-
if in.DataSource.Kind == "PersistentVolumeClaim" && in.DataSource.Name != "" {
35-
dataSource["persistent_volume_claim"] = []interface{}{
36-
map[string]interface{}{
37-
"claim_name": in.DataSource.Name,
38-
},
39-
}
32+
if in.DataSource != nil && in.DataSource.Name != "" {
33+
att["data_source"] = []interface{}{
34+
map[string]interface{}{
35+
"name": in.DataSource.Name,
36+
},
4037
}
41-
att["data_source"] = []interface{}{dataSource}
4238
}
4339
return []interface{}{att}
4440
}
@@ -104,13 +100,11 @@ func expandPersistentVolumeClaimSpec(l []interface{}) (*corev1.PersistentVolumeC
104100
}
105101
if v, ok := in["data_source"].([]interface{}); ok && len(v) > 0 && v[0] != nil {
106102
dataSource := v[0].(map[string]interface{})
107-
if pvcSource, ok := dataSource["persistent_volume_claim"].([]interface{}); ok && len(pvcSource) > 0 && pvcSource[0] != nil {
108-
pvcData := pvcSource[0].(map[string]interface{})
109-
if claimName, ok := pvcData["claim_name"].(string); ok && claimName != "" {
110-
obj.DataSource = &corev1.TypedLocalObjectReference{
111-
Kind: "PersistentVolumeClaim",
112-
Name: claimName,
113-
}
103+
if name, ok := dataSource["name"].(string); ok && name != "" {
104+
obj.DataSource = &corev1.TypedLocalObjectReference{
105+
Kind: "PersistentVolumeClaim",
106+
Name: name,
107+
APIGroup: ptr.To(""),
114108
}
115109
}
116110
}

0 commit comments

Comments
 (0)