From 2993eb76fb0009d79987f7e0c7804bec63fbad18 Mon Sep 17 00:00:00 2001 From: michiel de wilde Date: Thu, 21 Mar 2024 14:20:10 +0100 Subject: [PATCH] add support for policy description (#530) Co-authored-by: Mohamed El Mouctar HAIDARA Co-authored-by: Marcin Wyszynski --- docs/data-sources/policies.md | 1 + docs/data-sources/policy.md | 1 + docs/resources/policy.md | 1 + spacelift/data_policies.go | 27 ++++++++++++-------- spacelift/data_policy.go | 6 +++++ spacelift/data_policy_test.go | 4 +++ spacelift/internal/structs/policy.go | 13 +++++----- spacelift/resource_policy.go | 37 +++++++++++++++++++--------- spacelift/resource_policy_test.go | 4 +++ 9 files changed, 66 insertions(+), 28 deletions(-) diff --git a/docs/data-sources/policies.md b/docs/data-sources/policies.md index 4ead3397..7af568f4 100644 --- a/docs/data-sources/policies.md +++ b/docs/data-sources/policies.md @@ -45,6 +45,7 @@ output "policy_ids" { Read-Only: +- `description` (String) - `id` (String) - `labels` (Set of String) - `name` (String) diff --git a/docs/data-sources/policy.md b/docs/data-sources/policy.md index 4daca864..c17dd33a 100644 --- a/docs/data-sources/policy.md +++ b/docs/data-sources/policy.md @@ -32,6 +32,7 @@ output "policy_body" { ### Read-Only - `body` (String) body of the policy +- `description` (String) description of the policy - `id` (String) The ID of this resource. - `labels` (Set of String) - `name` (String) name of the policy diff --git a/docs/resources/policy.md b/docs/resources/policy.md index 7bdede47..c0360274 100644 --- a/docs/resources/policy.md +++ b/docs/resources/policy.md @@ -42,6 +42,7 @@ resource "spacelift_policy_attachment" "no-weekend-deploys" { ### Optional +- `description` (String) Description of the policy - `labels` (Set of String) - `space_id` (String) ID (slug) of the space the policy is in diff --git a/spacelift/data_policies.go b/spacelift/data_policies.go index b8af0a21..d010fddd 100644 --- a/spacelift/data_policies.go +++ b/spacelift/data_policies.go @@ -59,6 +59,11 @@ func dataPolicies() *schema.Resource { Description: "Type of the policy", Computed: true, }, + "description": { + Type: schema.TypeString, + Description: "description of the policy", + Computed: true, + }, }, }, }, @@ -70,11 +75,12 @@ func dataPoliciesRead(ctx context.Context, d *schema.ResourceData, meta interfac d.SetId(fmt.Sprintf("policies/%s/%s", d.Get("type").(string), d.Get("labels").(*schema.Set).List())) var query struct { Policies []struct { - ID string `graphql:"id"` - Labels []string `graphql:"labels"` - Name string `graphql:"name"` - Type string `graphql:"type"` - Space string `graphql:"space"` + ID string `graphql:"id"` + Labels []string `graphql:"labels"` + Name string `graphql:"name"` + Type string `graphql:"type"` + Space string `graphql:"space"` + Description string `graphql:"description"` } `graphql:"policies()"` } @@ -110,11 +116,12 @@ func dataPoliciesRead(ctx context.Context, d *schema.ResourceData, meta interfac } } policies = append(policies, map[string]interface{}{ - "id": policy.ID, - "labels": policy.Labels, - "name": policy.Name, - "type": policy.Type, - "space_id": policy.Space, + "id": policy.ID, + "labels": policy.Labels, + "name": policy.Name, + "type": policy.Type, + "space_id": policy.Space, + "description": policy.Description, }) } diff --git a/spacelift/data_policy.go b/spacelift/data_policy.go index 29842455..51691b71 100644 --- a/spacelift/data_policy.go +++ b/spacelift/data_policy.go @@ -42,6 +42,11 @@ func dataPolicy() *schema.Resource { Description: "name of the policy", Computed: true, }, + "description": { + Type: schema.TypeString, + Description: "description of the policy", + Computed: true, + }, "space_id": { Type: schema.TypeString, Description: "ID (slug) of the space the policy is in", @@ -76,6 +81,7 @@ func dataPolicyRead(ctx context.Context, d *schema.ResourceData, meta interface{ d.Set("body", policy.Body) d.Set("type", policy.Type) d.Set("space_id", policy.Space) + d.Set("description", policy.Description) labels := schema.NewSet(schema.HashString, []interface{}{}) for _, label := range policy.Labels { diff --git a/spacelift/data_policy_test.go b/spacelift/data_policy_test.go index a3632837..2695935c 100644 --- a/spacelift/data_policy_test.go +++ b/spacelift/data_policy_test.go @@ -19,6 +19,7 @@ func TestPolicyData(t *testing.T) { resource "spacelift_policy" "test" { name = "My first policy %s" labels = ["one", "two"] + description = "My awesome policy" body = <