diff --git a/internal/resources/core/v1/namespace/generate.go b/internal/resources/core/v1/namespace/generate.go index ac6ae9c4..3ee9ad19 100644 --- a/internal/resources/core/v1/namespace/generate.go +++ b/internal/resources/core/v1/namespace/generate.go @@ -4,15 +4,21 @@ import ( "github.com/hashicorp/terraform/helper/schema" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + + "github.com/previousnext/terraform-provider-k8s/internal/interfaceutils" ) // Generate the Namespace. func Generate(d *schema.ResourceData) (corev1.Namespace, error) { - var name = d.Get(FieldName).(string) + var ( + name = d.Get(FieldName).(string) + labels = d.Get(FieldLabels).(map[string]interface{}) + ) namespace := corev1.Namespace{ ObjectMeta: metav1.ObjectMeta{ - Name: name, + Name: name, + Labels: interfaceutils.ExpandMap(labels), }, } diff --git a/internal/resources/core/v1/namespace/read.go b/internal/resources/core/v1/namespace/read.go index b5e7cb48..f3a03a8f 100644 --- a/internal/resources/core/v1/namespace/read.go +++ b/internal/resources/core/v1/namespace/read.go @@ -22,6 +22,7 @@ func Read(d *schema.ResourceData, m interface{}) error { } d.Set(FieldName, namespace.ObjectMeta.Name) + d.Set(FieldLabels, namespace.ObjectMeta.Labels) return nil } diff --git a/internal/resources/core/v1/namespace/resource.go b/internal/resources/core/v1/namespace/resource.go index 3b1808e0..5e6eaed9 100644 --- a/internal/resources/core/v1/namespace/resource.go +++ b/internal/resources/core/v1/namespace/resource.go @@ -7,6 +7,8 @@ import ( const ( // FieldName is a field identifier. FieldName = "name" + // FieldLabels is a field identifier. + FieldLabels = "labels" ) // Resource returns this packages Resource and Fields. @@ -18,10 +20,14 @@ func Resource() *schema.Resource { Delete: Delete, Schema: map[string]*schema.Schema{ - FieldName: &schema.Schema{ + FieldName: { Type: schema.TypeString, Required: true, }, + FieldLabels: { + Type: schema.TypeMap, + Optional: true, + }, }, } }