Skip to content

Commit

Permalink
FFM-9085: Add a terraform resource to create a new target (#660)
Browse files Browse the repository at this point in the history
* FFM-9085: Add a terraform resource to create a new target

* Implement CRUD actions for creating a new target in terraform
* Add all the interfaces and implementations
* Add unit test
* Fix package path
* Add build script
* Fix code base
* Add release target
* Include documentation and examples
* Update 670.txt
* Update resource.tf
* add code review comments
* fix platform_slo
* add documentation for feature-flag-target
* add nextGen to featureFlag
* Update platform_feature_flag_target.md

---------

Co-authored-by: Meet Rathod <rathod.meetsatish@harness.io>
  • Loading branch information
ribeirophillipe and rathodmeetsatish committed Aug 30, 2023
1 parent 57e42e1 commit 28ba6a7
Show file tree
Hide file tree
Showing 9 changed files with 499 additions and 37 deletions.
3 changes: 3 additions & 0 deletions .changelog/660.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
resource_feature_flag_target - Added feature flag target resources to the Harness Terraform Provider.
```
46 changes: 46 additions & 0 deletions docs/resources/platform_feature_flag_target.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "harness_platform_feature_flag_target Resource - terraform-provider-harness"
subcategory: "Next Gen"
description: |-
Resource for managing Feature Flag Targets.
---

# harness_platform_feature_flag_target (Resource)

Resource for managing Feature Flag Targets.

## Example Usage

```terraform
resource "harness_platform_feature_flag_target" "target" {
org_id = "test"
project_id = "test"
identifier = "MY_FEATURE"
environment = "MY_ENVIRONMENT"
name = "MY_FEATURE"
account_id = "MY_ACCOUNT_ID"
attributes = { "foo" : "bar" }
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `account_id` (String) Account Identifier
- `environment` (String) Environment Identifier
- `identifier` (String) Identifier of the Feature Flag Target
- `name` (String) Target Name
- `org_id` (String) Organization Identifier
- `project_id` (String) Project Identifier

### Optional

- `attributes` (Map of String) Attributes

### Read-Only

- `id` (String) The ID of this resource.
50 changes: 25 additions & 25 deletions examples/resources/harness_platform_feature_flag/resource.tf
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
// Boolean Flag
resource "harness_platform_feature_flag" "mybooleanflag" {
org_id = "test"
org_id = "test"
project_id = "testff"

kind = "boolean"
name = "MY_FEATURE"
kind = "boolean"
name = "MY_FEATURE"
identifier = "MY_FEATURE"
permanent = false
permanent = false

default_on_variation = "Enabled"
default_on_variation = "Enabled"
default_off_variation = "Disabled"

variation {
identifier = "Enabled"
name = "Enabled"
identifier = "Enabled"
name = "Enabled"
description = "The feature is enabled"
value = "true"
value = "true"
}

variation {
identifier = "Disabled"
name = "Disabled"
identifier = "Disabled"
name = "Disabled"
description = "The feature is disabled"
value = "false"
value = "false"
}
}


// Multivariate flag
resource "harness_platform_feature_flag" "mymultivariateflag" {
org_id = "test"
org_id = "test"
project_id = "testff"

kind = "int"
name = "FREE_TRIAL_DURATION"
kind = "int"
name = "FREE_TRIAL_DURATION"
identifier = "FREE_TRIAL_DURATION"
permanent = false
permanent = false

default_on_variation = "trial7"
default_on_variation = "trial7"
default_off_variation = "trial20"

variation {
identifier = "trial7"
name = "7 days trial"
identifier = "trial7"
name = "7 days trial"
description = "Free trial period 7 days"
value = "7"
value = "7"
}

variation {
identifier = "trial14"
name = "14 days trial"
identifier = "trial14"
name = "14 days trial"
description = "Free trial period 14 days"
value = "14"
value = "14"
}

variation {
identifier = "trial20"
name = "20 days trial"
identifier = "trial20"
name = "20 days trial"
description = "Free trial period 20 days"
value = "20"
value = "20"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resource "harness_platform_feature_flag_target" "target" {
org_id = "test"
project_id = "test"

identifier = "MY_FEATURE"
environment = "MY_ENVIRONMENT"
name = "MY_FEATURE"
account_id = "MY_ACCOUNT_ID"
attributes = { "foo" : "bar" }
}
18 changes: 9 additions & 9 deletions examples/resources/harness_platform_ff_api_key/resource.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
resource "harness_platform_ff_api_key" "testserverapikey" {
identifier = "testserver"
name = "TestServer"
description = "this is a server SDK key"
org_id = "test"
project_id = "testff"
env_id = "testenv"
expired_at = 1713729225
type = "Server"
identifier = "testserver"
name = "TestServer"
description = "this is a server SDK key"
org_id = "test"
project_id = "testff"
env_id = "testenv"
expired_at = 1713729225
type = "Server"
}

output "serversdkkey" {
value = harness_platform_ff_api_key.testserverapikey.api_key
value = harness_platform_ff_api_key.testserverapikey.api_key
sensitive = true
}
4 changes: 3 additions & 1 deletion internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"log"

"github.com/harness/terraform-provider-harness/internal/service/platform/feature_flag"
"github.com/harness/terraform-provider-harness/internal/service/platform/feature_flag_target"
"github.com/harness/terraform-provider-harness/internal/service/platform/ff_api_key"
"github.com/harness/terraform-provider-harness/internal/service/platform/gitops/agent_yaml"
"github.com/harness/terraform-provider-harness/internal/service/platform/manual_freeze"
Expand Down Expand Up @@ -266,8 +267,9 @@ func Provider(version string) func() *schema.Provider {
"harness_platform_environment_group": pl_environment_group.ResourceEnvironmentGroup(),
"harness_platform_environment_clusters_mapping": pl_environment_clusters_mapping.ResourceEnvironmentClustersMapping(),
"harness_platform_environment_service_overrides": pl_environment_service_overrides.ResourceEnvironmentServiceOverrides(),
"harness_platform_service_overrides_v2": pl_service_overrides_v2.ResourceServiceOverrides(),
"harness_platform_feature_flag": feature_flag.ResourceFeatureFlag(),
"harness_platform_feature_flag_target": feature_flag_target.ResourceFeatureFlagTarget(),
"harness_platform_service_overrides_v2": pl_service_overrides_v2.ResourceServiceOverrides(),
"harness_platform_ff_api_key": ff_api_key.ResourceFFApiKey(),
"harness_platform_gitops_agent": gitops_agent.ResourceGitopsAgent(),
"harness_platform_gitops_applications": gitops_applications.ResourceGitopsApplication(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package feature_flag

import (
"context"
"io/ioutil"
"io"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -209,7 +209,7 @@ func resourceFeatureFlagCreate(ctx context.Context, d *schema.ResourceData, meta
resp, httpResp, err = c.FeatureFlagsApi.GetFeatureFlag(ctx, id, c.AccountId, qp.OrganizationId, qp.ProjectId, readOpts)

if err != nil {
body, _ := ioutil.ReadAll(httpResp.Body)
body, _ := io.ReadAll(httpResp.Body)
return diag.Errorf("readstatus: %s, \nBody:%s", httpResp.Status, body)
//return helpers.HandleReadApiError(err, d, httpResp)
}
Expand Down
Loading

0 comments on commit 28ba6a7

Please sign in to comment.