kubernetes: Make generatable name optional in metadataSchema
This commit is contained in:
parent
735dfc416d
commit
793ce368fc
|
@ -25,7 +25,7 @@ func resourceKubernetesNamespace() *schema.Resource {
|
||||||
},
|
},
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
"metadata": metadataSchema("namespace"),
|
"metadata": metadataSchema("namespace", true),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,12 @@ func metadataFields(objectName string) map[string]*schema.Schema {
|
||||||
ValidateFunc: validateLabels,
|
ValidateFunc: validateLabels,
|
||||||
},
|
},
|
||||||
"name": {
|
"name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Description: fmt.Sprintf("Name of the %s, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names", objectName),
|
Description: fmt.Sprintf("Name of the %s, must be unique. Cannot be updated. More info: http://kubernetes.io/docs/user-guide/identifiers#names", objectName),
|
||||||
Optional: true,
|
Optional: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
ValidateFunc: validateName,
|
ValidateFunc: validateName,
|
||||||
ConflictsWith: []string{"metadata.generate_name"},
|
|
||||||
},
|
},
|
||||||
"resource_version": {
|
"resource_version": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
|
@ -52,15 +51,19 @@ func metadataFields(objectName string) map[string]*schema.Schema {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func metadataSchema(objectName string) *schema.Schema {
|
func metadataSchema(objectName string, generatableName bool) *schema.Schema {
|
||||||
fields := metadataFields(objectName)
|
fields := metadataFields(objectName)
|
||||||
fields["generate_name"] = &schema.Schema{
|
|
||||||
Type: schema.TypeString,
|
if generatableName {
|
||||||
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",
|
fields["generate_name"] = &schema.Schema{
|
||||||
Optional: true,
|
Type: schema.TypeString,
|
||||||
ForceNew: true,
|
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",
|
||||||
ValidateFunc: validateGenerateName,
|
Optional: true,
|
||||||
ConflictsWith: []string{"metadata.name"},
|
ForceNew: true,
|
||||||
|
ValidateFunc: validateGenerateName,
|
||||||
|
ConflictsWith: []string{"metadata.name"},
|
||||||
|
}
|
||||||
|
fields["name"].ConflictsWith = []string{"metadata.generate_name"}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &schema.Schema{
|
return &schema.Schema{
|
||||||
|
@ -92,6 +95,7 @@ func namespacedMetadataSchema(objectName string, generatableName bool) *schema.S
|
||||||
ValidateFunc: validateGenerateName,
|
ValidateFunc: validateGenerateName,
|
||||||
ConflictsWith: []string{"metadata.name"},
|
ConflictsWith: []string{"metadata.name"},
|
||||||
}
|
}
|
||||||
|
fields["name"].ConflictsWith = []string{"metadata.generate_name"}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &schema.Schema{
|
return &schema.Schema{
|
||||||
|
|
|
@ -68,7 +68,9 @@ func expandStringMap(m map[string]interface{}) map[string]string {
|
||||||
func flattenMetadata(meta api.ObjectMeta) []map[string]interface{} {
|
func flattenMetadata(meta api.ObjectMeta) []map[string]interface{} {
|
||||||
m := make(map[string]interface{})
|
m := make(map[string]interface{})
|
||||||
m["annotations"] = filterAnnotations(meta.Annotations)
|
m["annotations"] = filterAnnotations(meta.Annotations)
|
||||||
m["generate_name"] = meta.GenerateName
|
if meta.GenerateName != "" {
|
||||||
|
m["generate_name"] = meta.GenerateName
|
||||||
|
}
|
||||||
m["labels"] = meta.Labels
|
m["labels"] = meta.Labels
|
||||||
m["name"] = meta.Name
|
m["name"] = meta.Name
|
||||||
m["resource_version"] = meta.ResourceVersion
|
m["resource_version"] = meta.ResourceVersion
|
||||||
|
|
Loading…
Reference in New Issue