github.com/cbroglie/terraform@v0.7.0-rc3.0.20170410193827-735dfc416d46/builtin/providers/kubernetes/schema_metadata.go (about)

     1  package kubernetes
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  )
     8  
     9  func metadataFields(objectName string) map[string]*schema.Schema {
    10  	return map[string]*schema.Schema{
    11  		"annotations": {
    12  			Type:         schema.TypeMap,
    13  			Description:  fmt.Sprintf("An unstructured key value map stored with the %s that may be used to store arbitrary metadata. More info: http://kubernetes.io/docs/user-guide/annotations", objectName),
    14  			Optional:     true,
    15  			ValidateFunc: validateAnnotations,
    16  		},
    17  		"generation": {
    18  			Type:        schema.TypeInt,
    19  			Description: "A sequence number representing a specific generation of the desired state.",
    20  			Computed:    true,
    21  		},
    22  		"labels": {
    23  			Type:         schema.TypeMap,
    24  			Description:  fmt.Sprintf("Map of string keys and values that can be used to organize and categorize (scope and select) the %s. May match selectors of replication controllers and services. More info: http://kubernetes.io/docs/user-guide/labels", objectName),
    25  			Optional:     true,
    26  			ValidateFunc: validateLabels,
    27  		},
    28  		"name": {
    29  			Type:          schema.TypeString,
    30  			Description:   fmt.Sprintf("Name of the %s, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names", objectName),
    31  			Optional:      true,
    32  			ForceNew:      true,
    33  			Computed:      true,
    34  			ValidateFunc:  validateName,
    35  			ConflictsWith: []string{"metadata.generate_name"},
    36  		},
    37  		"resource_version": {
    38  			Type:        schema.TypeString,
    39  			Description: fmt.Sprintf("An opaque value that represents the internal version of this %s that can be used by clients to determine when %s has changed. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#concurrency-control-and-consistency", objectName, objectName),
    40  			Computed:    true,
    41  		},
    42  		"self_link": {
    43  			Type:        schema.TypeString,
    44  			Description: fmt.Sprintf("A URL representing this %s.", objectName),
    45  			Computed:    true,
    46  		},
    47  		"uid": {
    48  			Type:        schema.TypeString,
    49  			Description: fmt.Sprintf("The unique in time and space value for this %s. More info: http://kubernetes.io/docs/user-guide/identifiers#uids", objectName),
    50  			Computed:    true,
    51  		},
    52  	}
    53  }
    54  
    55  func metadataSchema(objectName string) *schema.Schema {
    56  	fields := metadataFields(objectName)
    57  	fields["generate_name"] = &schema.Schema{
    58  		Type:          schema.TypeString,
    59  		Description:   "Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency",
    60  		Optional:      true,
    61  		ForceNew:      true,
    62  		ValidateFunc:  validateGenerateName,
    63  		ConflictsWith: []string{"metadata.name"},
    64  	}
    65  
    66  	return &schema.Schema{
    67  		Type:        schema.TypeList,
    68  		Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
    69  		Required:    true,
    70  		MaxItems:    1,
    71  		Elem: &schema.Resource{
    72  			Schema: fields,
    73  		},
    74  	}
    75  }
    76  
    77  func namespacedMetadataSchema(objectName string, generatableName bool) *schema.Schema {
    78  	fields := metadataFields(objectName)
    79  	fields["namespace"] = &schema.Schema{
    80  		Type:        schema.TypeString,
    81  		Description: fmt.Sprintf("Namespace defines the space within which name of the %s must be unique.", objectName),
    82  		Optional:    true,
    83  		ForceNew:    true,
    84  		Default:     "default",
    85  	}
    86  	if generatableName {
    87  		fields["generate_name"] = &schema.Schema{
    88  			Type:          schema.TypeString,
    89  			Description:   "Prefix, used by the server, to generate a unique name ONLY IF the `name` field has not been provided. This value will also be combined with a unique suffix. Read more: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#idempotency",
    90  			Optional:      true,
    91  			ForceNew:      true,
    92  			ValidateFunc:  validateGenerateName,
    93  			ConflictsWith: []string{"metadata.name"},
    94  		}
    95  	}
    96  
    97  	return &schema.Schema{
    98  		Type:        schema.TypeList,
    99  		Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
   100  		Required:    true,
   101  		MaxItems:    1,
   102  		Elem: &schema.Resource{
   103  			Schema: fields,
   104  		},
   105  	}
   106  }