github.com/nathanielks/terraform@v0.6.1-0.20170509030759-13e1a62319dc/builtin/providers/kubernetes/structure_persistent_volume_spec.go (about)

     1  package kubernetes
     2  
     3  import (
     4  	"k8s.io/kubernetes/pkg/api/v1"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  // Flatteners
    10  
    11  func flattenAWSElasticBlockStoreVolumeSource(in *v1.AWSElasticBlockStoreVolumeSource) []interface{} {
    12  	att := make(map[string]interface{})
    13  	att["volume_id"] = in.VolumeID
    14  	if in.FSType != "" {
    15  		att["fs_type"] = in.FSType
    16  	}
    17  	if in.Partition != 0 {
    18  		att["partition"] = in.Partition
    19  	}
    20  	if in.ReadOnly != false {
    21  		att["read_only"] = in.ReadOnly
    22  	}
    23  	return []interface{}{att}
    24  }
    25  
    26  func flattenAzureDiskVolumeSource(in *v1.AzureDiskVolumeSource) []interface{} {
    27  	att := make(map[string]interface{})
    28  	att["disk_name"] = in.DiskName
    29  	att["data_disk_uri"] = in.DataDiskURI
    30  	att["caching_mode"] = string(*in.CachingMode)
    31  	if in.FSType != nil {
    32  		att["fs_type"] = *in.FSType
    33  	}
    34  	if in.ReadOnly != nil {
    35  		att["read_only"] = *in.ReadOnly
    36  	}
    37  	return []interface{}{att}
    38  }
    39  
    40  func flattenAzureFileVolumeSource(in *v1.AzureFileVolumeSource) []interface{} {
    41  	att := make(map[string]interface{})
    42  	att["secret_name"] = in.SecretName
    43  	att["share_name"] = in.ShareName
    44  	if in.ReadOnly != false {
    45  		att["read_only"] = in.ReadOnly
    46  	}
    47  	return []interface{}{att}
    48  }
    49  
    50  func flattenCephFSVolumeSource(in *v1.CephFSVolumeSource) []interface{} {
    51  	att := make(map[string]interface{})
    52  	att["monitors"] = newStringSet(schema.HashString, in.Monitors)
    53  	if in.Path != "" {
    54  		att["path"] = in.Path
    55  	}
    56  	if in.User != "" {
    57  		att["user"] = in.User
    58  	}
    59  	if in.SecretFile != "" {
    60  		att["secret_file"] = in.SecretFile
    61  	}
    62  	if in.SecretRef != nil {
    63  		att["secret_ref"] = flattenLocalObjectReference(in.SecretRef)
    64  	}
    65  	if in.ReadOnly != false {
    66  		att["read_only"] = in.ReadOnly
    67  	}
    68  	return []interface{}{att}
    69  }
    70  
    71  func flattenCinderVolumeSource(in *v1.CinderVolumeSource) []interface{} {
    72  	att := make(map[string]interface{})
    73  	att["volume_id"] = in.VolumeID
    74  	if in.FSType != "" {
    75  		att["fs_type"] = in.FSType
    76  	}
    77  	if in.ReadOnly != false {
    78  		att["read_only"] = in.ReadOnly
    79  	}
    80  	return []interface{}{att}
    81  }
    82  
    83  func flattenFCVolumeSource(in *v1.FCVolumeSource) []interface{} {
    84  	att := make(map[string]interface{})
    85  	att["target_ww_ns"] = newStringSet(schema.HashString, in.TargetWWNs)
    86  	att["lun"] = *in.Lun
    87  	if in.FSType != "" {
    88  		att["fs_type"] = in.FSType
    89  	}
    90  	if in.ReadOnly != false {
    91  		att["read_only"] = in.ReadOnly
    92  	}
    93  	return []interface{}{att}
    94  }
    95  
    96  func flattenFlexVolumeSource(in *v1.FlexVolumeSource) []interface{} {
    97  	att := make(map[string]interface{})
    98  	att["driver"] = in.Driver
    99  	if in.FSType != "" {
   100  		att["fs_type"] = in.FSType
   101  	}
   102  	if in.SecretRef != nil {
   103  		att["secret_ref"] = flattenLocalObjectReference(in.SecretRef)
   104  	}
   105  	if in.ReadOnly != false {
   106  		att["read_only"] = in.ReadOnly
   107  	}
   108  	if len(in.Options) > 0 {
   109  		att["options"] = in.Options
   110  	}
   111  	return []interface{}{att}
   112  }
   113  
   114  func flattenFlockerVolumeSource(in *v1.FlockerVolumeSource) []interface{} {
   115  	att := make(map[string]interface{})
   116  	att["dataset_name"] = in.DatasetName
   117  	att["dataset_uuid"] = in.DatasetUUID
   118  	return []interface{}{att}
   119  }
   120  
   121  func flattenGCEPersistentDiskVolumeSource(in *v1.GCEPersistentDiskVolumeSource) []interface{} {
   122  	att := make(map[string]interface{})
   123  	att["pd_name"] = in.PDName
   124  	if in.FSType != "" {
   125  		att["fs_type"] = in.FSType
   126  	}
   127  	if in.Partition != 0 {
   128  		att["partition"] = in.Partition
   129  	}
   130  	if in.ReadOnly != false {
   131  		att["read_only"] = in.ReadOnly
   132  	}
   133  	return []interface{}{att}
   134  }
   135  
   136  func flattenGlusterfsVolumeSource(in *v1.GlusterfsVolumeSource) []interface{} {
   137  	att := make(map[string]interface{})
   138  	att["endpoints_name"] = in.EndpointsName
   139  	att["path"] = in.Path
   140  	if in.ReadOnly != false {
   141  		att["read_only"] = in.ReadOnly
   142  	}
   143  	return []interface{}{att}
   144  }
   145  
   146  func flattenHostPathVolumeSource(in *v1.HostPathVolumeSource) []interface{} {
   147  	att := make(map[string]interface{})
   148  	att["path"] = in.Path
   149  	return []interface{}{att}
   150  }
   151  
   152  func flattenISCSIVolumeSource(in *v1.ISCSIVolumeSource) []interface{} {
   153  	att := make(map[string]interface{})
   154  	if in.TargetPortal != "" {
   155  		att["target_portal"] = in.TargetPortal
   156  	}
   157  	if in.IQN != "" {
   158  		att["iqn"] = in.IQN
   159  	}
   160  	if in.Lun != 0 {
   161  		att["lun"] = in.Lun
   162  	}
   163  	if in.ISCSIInterface != "" {
   164  		att["iscsi_interface"] = in.ISCSIInterface
   165  	}
   166  	if in.FSType != "" {
   167  		att["fs_type"] = in.FSType
   168  	}
   169  	if in.ReadOnly != false {
   170  		att["read_only"] = in.ReadOnly
   171  	}
   172  	return []interface{}{att}
   173  }
   174  
   175  func flattenLocalObjectReference(in *v1.LocalObjectReference) []interface{} {
   176  	att := make(map[string]interface{})
   177  	if in.Name != "" {
   178  		att["name"] = in.Name
   179  	}
   180  	return []interface{}{att}
   181  }
   182  
   183  func flattenNFSVolumeSource(in *v1.NFSVolumeSource) []interface{} {
   184  	att := make(map[string]interface{})
   185  	att["server"] = in.Server
   186  	att["path"] = in.Path
   187  	if in.ReadOnly != false {
   188  		att["read_only"] = in.ReadOnly
   189  	}
   190  	return []interface{}{att}
   191  }
   192  
   193  func flattenPersistentVolumeSource(in v1.PersistentVolumeSource) []interface{} {
   194  	att := make(map[string]interface{})
   195  	if in.GCEPersistentDisk != nil {
   196  		att["gce_persistent_disk"] = flattenGCEPersistentDiskVolumeSource(in.GCEPersistentDisk)
   197  	}
   198  	if in.AWSElasticBlockStore != nil {
   199  		att["aws_elastic_block_store"] = flattenAWSElasticBlockStoreVolumeSource(in.AWSElasticBlockStore)
   200  	}
   201  	if in.HostPath != nil {
   202  		att["host_path"] = flattenHostPathVolumeSource(in.HostPath)
   203  	}
   204  	if in.Glusterfs != nil {
   205  		att["glusterfs"] = flattenGlusterfsVolumeSource(in.Glusterfs)
   206  	}
   207  	if in.NFS != nil {
   208  		att["nfs"] = flattenNFSVolumeSource(in.NFS)
   209  	}
   210  	if in.RBD != nil {
   211  		att["rbd"] = flattenRBDVolumeSource(in.RBD)
   212  	}
   213  	if in.ISCSI != nil {
   214  		att["iscsi"] = flattenISCSIVolumeSource(in.ISCSI)
   215  	}
   216  	if in.Cinder != nil {
   217  		att["cinder"] = flattenCinderVolumeSource(in.Cinder)
   218  	}
   219  	if in.CephFS != nil {
   220  		att["ceph_fs"] = flattenCephFSVolumeSource(in.CephFS)
   221  	}
   222  	if in.FC != nil {
   223  		att["fc"] = flattenFCVolumeSource(in.FC)
   224  	}
   225  	if in.Flocker != nil {
   226  		att["flocker"] = flattenFlockerVolumeSource(in.Flocker)
   227  	}
   228  	if in.FlexVolume != nil {
   229  		att["flex_volume"] = flattenFlexVolumeSource(in.FlexVolume)
   230  	}
   231  	if in.AzureFile != nil {
   232  		att["azure_file"] = flattenAzureFileVolumeSource(in.AzureFile)
   233  	}
   234  	if in.VsphereVolume != nil {
   235  		att["vsphere_volume"] = flattenVsphereVirtualDiskVolumeSource(in.VsphereVolume)
   236  	}
   237  	if in.Quobyte != nil {
   238  		att["quobyte"] = flattenQuobyteVolumeSource(in.Quobyte)
   239  	}
   240  	if in.AzureDisk != nil {
   241  		att["azure_disk"] = flattenAzureDiskVolumeSource(in.AzureDisk)
   242  	}
   243  	if in.PhotonPersistentDisk != nil {
   244  		att["photon_persistent_disk"] = flattenPhotonPersistentDiskVolumeSource(in.PhotonPersistentDisk)
   245  	}
   246  	return []interface{}{att}
   247  }
   248  
   249  func flattenPersistentVolumeSpec(in v1.PersistentVolumeSpec) []interface{} {
   250  	att := make(map[string]interface{})
   251  	if len(in.Capacity) > 0 {
   252  		att["capacity"] = flattenResourceList(in.Capacity)
   253  	}
   254  
   255  	att["persistent_volume_source"] = flattenPersistentVolumeSource(in.PersistentVolumeSource)
   256  	if len(in.AccessModes) > 0 {
   257  		att["access_modes"] = flattenPersistentVolumeAccessModes(in.AccessModes)
   258  	}
   259  	if in.PersistentVolumeReclaimPolicy != "" {
   260  		att["persistent_volume_reclaim_policy"] = in.PersistentVolumeReclaimPolicy
   261  	}
   262  	return []interface{}{att}
   263  }
   264  
   265  func flattenPhotonPersistentDiskVolumeSource(in *v1.PhotonPersistentDiskVolumeSource) []interface{} {
   266  	att := make(map[string]interface{})
   267  	att["pd_id"] = in.PdID
   268  	if in.FSType != "" {
   269  		att["fs_type"] = in.FSType
   270  	}
   271  	return []interface{}{att}
   272  }
   273  
   274  func flattenQuobyteVolumeSource(in *v1.QuobyteVolumeSource) []interface{} {
   275  	att := make(map[string]interface{})
   276  	att["registry"] = in.Registry
   277  	att["volume"] = in.Volume
   278  	if in.ReadOnly != false {
   279  		att["read_only"] = in.ReadOnly
   280  	}
   281  	if in.User != "" {
   282  		att["user"] = in.User
   283  	}
   284  	if in.Group != "" {
   285  		att["group"] = in.Group
   286  	}
   287  	return []interface{}{att}
   288  }
   289  
   290  func flattenRBDVolumeSource(in *v1.RBDVolumeSource) []interface{} {
   291  	att := make(map[string]interface{})
   292  	att["ceph_monitors"] = newStringSet(schema.HashString, in.CephMonitors)
   293  	att["rbd_image"] = in.RBDImage
   294  	if in.FSType != "" {
   295  		att["fs_type"] = in.FSType
   296  	}
   297  	if in.RBDPool != "" {
   298  		att["rbd_pool"] = in.RBDPool
   299  	}
   300  	if in.RadosUser != "" {
   301  		att["rados_user"] = in.RadosUser
   302  	}
   303  	if in.Keyring != "" {
   304  		att["keyring"] = in.Keyring
   305  	}
   306  	if in.SecretRef != nil {
   307  		att["secret_ref"] = flattenLocalObjectReference(in.SecretRef)
   308  	}
   309  	if in.ReadOnly != false {
   310  		att["read_only"] = in.ReadOnly
   311  	}
   312  	return []interface{}{att}
   313  }
   314  
   315  func flattenVsphereVirtualDiskVolumeSource(in *v1.VsphereVirtualDiskVolumeSource) []interface{} {
   316  	att := make(map[string]interface{})
   317  	att["volume_path"] = in.VolumePath
   318  	if in.FSType != "" {
   319  		att["fs_type"] = in.FSType
   320  	}
   321  	return []interface{}{att}
   322  }
   323  
   324  // Expanders
   325  
   326  func expandAWSElasticBlockStoreVolumeSource(l []interface{}) *v1.AWSElasticBlockStoreVolumeSource {
   327  	if len(l) == 0 || l[0] == nil {
   328  		return &v1.AWSElasticBlockStoreVolumeSource{}
   329  	}
   330  	in := l[0].(map[string]interface{})
   331  	obj := &v1.AWSElasticBlockStoreVolumeSource{
   332  		VolumeID: in["volume_id"].(string),
   333  	}
   334  	if v, ok := in["fs_type"].(string); ok {
   335  		obj.FSType = v
   336  	}
   337  	if v, ok := in["partition"].(int); ok {
   338  		obj.Partition = int32(v)
   339  	}
   340  	if v, ok := in["read_only"].(bool); ok {
   341  		obj.ReadOnly = v
   342  	}
   343  	return obj
   344  }
   345  
   346  func expandAzureDiskVolumeSource(l []interface{}) *v1.AzureDiskVolumeSource {
   347  	if len(l) == 0 || l[0] == nil {
   348  		return &v1.AzureDiskVolumeSource{}
   349  	}
   350  	in := l[0].(map[string]interface{})
   351  	cachingMode := v1.AzureDataDiskCachingMode(in["caching_mode"].(string))
   352  	obj := &v1.AzureDiskVolumeSource{
   353  		CachingMode: &cachingMode,
   354  		DiskName:    in["disk_name"].(string),
   355  		DataDiskURI: in["data_disk_uri"].(string),
   356  	}
   357  	if v, ok := in["fs_type"].(string); ok {
   358  		obj.FSType = ptrToString(v)
   359  	}
   360  	if v, ok := in["read_only"].(bool); ok {
   361  		obj.ReadOnly = ptrToBool(v)
   362  	}
   363  	return obj
   364  }
   365  
   366  func expandAzureFileVolumeSource(l []interface{}) *v1.AzureFileVolumeSource {
   367  	if len(l) == 0 || l[0] == nil {
   368  		return &v1.AzureFileVolumeSource{}
   369  	}
   370  	in := l[0].(map[string]interface{})
   371  	obj := &v1.AzureFileVolumeSource{
   372  		SecretName: in["secret_name"].(string),
   373  		ShareName:  in["share_name"].(string),
   374  	}
   375  	if v, ok := in["read_only"].(bool); ok {
   376  		obj.ReadOnly = v
   377  	}
   378  	return obj
   379  }
   380  
   381  func expandCephFSVolumeSource(l []interface{}) *v1.CephFSVolumeSource {
   382  	if len(l) == 0 || l[0] == nil {
   383  		return &v1.CephFSVolumeSource{}
   384  	}
   385  	in := l[0].(map[string]interface{})
   386  	obj := &v1.CephFSVolumeSource{
   387  		Monitors: sliceOfString(in["monitors"].(*schema.Set).List()),
   388  	}
   389  	if v, ok := in["path"].(string); ok {
   390  		obj.Path = v
   391  	}
   392  	if v, ok := in["user"].(string); ok {
   393  		obj.User = v
   394  	}
   395  	if v, ok := in["secret_file"].(string); ok {
   396  		obj.SecretFile = v
   397  	}
   398  	if v, ok := in["secret_ref"].([]interface{}); ok && len(v) > 0 {
   399  		obj.SecretRef = expandLocalObjectReference(v)
   400  	}
   401  	if v, ok := in["read_only"].(bool); ok {
   402  		obj.ReadOnly = v
   403  	}
   404  	return obj
   405  }
   406  
   407  func expandCinderVolumeSource(l []interface{}) *v1.CinderVolumeSource {
   408  	if len(l) == 0 || l[0] == nil {
   409  		return &v1.CinderVolumeSource{}
   410  	}
   411  	in := l[0].(map[string]interface{})
   412  	obj := &v1.CinderVolumeSource{
   413  		VolumeID: in["volume_id"].(string),
   414  	}
   415  	if v, ok := in["fs_type"].(string); ok {
   416  		obj.FSType = v
   417  	}
   418  	if v, ok := in["read_only"].(bool); ok {
   419  		obj.ReadOnly = v
   420  	}
   421  	return obj
   422  }
   423  
   424  func expandFCVolumeSource(l []interface{}) *v1.FCVolumeSource {
   425  	if len(l) == 0 || l[0] == nil {
   426  		return &v1.FCVolumeSource{}
   427  	}
   428  	in := l[0].(map[string]interface{})
   429  	obj := &v1.FCVolumeSource{
   430  		TargetWWNs: sliceOfString(in["target_ww_ns"].(*schema.Set).List()),
   431  		Lun:        ptrToInt32(int32(in["lun"].(int))),
   432  	}
   433  	if v, ok := in["fs_type"].(string); ok {
   434  		obj.FSType = v
   435  	}
   436  	if v, ok := in["read_only"].(bool); ok {
   437  		obj.ReadOnly = v
   438  	}
   439  	return obj
   440  }
   441  
   442  func expandFlexVolumeSource(l []interface{}) *v1.FlexVolumeSource {
   443  	if len(l) == 0 || l[0] == nil {
   444  		return &v1.FlexVolumeSource{}
   445  	}
   446  	in := l[0].(map[string]interface{})
   447  	obj := &v1.FlexVolumeSource{
   448  		Driver: in["driver"].(string),
   449  	}
   450  	if v, ok := in["fs_type"].(string); ok {
   451  		obj.FSType = v
   452  	}
   453  	if v, ok := in["secret_ref"].([]interface{}); ok && len(v) > 0 {
   454  		obj.SecretRef = expandLocalObjectReference(v)
   455  	}
   456  	if v, ok := in["read_only"].(bool); ok {
   457  		obj.ReadOnly = v
   458  	}
   459  	if v, ok := in["options"].(map[string]interface{}); ok && len(v) > 0 {
   460  		obj.Options = expandStringMap(v)
   461  	}
   462  	return obj
   463  }
   464  
   465  func expandFlockerVolumeSource(l []interface{}) *v1.FlockerVolumeSource {
   466  	if len(l) == 0 || l[0] == nil {
   467  		return &v1.FlockerVolumeSource{}
   468  	}
   469  	in := l[0].(map[string]interface{})
   470  	obj := &v1.FlockerVolumeSource{
   471  		DatasetName: in["dataset_name"].(string),
   472  		DatasetUUID: in["dataset_uuid"].(string),
   473  	}
   474  	return obj
   475  }
   476  
   477  func expandGCEPersistentDiskVolumeSource(l []interface{}) *v1.GCEPersistentDiskVolumeSource {
   478  	if len(l) == 0 || l[0] == nil {
   479  		return &v1.GCEPersistentDiskVolumeSource{}
   480  	}
   481  	in := l[0].(map[string]interface{})
   482  	obj := &v1.GCEPersistentDiskVolumeSource{
   483  		PDName: in["pd_name"].(string),
   484  	}
   485  	if v, ok := in["fs_type"].(string); ok {
   486  		obj.FSType = v
   487  	}
   488  	if v, ok := in["partition"].(int); ok {
   489  		obj.Partition = int32(v)
   490  	}
   491  	if v, ok := in["read_only"].(bool); ok {
   492  		obj.ReadOnly = v
   493  	}
   494  	return obj
   495  }
   496  
   497  func expandGlusterfsVolumeSource(l []interface{}) *v1.GlusterfsVolumeSource {
   498  	if len(l) == 0 || l[0] == nil {
   499  		return &v1.GlusterfsVolumeSource{}
   500  	}
   501  	in := l[0].(map[string]interface{})
   502  	obj := &v1.GlusterfsVolumeSource{
   503  		EndpointsName: in["endpoints_name"].(string),
   504  		Path:          in["path"].(string),
   505  	}
   506  	if v, ok := in["read_only"].(bool); ok {
   507  		obj.ReadOnly = v
   508  	}
   509  	return obj
   510  }
   511  
   512  func expandHostPathVolumeSource(l []interface{}) *v1.HostPathVolumeSource {
   513  	if len(l) == 0 || l[0] == nil {
   514  		return &v1.HostPathVolumeSource{}
   515  	}
   516  	in := l[0].(map[string]interface{})
   517  	obj := &v1.HostPathVolumeSource{
   518  		Path: in["path"].(string),
   519  	}
   520  	return obj
   521  }
   522  
   523  func expandISCSIVolumeSource(l []interface{}) *v1.ISCSIVolumeSource {
   524  	if len(l) == 0 || l[0] == nil {
   525  		return &v1.ISCSIVolumeSource{}
   526  	}
   527  	in := l[0].(map[string]interface{})
   528  	obj := &v1.ISCSIVolumeSource{
   529  		TargetPortal: in["target_portal"].(string),
   530  		IQN:          in["iqn"].(string),
   531  	}
   532  	if v, ok := in["lun"].(int); ok {
   533  		obj.Lun = int32(v)
   534  	}
   535  	if v, ok := in["iscsi_interface"].(string); ok {
   536  		obj.ISCSIInterface = v
   537  	}
   538  	if v, ok := in["fs_type"].(string); ok {
   539  		obj.FSType = v
   540  	}
   541  	if v, ok := in["read_only"].(bool); ok {
   542  		obj.ReadOnly = v
   543  	}
   544  	return obj
   545  }
   546  
   547  func expandLocalObjectReference(l []interface{}) *v1.LocalObjectReference {
   548  	if len(l) == 0 || l[0] == nil {
   549  		return &v1.LocalObjectReference{}
   550  	}
   551  	in := l[0].(map[string]interface{})
   552  	obj := &v1.LocalObjectReference{}
   553  	if v, ok := in["name"].(string); ok {
   554  		obj.Name = v
   555  	}
   556  	return obj
   557  }
   558  
   559  func expandNFSVolumeSource(l []interface{}) *v1.NFSVolumeSource {
   560  	if len(l) == 0 || l[0] == nil {
   561  		return &v1.NFSVolumeSource{}
   562  	}
   563  	in := l[0].(map[string]interface{})
   564  	obj := &v1.NFSVolumeSource{
   565  		Server: in["server"].(string),
   566  		Path:   in["path"].(string),
   567  	}
   568  	if v, ok := in["read_only"].(bool); ok {
   569  		obj.ReadOnly = v
   570  	}
   571  	return obj
   572  }
   573  
   574  func expandPersistentVolumeSource(l []interface{}) v1.PersistentVolumeSource {
   575  	if len(l) == 0 || l[0] == nil {
   576  		return v1.PersistentVolumeSource{}
   577  	}
   578  	in := l[0].(map[string]interface{})
   579  	obj := v1.PersistentVolumeSource{}
   580  	if v, ok := in["gce_persistent_disk"].([]interface{}); ok && len(v) > 0 {
   581  		obj.GCEPersistentDisk = expandGCEPersistentDiskVolumeSource(v)
   582  	}
   583  	if v, ok := in["aws_elastic_block_store"].([]interface{}); ok && len(v) > 0 {
   584  		obj.AWSElasticBlockStore = expandAWSElasticBlockStoreVolumeSource(v)
   585  	}
   586  	if v, ok := in["host_path"].([]interface{}); ok && len(v) > 0 {
   587  		obj.HostPath = expandHostPathVolumeSource(v)
   588  	}
   589  	if v, ok := in["glusterfs"].([]interface{}); ok && len(v) > 0 {
   590  		obj.Glusterfs = expandGlusterfsVolumeSource(v)
   591  	}
   592  	if v, ok := in["nfs"].([]interface{}); ok && len(v) > 0 {
   593  		obj.NFS = expandNFSVolumeSource(v)
   594  	}
   595  	if v, ok := in["rbd"].([]interface{}); ok && len(v) > 0 {
   596  		obj.RBD = expandRBDVolumeSource(v)
   597  	}
   598  	if v, ok := in["iscsi"].([]interface{}); ok && len(v) > 0 {
   599  		obj.ISCSI = expandISCSIVolumeSource(v)
   600  	}
   601  	if v, ok := in["cinder"].([]interface{}); ok && len(v) > 0 {
   602  		obj.Cinder = expandCinderVolumeSource(v)
   603  	}
   604  	if v, ok := in["ceph_fs"].([]interface{}); ok && len(v) > 0 {
   605  		obj.CephFS = expandCephFSVolumeSource(v)
   606  	}
   607  	if v, ok := in["fc"].([]interface{}); ok && len(v) > 0 {
   608  		obj.FC = expandFCVolumeSource(v)
   609  	}
   610  	if v, ok := in["flocker"].([]interface{}); ok && len(v) > 0 {
   611  		obj.Flocker = expandFlockerVolumeSource(v)
   612  	}
   613  	if v, ok := in["flex_volume"].([]interface{}); ok && len(v) > 0 {
   614  		obj.FlexVolume = expandFlexVolumeSource(v)
   615  	}
   616  	if v, ok := in["azure_file"].([]interface{}); ok && len(v) > 0 {
   617  		obj.AzureFile = expandAzureFileVolumeSource(v)
   618  	}
   619  	if v, ok := in["vsphere_volume"].([]interface{}); ok && len(v) > 0 {
   620  		obj.VsphereVolume = expandVsphereVirtualDiskVolumeSource(v)
   621  	}
   622  	if v, ok := in["quobyte"].([]interface{}); ok && len(v) > 0 {
   623  		obj.Quobyte = expandQuobyteVolumeSource(v)
   624  	}
   625  	if v, ok := in["azure_disk"].([]interface{}); ok && len(v) > 0 {
   626  		obj.AzureDisk = expandAzureDiskVolumeSource(v)
   627  	}
   628  	if v, ok := in["photon_persistent_disk"].([]interface{}); ok && len(v) > 0 {
   629  		obj.PhotonPersistentDisk = expandPhotonPersistentDiskVolumeSource(v)
   630  	}
   631  	return obj
   632  }
   633  
   634  func expandPersistentVolumeSpec(l []interface{}) (v1.PersistentVolumeSpec, error) {
   635  	if len(l) == 0 || l[0] == nil {
   636  		return v1.PersistentVolumeSpec{}, nil
   637  	}
   638  	in := l[0].(map[string]interface{})
   639  	obj := v1.PersistentVolumeSpec{}
   640  	if v, ok := in["capacity"].(map[string]interface{}); ok && len(v) > 0 {
   641  		var err error
   642  		obj.Capacity, err = expandMapToResourceList(v)
   643  		if err != nil {
   644  			return obj, err
   645  		}
   646  	}
   647  	if v, ok := in["persistent_volume_source"].([]interface{}); ok && len(v) > 0 {
   648  		obj.PersistentVolumeSource = expandPersistentVolumeSource(v)
   649  	}
   650  	if v, ok := in["access_modes"].(*schema.Set); ok && v.Len() > 0 {
   651  		obj.AccessModes = expandPersistentVolumeAccessModes(v.List())
   652  	}
   653  	if v, ok := in["persistent_volume_reclaim_policy"].(string); ok {
   654  		obj.PersistentVolumeReclaimPolicy = v1.PersistentVolumeReclaimPolicy(v)
   655  	}
   656  	return obj, nil
   657  }
   658  
   659  func expandPhotonPersistentDiskVolumeSource(l []interface{}) *v1.PhotonPersistentDiskVolumeSource {
   660  	if len(l) == 0 || l[0] == nil {
   661  		return &v1.PhotonPersistentDiskVolumeSource{}
   662  	}
   663  	in := l[0].(map[string]interface{})
   664  	obj := &v1.PhotonPersistentDiskVolumeSource{
   665  		PdID: in["pd_id"].(string),
   666  	}
   667  	if v, ok := in["fs_type"].(string); ok {
   668  		obj.FSType = v
   669  	}
   670  	return obj
   671  }
   672  
   673  func expandQuobyteVolumeSource(l []interface{}) *v1.QuobyteVolumeSource {
   674  	if len(l) == 0 || l[0] == nil {
   675  		return &v1.QuobyteVolumeSource{}
   676  	}
   677  	in := l[0].(map[string]interface{})
   678  	obj := &v1.QuobyteVolumeSource{
   679  		Registry: in["registry"].(string),
   680  		Volume:   in["volume"].(string),
   681  	}
   682  	if v, ok := in["read_only"].(bool); ok {
   683  		obj.ReadOnly = v
   684  	}
   685  	if v, ok := in["user"].(string); ok {
   686  		obj.User = v
   687  	}
   688  	if v, ok := in["group"].(string); ok {
   689  		obj.Group = v
   690  	}
   691  	return obj
   692  }
   693  
   694  func expandRBDVolumeSource(l []interface{}) *v1.RBDVolumeSource {
   695  	if len(l) == 0 || l[0] == nil {
   696  		return &v1.RBDVolumeSource{}
   697  	}
   698  	in := l[0].(map[string]interface{})
   699  	obj := &v1.RBDVolumeSource{
   700  		CephMonitors: expandStringSlice(in["ceph_monitors"].(*schema.Set).List()),
   701  		RBDImage:     in["rbd_image"].(string),
   702  	}
   703  	if v, ok := in["fs_type"].(string); ok {
   704  		obj.FSType = v
   705  	}
   706  	if v, ok := in["rbd_pool"].(string); ok {
   707  		obj.RBDPool = v
   708  	}
   709  	if v, ok := in["rados_user"].(string); ok {
   710  		obj.RadosUser = v
   711  	}
   712  	if v, ok := in["keyring"].(string); ok {
   713  		obj.Keyring = v
   714  	}
   715  	if v, ok := in["secret_ref"].([]interface{}); ok && len(v) > 0 {
   716  		obj.SecretRef = expandLocalObjectReference(v)
   717  	}
   718  	if v, ok := in["read_only"].(bool); ok {
   719  		obj.ReadOnly = v
   720  	}
   721  	return obj
   722  }
   723  
   724  func expandVsphereVirtualDiskVolumeSource(l []interface{}) *v1.VsphereVirtualDiskVolumeSource {
   725  	if len(l) == 0 || l[0] == nil {
   726  		return &v1.VsphereVirtualDiskVolumeSource{}
   727  	}
   728  	in := l[0].(map[string]interface{})
   729  	obj := &v1.VsphereVirtualDiskVolumeSource{
   730  		VolumePath: in["volume_path"].(string),
   731  	}
   732  	if v, ok := in["fs_type"].(string); ok {
   733  		obj.FSType = v
   734  	}
   735  	return obj
   736  }
   737  
   738  func patchPersistentVolumeSpec(pathPrefix, prefix string, d *schema.ResourceData) (PatchOperations, error) {
   739  	ops := make([]PatchOperation, 0)
   740  	prefix += ".0."
   741  
   742  	if d.HasChange(prefix + "capacity") {
   743  		v := d.Get(prefix + "capacity").(map[string]interface{})
   744  		capacity, err := expandMapToResourceList(v)
   745  		if err != nil {
   746  			return ops, err
   747  		}
   748  		ops = append(ops, &ReplaceOperation{
   749  			Path:  pathPrefix + "/capacity",
   750  			Value: capacity,
   751  		})
   752  	}
   753  
   754  	if d.HasChange(prefix + "persistent_volume_source") {
   755  		ops = append(ops, patchPersistentVolumeSource(
   756  			pathPrefix,
   757  			prefix+"persistent_volume_source.0.",
   758  			d,
   759  		)...)
   760  	}
   761  
   762  	if d.HasChange(prefix + "access_modes") {
   763  		v := d.Get(prefix + "access_modes").(*schema.Set)
   764  		ops = append(ops, &ReplaceOperation{
   765  			Path:  pathPrefix + "/accessModes",
   766  			Value: expandPersistentVolumeAccessModes(v.List()),
   767  		})
   768  	}
   769  	if d.HasChange(prefix + "access_modes") {
   770  		v := d.Get(prefix + "persistent_volume_reclaim_policy").(string)
   771  		ops = append(ops, &ReplaceOperation{
   772  			Path:  pathPrefix + "/persistentVolumeReclaimPolicy",
   773  			Value: v1.PersistentVolumeReclaimPolicy(v),
   774  		})
   775  	}
   776  
   777  	return ops, nil
   778  }
   779  
   780  func patchPersistentVolumeSource(pathPrefix, prefix string, d *schema.ResourceData) []PatchOperation {
   781  	ops := make([]PatchOperation, 0)
   782  
   783  	if d.HasChange(prefix + "gce_persistent_disk") {
   784  		oldIn, newIn := d.GetChange(prefix + "gce_persistent_disk")
   785  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   786  			ops = append(ops, &ReplaceOperation{
   787  				Path:  pathPrefix + "/gcePersistentDisk",
   788  				Value: expandGCEPersistentDiskVolumeSource(v),
   789  			})
   790  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   791  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/gcePersistentDisk"})
   792  		}
   793  	}
   794  
   795  	if d.HasChange(prefix + "aws_elastic_block_store") {
   796  		oldIn, newIn := d.GetChange(prefix + "aws_elastic_block_store")
   797  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   798  			ops = append(ops, &ReplaceOperation{
   799  				Path:  pathPrefix + "/awsElasticBlockStore",
   800  				Value: expandAWSElasticBlockStoreVolumeSource(v),
   801  			})
   802  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   803  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/awsElasticBlockStore"})
   804  		}
   805  	}
   806  
   807  	if d.HasChange(prefix + "host_path") {
   808  		oldIn, newIn := d.GetChange(prefix + "host_path")
   809  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   810  			ops = append(ops, &ReplaceOperation{
   811  				Path:  pathPrefix + "/hostPath",
   812  				Value: expandHostPathVolumeSource(v),
   813  			})
   814  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   815  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/hostPath"})
   816  		}
   817  	}
   818  
   819  	if d.HasChange(prefix + "glusterfs") {
   820  		oldIn, newIn := d.GetChange(prefix + "glusterfs")
   821  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   822  			ops = append(ops, &ReplaceOperation{
   823  				Path:  pathPrefix + "/glusterfs",
   824  				Value: expandGlusterfsVolumeSource(v),
   825  			})
   826  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   827  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/glusterfs"})
   828  		}
   829  	}
   830  
   831  	if d.HasChange(prefix + "nfs") {
   832  		oldIn, newIn := d.GetChange(prefix + "nfs")
   833  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   834  			ops = append(ops, &ReplaceOperation{
   835  				Path:  pathPrefix + "/nfs",
   836  				Value: expandNFSVolumeSource(v),
   837  			})
   838  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   839  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/nfs"})
   840  		}
   841  	}
   842  
   843  	if d.HasChange(prefix + "rbd") {
   844  		oldIn, newIn := d.GetChange(prefix + "rbd")
   845  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   846  			ops = append(ops, &ReplaceOperation{
   847  				Path:  pathPrefix + "/rbd",
   848  				Value: expandRBDVolumeSource(v),
   849  			})
   850  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   851  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/rbd"})
   852  		}
   853  	}
   854  
   855  	if d.HasChange(prefix + "iscsi") {
   856  		oldIn, newIn := d.GetChange(prefix + "iscsi")
   857  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   858  			ops = append(ops, &ReplaceOperation{
   859  				Path:  pathPrefix + "/iscsi",
   860  				Value: expandISCSIVolumeSource(v),
   861  			})
   862  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   863  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/iscsi"})
   864  		}
   865  	}
   866  
   867  	if d.HasChange(prefix + "cinder") {
   868  		oldIn, newIn := d.GetChange(prefix + "cinder")
   869  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   870  			ops = append(ops, &ReplaceOperation{
   871  				Path:  pathPrefix + "/cinder",
   872  				Value: expandCinderVolumeSource(v),
   873  			})
   874  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   875  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/cinder"})
   876  		}
   877  	}
   878  
   879  	if d.HasChange(prefix + "ceph_fs") {
   880  		oldIn, newIn := d.GetChange(prefix + "ceph_fs")
   881  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   882  			ops = append(ops, &ReplaceOperation{
   883  				Path:  pathPrefix + "/cephfs",
   884  				Value: expandCephFSVolumeSource(v),
   885  			})
   886  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   887  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/cephfs"})
   888  		}
   889  	}
   890  
   891  	if d.HasChange(prefix + "fc") {
   892  		oldIn, newIn := d.GetChange(prefix + "fc")
   893  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   894  			ops = append(ops, &ReplaceOperation{
   895  				Path:  pathPrefix + "/fc",
   896  				Value: expandFCVolumeSource(v),
   897  			})
   898  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   899  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/fc"})
   900  		}
   901  	}
   902  
   903  	if d.HasChange(prefix + "flocker") {
   904  		oldIn, newIn := d.GetChange(prefix + "flocker")
   905  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   906  			ops = append(ops, &ReplaceOperation{
   907  				Path:  pathPrefix + "/flocker",
   908  				Value: expandFlockerVolumeSource(v),
   909  			})
   910  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   911  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/flocker"})
   912  		}
   913  	}
   914  
   915  	if d.HasChange(prefix + "flex_volume") {
   916  		oldIn, newIn := d.GetChange(prefix + "flex_volume")
   917  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   918  			ops = append(ops, &ReplaceOperation{
   919  				Path:  pathPrefix + "/flexVolume",
   920  				Value: expandFlexVolumeSource(v),
   921  			})
   922  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   923  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/flexVolume"})
   924  		}
   925  	}
   926  
   927  	if d.HasChange(prefix + "azure_file") {
   928  		oldIn, newIn := d.GetChange(prefix + "azure_file")
   929  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   930  			ops = append(ops, &ReplaceOperation{
   931  				Path:  pathPrefix + "/azureFile",
   932  				Value: expandAzureFileVolumeSource(v),
   933  			})
   934  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   935  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/azureFile"})
   936  		}
   937  	}
   938  
   939  	if d.HasChange(prefix + "vsphere_volume") {
   940  		oldIn, newIn := d.GetChange(prefix + "vsphere_volume")
   941  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   942  			ops = append(ops, &ReplaceOperation{
   943  				Path:  pathPrefix + "/vsphereVolume",
   944  				Value: expandVsphereVirtualDiskVolumeSource(v),
   945  			})
   946  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   947  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/vsphereVolume"})
   948  		}
   949  	}
   950  
   951  	if d.HasChange(prefix + "quobyte") {
   952  		oldIn, newIn := d.GetChange(prefix + "quobyte")
   953  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   954  			ops = append(ops, &ReplaceOperation{
   955  				Path:  pathPrefix + "/quobyte",
   956  				Value: expandQuobyteVolumeSource(v),
   957  			})
   958  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   959  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/quobyte"})
   960  		}
   961  	}
   962  
   963  	if d.HasChange(prefix + "azure_disk") {
   964  		oldIn, newIn := d.GetChange(prefix + "azure_disk")
   965  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   966  			ops = append(ops, &ReplaceOperation{
   967  				Path:  pathPrefix + "/azureDisk",
   968  				Value: expandAzureDiskVolumeSource(v),
   969  			})
   970  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   971  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/azureDisk"})
   972  		}
   973  	}
   974  
   975  	if d.HasChange(prefix + "photon_persistent_disk") {
   976  		oldIn, newIn := d.GetChange(prefix + "photon_persistent_disk")
   977  		if v, ok := newIn.([]interface{}); ok && len(v) > 0 {
   978  			ops = append(ops, &ReplaceOperation{
   979  				Path:  pathPrefix + "/photonPersistentDisk",
   980  				Value: expandPhotonPersistentDiskVolumeSource(v),
   981  			})
   982  		} else if v, ok := oldIn.([]interface{}); ok && len(v) > 0 {
   983  			ops = append(ops, &RemoveOperation{Path: pathPrefix + "/photonPersistentDisk"})
   984  		}
   985  	}
   986  
   987  	return ops
   988  }