generated from hashicorp/terraform-provider-scaffolding-framework
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add project, environment resource and orgnanisation data resour…
…ce (#168) * feat: Add organisation data source * feat: Add project resource * feat: Add environment resource * Add test data * Add docs * !fixup: Add project resource * bump terraform-plugin-docs * bump terraform-plugin-sdk/v2 * bump terraform-plugin-framework-validators * update changelog * remove outdated comment
- Loading branch information
1 parent
28a1b23
commit dc4ce8a
Showing
16 changed files
with
1,215 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "flagsmith_organisation Data Source - terraform-provider-flagsmith" | ||
subcategory: "" | ||
description: |- | ||
Flagsmith Organisation | ||
--- | ||
|
||
# flagsmith_organisation (Data Source) | ||
|
||
Flagsmith Organisation | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `uuid` (String) UUID of the organisation | ||
|
||
### Read-Only | ||
|
||
- `force_2fa` (Boolean) If true, signup will require 2FA | ||
- `id` (Number) ID of the organisation | ||
- `name` (String) Name of the organisation | ||
- `persist_trait_data` (Boolean) If false, trait data for this organisation identities will not stored | ||
- `restrict_project_create_to_admin` (Boolean) If true, only organisation admin can create projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "flagsmith_environment Resource - terraform-provider-flagsmith" | ||
subcategory: "" | ||
description: |- | ||
Flagsmith Environment | ||
--- | ||
|
||
# flagsmith_environment (Resource) | ||
|
||
Flagsmith Environment | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the environment | ||
- `project_id` (Number) ID of the project | ||
|
||
### Optional | ||
|
||
- `allow_client_traits` (Boolean) Allows clients using the client API key to set traits. | ||
- `banner_colour` (String) hex code for the UI banner colour | ||
- `banner_text` (String) Banner text to display in the UI | ||
- `description` (String) Description of the environment | ||
- `hide_disabled_flags` (Boolean) If true will exclude flags from SDK which are disabled | ||
- `hide_sensitive_data` (Boolean) If true, will hide sensitive data(e.g: traits, description etc) from the SDK endpoints | ||
- `minimum_change_request_approvals` (Number) Minimum number of approvals required for a change request | ||
- `use_identity_composite_key_for_hashing` (Boolean) Enable this to have consistent multivariate and percentage split evaluations across all SDKs (in local and server side mode) | ||
|
||
### Read-Only | ||
|
||
- `api_key` (String) Client side API Key | ||
- `id` (Number) ID of the environment | ||
- `uuid` (String) UUID of the environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "flagsmith_project Resource - terraform-provider-flagsmith" | ||
subcategory: "" | ||
description: |- | ||
Flagsmith Project | ||
--- | ||
|
||
# flagsmith_project (Resource) | ||
|
||
Flagsmith Project | ||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `name` (String) Name of the project | ||
- `organisation_id` (Number) ID of the organisation project belongs to | ||
|
||
### Optional | ||
|
||
- `enable_realtime_updates` (Boolean) Enable this to trigger a realtime(sse) event whenever the value of a flag changes | ||
- `feature_name_regex` (String) Used for validating feature names | ||
- `hide_disabled_flags` (Boolean) If true will exclude flags from SDK which are disabled | ||
- `only_allow_lower_case_feature_names` (Boolean) Used by UI to validate feature names | ||
- `prevent_flag_defaults` (Boolean) Prevent defaults from being set in all environments when creating a feature. | ||
- `stale_flags_limit_days` (Number) Number of days without modification in any environment before a flag is considered stale. | ||
|
||
### Read-Only | ||
|
||
- `id` (Number) ID of the project | ||
- `uuid` (String) UUID of the project |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package flagsmith | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Flagsmith/flagsmith-go-api-client" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource" | ||
"github.com/hashicorp/terraform-plugin-framework/datasource/schema" | ||
) | ||
|
||
// Ensure provider defined types fully satisfy framework interfaces | ||
var _ datasource.DataSource = &organisationDataResource{} | ||
|
||
func newOrganisationDataResource() datasource.DataSource { | ||
return &organisationDataResource{} | ||
} | ||
|
||
type organisationDataResource struct { | ||
client *flagsmithapi.Client | ||
} | ||
|
||
func (o *organisationDataResource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) { | ||
resp.TypeName = req.ProviderTypeName + "_organisation" | ||
} | ||
|
||
func (o *organisationDataResource) Configure(ctx context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) { | ||
// Prevent panic if the provider has not been configured. | ||
if req.ProviderData == nil { | ||
return | ||
} | ||
|
||
client, ok := req.ProviderData.(*flagsmithapi.Client) | ||
if !ok { | ||
resp.Diagnostics.AddError( | ||
"Unexpected Resource Configure Type", | ||
fmt.Sprintf("Expected *flagsmithapi.Client, got: %T. Please report this issue to the provider developers.", req.ProviderData), | ||
) | ||
return | ||
} | ||
|
||
o.client = client | ||
} | ||
func (o *organisationDataResource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) { | ||
resp.Schema = schema.Schema{ | ||
// This description is used by the documentation generator and the language server. | ||
MarkdownDescription: "Flagsmith Organisation", | ||
|
||
Attributes: map[string]schema.Attribute{ | ||
"uuid": schema.StringAttribute{ | ||
Required: true, | ||
MarkdownDescription: "UUID of the organisation", | ||
}, | ||
"id": schema.Int64Attribute{ | ||
Computed: true, | ||
MarkdownDescription: "ID of the organisation", | ||
}, | ||
"name": schema.StringAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "Name of the organisation", | ||
}, | ||
"force_2fa": schema.BoolAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "If true, signup will require 2FA", | ||
}, | ||
"persist_trait_data": schema.BoolAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "If false, trait data for this organisation identities will not stored", | ||
}, | ||
"restrict_project_create_to_admin": schema.BoolAttribute{ | ||
Computed: true, | ||
MarkdownDescription: "If true, only organisation admin can create projects", | ||
}, | ||
}, | ||
} | ||
} | ||
func (o *organisationDataResource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
var data OrganisationResourceData | ||
diags := req.Config.Get(ctx, &data) | ||
resp.Diagnostics.Append(diags...) | ||
|
||
// Early return if the state is wrong | ||
if diags.HasError() { | ||
return | ||
} | ||
|
||
organisation, err := o.client.GetOrganisationByUUID(data.UUID.ValueString()) | ||
if err != nil { | ||
panic(err) | ||
|
||
} | ||
resourceData := MakeOrganisationResourceDataFromClientOrganisation(organisation) | ||
|
||
diags = resp.State.Set(ctx, &resourceData) | ||
resp.Diagnostics.Append(diags...) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package flagsmith_test | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"testing" | ||
"strconv" | ||
) | ||
|
||
func TestAccOrganisationDataResource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccOrganisationDataResourceConfig(organisationUUID()), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
|
||
resource.TestCheckResourceAttr("data.flagsmith_organisation.test_org", "id", strconv.Itoa( organisationID())), | ||
resource.TestCheckResourceAttr("data.flagsmith_organisation.test_org", "uuid", organisationUUID()), | ||
|
||
resource.TestCheckResourceAttrSet("data.flagsmith_organisation.test_org", "name"), | ||
|
||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
|
||
func testAccOrganisationDataResourceConfig(organisationUUID string) string { | ||
return fmt.Sprintf(` | ||
provider "flagsmith" { | ||
} | ||
data "flagsmith_organisation" "test_org" { | ||
uuid = "%s" | ||
} | ||
`,organisationUUID) | ||
} |
Oops, something went wrong.