github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/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  		},
    36  		"resource_version": {
    37  			Type:        schema.TypeString,
    38  			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),
    39  			Computed:    true,
    40  		},
    41  		"self_link": {
    42  			Type:        schema.TypeString,
    43  			Description: fmt.Sprintf("A URL representing this %s.", objectName),
    44  			Computed:    true,
    45  		},
    46  		"uid": {
    47  			Type:        schema.TypeString,
    48  			Description: fmt.Sprintf("The unique in time and space value for this %s. More info: http://kubernetes.io/docs/user-guide/identifiers#uids", objectName),
    49  			Computed:    true,
    50  		},
    51  	}
    52  }
    53  
    54  func metadataSchema(objectName string, generatableName bool) *schema.Schema {
    55  	fields := metadataFields(objectName)
    56  
    57  	if generatableName {
    58  		fields["generate_name"] = &schema.Schema{
    59  			Type:          schema.TypeString,
    60  			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",
    61  			Optional:      true,
    62  			ForceNew:      true,
    63  			ValidateFunc:  validateGenerateName,
    64  			ConflictsWith: []string{"metadata.name"},
    65  		}
    66  		fields["name"].ConflictsWith = []string{"metadata.generate_name"}
    67  	}
    68  
    69  	return &schema.Schema{
    70  		Type:        schema.TypeList,
    71  		Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
    72  		Required:    true,
    73  		MaxItems:    1,
    74  		Elem: &schema.Resource{
    75  			Schema: fields,
    76  		},
    77  	}
    78  }
    79  
    80  func namespacedMetadataSchema(objectName string, generatableName bool) *schema.Schema {
    81  	fields := metadataFields(objectName)
    82  	fields["namespace"] = &schema.Schema{
    83  		Type:        schema.TypeString,
    84  		Description: fmt.Sprintf("Namespace defines the space within which name of the %s must be unique.", objectName),
    85  		Optional:    true,
    86  		ForceNew:    true,
    87  		Default:     "default",
    88  	}
    89  	if generatableName {
    90  		fields["generate_name"] = &schema.Schema{
    91  			Type:          schema.TypeString,
    92  			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",
    93  			Optional:      true,
    94  			ForceNew:      true,
    95  			ValidateFunc:  validateGenerateName,
    96  			ConflictsWith: []string{"metadata.name"},
    97  		}
    98  		fields["name"].ConflictsWith = []string{"metadata.generate_name"}
    99  	}
   100  
   101  	return &schema.Schema{
   102  		Type:        schema.TypeList,
   103  		Description: fmt.Sprintf("Standard %s's metadata. More info: https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md#metadata", objectName),
   104  		Required:    true,
   105  		MaxItems:    1,
   106  		Elem: &schema.Resource{
   107  			Schema: fields,
   108  		},
   109  	}
   110  }