diff --git a/kubernetes/resource_kubernetes_persistent_volume.go b/kubernetes/resource_kubernetes_persistent_volume.go index 36c72f4ae4..4ec06db09b 100644 --- a/kubernetes/resource_kubernetes_persistent_volume.go +++ b/kubernetes/resource_kubernetes_persistent_volume.go @@ -60,6 +60,11 @@ func resourceKubernetesPersistentVolume() *schema.Resource { MaxItems: 1, Elem: persistentVolumeSourceSchema(), }, + "storage_class_name": { + Type: schema.TypeString, + Description: "A description of the persistent volume's class. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class", + Optional: true, + }, }, }, }, diff --git a/kubernetes/structure_persistent_volume_spec.go b/kubernetes/structure_persistent_volume_spec.go index f5463d2ac6..370d7ed288 100644 --- a/kubernetes/structure_persistent_volume_spec.go +++ b/kubernetes/structure_persistent_volume_spec.go @@ -259,6 +259,9 @@ func flattenPersistentVolumeSpec(in v1.PersistentVolumeSpec) []interface{} { if in.PersistentVolumeReclaimPolicy != "" { att["persistent_volume_reclaim_policy"] = in.PersistentVolumeReclaimPolicy } + if in.StorageClassName != "" { + att["storage_class_name"] = in.StorageClassName + } return []interface{}{att} } @@ -653,6 +656,9 @@ func expandPersistentVolumeSpec(l []interface{}) (v1.PersistentVolumeSpec, error if v, ok := in["persistent_volume_reclaim_policy"].(string); ok { obj.PersistentVolumeReclaimPolicy = v1.PersistentVolumeReclaimPolicy(v) } + if v, ok := in["storage_class_name"].(string); ok { + obj.StorageClassName = v + } return obj, nil } @@ -773,6 +779,13 @@ func patchPersistentVolumeSpec(pathPrefix, prefix string, d *schema.ResourceData Value: v1.PersistentVolumeReclaimPolicy(v), }) } + if d.HasChange(prefix + "storage_class_name") { + v := d.Get(prefix + "storage_class_name").(string) + ops = append(ops, &ReplaceOperation{ + Path: pathPrefix + "/storageClassName", + Value: v1.StorageClassName(v), + }) + } return ops, nil } diff --git a/vendor/k8s.io/kubernetes/pkg/api/v1/types.go b/vendor/k8s.io/kubernetes/pkg/api/v1/types.go index a75a1d0f06..4158a664b1 100644 --- a/vendor/k8s.io/kubernetes/pkg/api/v1/types.go +++ b/vendor/k8s.io/kubernetes/pkg/api/v1/types.go @@ -498,6 +498,9 @@ type PersistentVolumeSpec struct { // PersistentVolumeReclaimPolicy describes a policy for end-of-life maintenance of persistent volumes. type PersistentVolumeReclaimPolicy string +// Name of StorageClass to which this persistent volume belongs. +type StorageClassName string + const ( // PersistentVolumeReclaimRecycle means the volume will be recycled back into the pool of unbound persistent volumes on release from its claim. // The volume plugin must support Recycling. diff --git a/website/docs/r/persistent_volume.html.markdown b/website/docs/r/persistent_volume.html.markdown index 016333c43e..31f4b9fefb 100644 --- a/website/docs/r/persistent_volume.html.markdown +++ b/website/docs/r/persistent_volume.html.markdown @@ -29,6 +29,7 @@ resource "kubernetes_persistent_volume" "example" { volume_path = "/absolute/path" } } + storage_class_name = "standard" } } ``` @@ -50,6 +51,7 @@ The following arguments are supported: * `capacity` - (Required) A description of the persistent volume's resources and capacity. More info: http://kubernetes.io/docs/user-guide/persistent-volumes#capacity * `persistent_volume_reclaim_policy` - (Optional) What happens to a persistent volume when released from its claim. Valid options are Retain (default) and Recycle. Recycling must be supported by the volume plugin underlying this persistent volume. More info: http://kubernetes.io/docs/user-guide/persistent-volumes#recycling-policy * `persistent_volume_source` - (Required) The specification of a persistent volume. +* `storage_class_name` - (Optional) A description of the persistent volume's class. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#class ### `persistent_volume_source`