Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/resources/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ output "config_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Configs can be imported using the ConfigId. Get the ConfigId using the [List Configs API](https://api.configcat.com/docs/#tag/Configs/operation/get-configs) for example.

Expand Down
3 changes: 1 addition & 2 deletions docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ output "environment_id" {

### Optional

- `cleanup_auditlogs_on_destroy` (Boolean) An optional flag which indicates whether the audit log records related to the environment should be deleted upon destroying the resource. It can be useful to turn on for temporary, ephemeral environments, when you don't want to keep the audit log entries for the environment after it is destroyed.
- `color` (String) The color of the Environment.
- `description` (String) The description of the Environment.

Expand All @@ -53,8 +54,6 @@ output "environment_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Environments can be imported using the EnvironmentId. Get the EnvironmentId using the [List Environments API](https://api.configcat.com/docs/#tag/Environments/operation/get-environments) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ output "slack_integration_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Integrations can be imported using the IntegrationId. Get the IntegrationId using the [List Integrations API](https://api.configcat.com/docs/index.html#tag/Integrations/operation/get-integrations) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/permission_group.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ output "custom_permission_group_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Permission Groups can be imported using the PermissionGroupId. Get the PermissionGroupId using the [List Permission Groups API](https://api.configcat.com/docs/#tag/Permission-Groups/operation/get-permission-groups) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/product.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ output "product_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Products can be imported using the ProductId. Get the ProductId using the [List Products API](https://api.configcat.com/docs/#tag/Products/operation/get-products) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/product_preferences.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ resource "configcat_product_preferences" "preferences" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Product preferences can be imported using the ProductId. Get the ProductId using the [List Products API](https://api.configcat.com/docs/#tag/Products/operation/get-products) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/segment.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ output "segment_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Segments can be imported using the SegmentId. Get the SegmentId using the [List Segments API](https://api.configcat.com/docs/#tag/Segments/operation/get-segments) for example.

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ Optional:

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Feature Flags/Settings can be imported using the SettingId. Get the SettingId using e.g. the [List Flags API](https://api.configcat.com/docs/#tag/Feature-Flags-and-Settings/operation/get-settings).

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/setting_tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ resource "configcat_setting_tag" "my_setting_tag" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Setting Tags can be imported using a combined SettingId:TagId ID.
# Get the SettingId using e.g. the [List Flags API](https://api.configcat.com/docs/#tag/Feature-Flags-and-Settings/operation/get-settings).
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/setting_value.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ Optional:

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Feature Flag/Setting values (V1) can be imported using a combined EnvironmentID:SettingId ID.
# Get the EnvironmentId using e.g. the [List Environments API](https://api.configcat.com/docs/#tag/Environments/operation/get-environments).
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/setting_value_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ Optional:

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Feature Flag/Setting values (V2) can be imported using a combined EnvironmentID:SettingId ID.
# Get the EnvironmentId using e.g. the [List Environments API](https://api.configcat.com/docs/#tag/Environments/operation/get-environments).
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/tag.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ output "tag_id" {

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Tags can be imported using the TagId. Get the TagId using e.g. the [List Tags API](https://api.configcat.com/docs/#tag/Tags/operation/get-tags).

Expand Down
2 changes: 0 additions & 2 deletions docs/resources/webhook.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ Required:

Import is supported using the following syntax:

The [`terraform import` command](https://developer.hashicorp.com/terraform/cli/commands/import) can be used, for example:

```shell
# Webhooks can be imported using the WebhookId. Get the WebhookId using the [List Webhooks API](https://api.configcat.com/docs/index.html#tag/Webhooks/operation/get-webhooks) for example.
# It is important to note that webhooks containing secure webhook headers cannot be imported via `terraform import`.
Expand Down
4 changes: 2 additions & 2 deletions internal/configcat/client/client_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ func (client *Client) UpdateEnvironment(environmentID string, body sw.UpdateEnvi
return model, error
}

func (client *Client) DeleteEnvironment(environmentID string) error {
func (client *Client) DeleteEnvironment(environmentID string, cleanupAuditLogs bool) error {
response, err := client.apiClient.EnvironmentsAPI.DeleteEnvironment(
client.GetAuthContext(),
environmentID).Execute()
environmentID).CleanupAuditLogs(cleanupAuditLogs).Execute()
error := handleAPIError(err)
if response != nil && response.Body != nil {
defer response.Body.Close()
Expand Down
7 changes: 4 additions & 3 deletions internal/configcat/configcat_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@ const (
ConfigId = "config_id"
EvaluationVersion = "evaluation_version"

EnvironmentResourceName = "Environment"
Environments = "environments"
EnvironmentId = "environment_id"
EnvironmentResourceName = "Environment"
Environments = "environments"
EnvironmentId = "environment_id"
CleanupAuditLogsOnDestroy = "cleanup_auditlogs_on_destroy"

WebhookResourceName = "Webhook"
WebhookId = "webhook_id"
Expand Down
33 changes: 23 additions & 10 deletions internal/configcat/environment_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
Expand All @@ -31,11 +33,12 @@ type environmentResource struct {
type environmentResourceModel struct {
ProductId types.String `tfsdk:"product_id"`

ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Color types.String `tfsdk:"color"`
Order types.Int64 `tfsdk:"order"`
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Color types.String `tfsdk:"color"`
Order types.Int64 `tfsdk:"order"`
CleanupAuditLogsOnDestroy types.Bool `tfsdk:"cleanup_auditlogs_on_destroy"`
}

func (r *environmentResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
Expand Down Expand Up @@ -86,6 +89,15 @@ func (r *environmentResource) Schema(ctx context.Context, req resource.SchemaReq
Description: "The order of the " + EnvironmentResourceName + " within a " + ProductResourceName + " (zero-based). If multiple " + EnvironmentResourceName + "s has the same order, they are displayed in alphabetical order.",
Required: true,
},
CleanupAuditLogsOnDestroy: schema.BoolAttribute{
Description: "An optional flag which indicates whether the audit log records related to the environment should be deleted upon destroying the resource. It can be useful to turn on for temporary, ephemeral environments, when you don't want to keep the audit log entries for the environment after it is destroyed.",
Computed: true,
Optional: true,
Default: booldefault.StaticBool(false),
PlanModifiers: []planmodifier.Bool{
boolplanmodifier.UseStateForUnknown(),
},
},
},
}
}
Expand Down Expand Up @@ -132,7 +144,7 @@ func (r *environmentResource) Create(ctx context.Context, req resource.CreateReq
return
}

plan.UpdateFromApiModel(*model)
plan.UpdateFromApiModel(*model, plan.CleanupAuditLogsOnDestroy.ValueBool())

resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}
Expand All @@ -158,7 +170,7 @@ func (r *environmentResource) Read(ctx context.Context, req resource.ReadRequest
return
}

state.UpdateFromApiModel(*model)
state.UpdateFromApiModel(*model, state.CleanupAuditLogsOnDestroy.ValueBool())
resp.Diagnostics.Append(resp.State.Set(ctx, &state)...)
}

Expand Down Expand Up @@ -190,7 +202,7 @@ func (r *environmentResource) Update(ctx context.Context, req resource.UpdateReq
return
}

plan.UpdateFromApiModel(*model)
plan.UpdateFromApiModel(*model, plan.CleanupAuditLogsOnDestroy.ValueBool())
resp.Diagnostics.Append(resp.State.Set(ctx, &plan)...)
}

Expand All @@ -203,7 +215,7 @@ func (r *environmentResource) Delete(ctx context.Context, req resource.DeleteReq
return
}

err := r.client.DeleteEnvironment(state.ID.ValueString())
err := r.client.DeleteEnvironment(state.ID.ValueString(), state.CleanupAuditLogsOnDestroy.ValueBool())

if err != nil {
if _, ok := err.(client.NotFoundError); ok {
Expand All @@ -220,12 +232,13 @@ func (r *environmentResource) ImportState(ctx context.Context, req resource.Impo
resource.ImportStatePassthroughID(ctx, path.Root(ID), req, resp)
}

func (resourceModel *environmentResourceModel) UpdateFromApiModel(model sw.EnvironmentModel) {
func (resourceModel *environmentResourceModel) UpdateFromApiModel(model sw.EnvironmentModel, cleanupAuditLogsOnDestroy bool) {
modelOrder := int64(model.Order)
resourceModel.ID = types.StringValue(model.EnvironmentId)
resourceModel.ProductId = types.StringValue(model.Product.ProductId)
resourceModel.Name = types.StringValue(model.Name)
resourceModel.Description = types.StringPointerValue(model.Description.Get())
resourceModel.Color = types.StringPointerValue(model.Color.Get())
resourceModel.Order = types.Int64Value(modelOrder)
resourceModel.CleanupAuditLogsOnDestroy = types.BoolValue(cleanupAuditLogsOnDestroy)
}
49 changes: 49 additions & 0 deletions internal/configcat/environment_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,52 @@ func TestAccEnvironmentResource(t *testing.T) {
},
})
}

func TestAccCleanupAuditLogsOnDestroyEnvironmentResource(t *testing.T) {
const productId = "08d86d63-2721-4da6-8c06-584521d516bc"
const testResourceName = "configcat_environment.test"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
{
ConfigFile: config.TestNameFile("cleanup_step_1.tf"),
ConfigVariables: config.Variables{
"product_id": config.StringVariable(productId),
"name": config.StringVariable("Resource name"),
"order": config.IntegerVariable(1),
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(testResourceName, ID),
resource.TestCheckResourceAttr(testResourceName, Name, "Resource name"),
resource.TestCheckResourceAttr(testResourceName, Order, "1"),
resource.TestCheckResourceAttr(testResourceName, Description, ""),
resource.TestCheckResourceAttr(testResourceName, Color, ""),
),
},
{
ConfigFile: config.TestNameFile("cleanup_step_2.tf"),
},
{
ConfigFile: config.TestNameFile("cleanup_step_1.tf"),
ConfigVariables: config.Variables{
"product_id": config.StringVariable(productId),
"name": config.StringVariable("Resource name"),
"order": config.IntegerVariable(1),
"cleanup_auditlogs_on_destroy": config.BoolVariable(true),
},
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttrSet(testResourceName, ID),
resource.TestCheckResourceAttr(testResourceName, Name, "Resource name"),
resource.TestCheckResourceAttr(testResourceName, Order, "1"),
resource.TestCheckResourceAttr(testResourceName, Description, ""),
resource.TestCheckResourceAttr(testResourceName, Color, ""),
),
},
{
ConfigFile: config.TestNameFile("cleanup_step_2.tf"),
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
variable "product_id" {
type = string
}

variable "name" {
type = string
}
variable "description" {
type = string
default = null
}
variable "color" {
type = string
default = null
}
variable "order" {
type = number
default = 0
}
variable "cleanup_auditlogs_on_destroy" {
type = bool
default = false
}

resource "configcat_environment" "test" {
product_id = var.product_id
name = var.name
description = var.description
color = var.color
order = var.order
cleanup_auditlogs_on_destroy = var.cleanup_auditlogs_on_destroy
}
Loading