Skip to content

Commit

Permalink
Fix projects data source (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdelucaa authored Aug 9, 2023
1 parent a372540 commit 95cfb7e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
9 changes: 8 additions & 1 deletion docs/data-sources/project.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a id="nestedatt--environments"></a>
### Nested Schema for `environments`

Read-Only:

- `environment` (String)


2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
21 changes: 17 additions & 4 deletions internal/provider/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
},
},
},
Expand All @@ -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
}

0 comments on commit 95cfb7e

Please sign in to comment.