From 95cfb7e0ad9a3d36eddfe0176b6ca790fcb410a3 Mon Sep 17 00:00:00 2001 From: Joana Deluca Kleis <13077810+jdelucaa@users.noreply.github.com> Date: Wed, 9 Aug 2023 14:22:39 -0300 Subject: [PATCH] Fix projects data source (#79) --- docs/data-sources/project.md | 9 ++++++++- go.mod | 2 +- go.sum | 4 ++-- internal/provider/data_source_project.go | 21 +++++++++++++++++---- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/data-sources/project.md b/docs/data-sources/project.md index 2202672..1d460c7 100644 --- a/docs/data-sources/project.md +++ b/docs/data-sources/project.md @@ -28,9 +28,16 @@ data "unleash_project" "example" { ### Read-Only - `description` (String) The description of the unleash project -- `environments` (Set of String) The list of unleash environments in this project +- `environments` (List of Object) The list of unleash environments in this project (see [below for nested schema](#nestedatt--environments)) - `id` (String) The ID of this resource. - `name` (String) Project name - `updated_at` (String) The date the unleash project was last updated + +### Nested Schema for `environments` + +Read-Only: + +- `environment` (String) + diff --git a/go.mod b/go.mod index 0230cd1..89e44e1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.18 require ( github.com/hashicorp/terraform-plugin-docs v0.14.1 github.com/hashicorp/terraform-plugin-sdk/v2 v2.26.1 - github.com/philips-labs/go-unleash-api v1.0.5 + github.com/philips-labs/go-unleash-api v1.0.6 ) require ( diff --git a/go.sum b/go.sum index 2100e8d..8e46a0a 100644 --- a/go.sum +++ b/go.sum @@ -184,8 +184,8 @@ github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/run v1.0.0 h1:Ru7dDtJNOyC66gQ5dQmaCa0qIsAUFY3sFpK1Xk8igrw= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= -github.com/philips-labs/go-unleash-api v1.0.5 h1:eESdVQbH7szoLfe8l0JjCuQWoL7uKVJ4u2Fjt15B0Tw= -github.com/philips-labs/go-unleash-api v1.0.5/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4= +github.com/philips-labs/go-unleash-api v1.0.6 h1:jXGwBfW2wvCirvJCjFly9kOIhFT7PN4VVpgdoyovOGQ= +github.com/philips-labs/go-unleash-api v1.0.6/go.mod h1:7iJbdxlvMu9VlRLpitWFavCifH8IsfYPc7EkDY3PFv4= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= diff --git a/internal/provider/data_source_project.go b/internal/provider/data_source_project.go index 862f066..a31604d 100644 --- a/internal/provider/data_source_project.go +++ b/internal/provider/data_source_project.go @@ -39,10 +39,16 @@ func dataSourceProject() *schema.Resource { }, "environments": { Description: "The list of unleash environments in this project", - Type: schema.TypeSet, + Type: schema.TypeList, Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "environment": { + Description: "The environment name.", + Type: schema.TypeString, + Computed: true, + }, + }, }, }, }, @@ -65,7 +71,14 @@ func dataSourceProjectRead(ctx context.Context, d *schema.ResourceData, meta int _ = d.Set("name", foundProject.Name) _ = d.Set("description", foundProject.Description) _ = d.Set("updatedAt", foundProject.UpdatedAt) - _ = d.Set("environments", foundProject.Environments) + + envs := []interface{}{} + for _, env := range foundProject.Environments { + tfMap := map[string]interface{}{} + tfMap["environment"] = env.Environment + envs = append(envs, tfMap) + } + _ = d.Set("environments", envs) return diags }