Harness integrates with Terraform to manage feature flags as code, enabling streamlined deployment pipelines and automated feature management. This integration enhances collaboration, ensures consistent infrastructure management, and offers granular control over feature rollouts.
Before we dive into the details of the harness_platform_feature_flag resource, let's briefly understand what Feature Flags are and why they are essential for modern software delivery.
Feature Flags are a technique that allows you to toggle the visibility of certain features or code sections in your application without redeploying it. This approach provides several benefits, including controlled rollouts, A/B testing, and quickly responding to issues by disabling specific features.
Harness seamlessly integrates with Terraform, enabling you to define and manage Feature Flags as code. This integration streamlines your deployment pipelines, enhances collaboration between development and operations teams, and ensures consistent, automated management of your feature flags.
The harness_platform_feature_flag resource empowers you to define and manage Feature Flags within your Harness environment. Let's explore some usage examples:
resource "harness_platform_feature_flag" "mybooleanflag" {
org_id = "your-org-id"
project_id = "your-project-id"
kind = "boolean"
name = "MY_FEATURE"
identifier = "MY_FEATURE"
permanent = false
default_on_variation = "Enabled"
default_off_variation = "Disabled"
variation {
identifier = "Enabled"
name = "Enabled"
description = "The feature is enabled"
value = "true"
}
variation {
identifier = "Disabled"
name = "Disabled"
description = "The feature is disabled"
value = "false"
}
}
In this example, we create a boolean Feature Flag named "MY_FEATURE" with two variations: "Enabled" and "Disabled."
resource "harness_platform_feature_flag" "mymultivariateflag" {
org_id = "your-org-id"
project_id = "your-project-id"
kind = "int"
name = "FREE_TRIAL_DURATION"
identifier = "FREE_TRIAL_DURATION"
permanent = false
default_on_variation = "trial7"
default_off_variation = "trial20"
variation {
identifier = "trial7"
name = "7 days trial"
description = "Free trial period 7 days"
value = "7"
}
variation {
identifier = "trial14"
name = "14 days trial"
description = "Free trial period 14 days"
value = "14"
}
variation {
identifier = "trial20"
name = "20 days trial"
description = "Free trial period 20 days"
value = "20"
}
}
In this example, we create a multivariate Feature Flag named "FREE_TRIAL_DURATION" with three variations: "7 days trial," "14 days trial," and "20 days trial."
You can also assign targets or target groups to your Feature Flags:
resource "harness_platform_feature_flag" "mytargetedflag" {
org_id = "your-org-id"
project_id = "your-project-id"
kind = "boolean"
name = "MY_TARGETED_FEATURE"
identifier = "MY_TARGETED_FEATURE"
environment = "MY_ENVIRONMENT"
permanent = false
default_on_variation = "Enabled"
default_off_variation = "Disabled"
variation {
identifier = "Enabled"
name = "Enabled"
description = "The feature is enabled"
value = "true"
}
variation {
identifier = "Disabled"
name = "Disabled"
description = "The feature is disabled"
value = "false"
}
add_target_rule {
variation = "Enabled"
targets = ["target1", "target2"]
}
}
In this example, we create a Feature Flag "MY_TARGETED_FEATURE" and assign it to specific targets in the "MY_ENVIRONMENT."
Harness and Terraform provide extensive options for configuring Feature Flags:
Before we dive into the details of the harness_platform_feature_flag_target_group resource, let's clarify what Feature Flag Target Groups are and why they are essential.
Feature Flag Target Groups are collections of target destinations that determine where specific feature flags should be enabled or disabled. These groups allow you to define granular rules for targeting environments, users, or accounts, making managing feature flag rollouts and experimentation easier.
The harness_platform_feature_flag_target_group resource enables you to define and manage Feature Flag Target Groups as code. Here's a basic example of how to use it:
resource "harness_platform_feature_flag_target_group" "example_target_group" {
org_id = "your-org-id"
project_id = "your-project-id"
identifier = "MY_FEATURE_GROUP"
environment = "MY_ENVIRONMENT"
name = "MY_FEATURE_TARGET_GROUP"
account_id = "MY_ACCOUNT_ID"
included = ["target_id_1"]
excluded = ["target_id_2"]
rule {
attribute = "MY_ATTRIBUTE"
operator = "equal"
value = "MY_VALUE"
}
}
In this example, we create a Feature Flag Target Group named "MY_FEATURE_TARGET_GROUP" associated with the feature identified as "MY_FEATURE_GROUP." We specify the organization, project, environment, account ID, included and excluded targets, and a rule for targeting specific destinations based on attributes.
Harness and Terraform provide extensive options for configuring Feature Flag Target Groups:
The harness_platform_feature_flag_target resource enables you to define and manage Feature Flag Targets as code. Here's a basic example of how to use it:
resource "harness_platform_feature_flag_target" "example_target" {
org_id = "your-org-id"
project_id = "your-project-id"
identifier = "MY_FEATURE"
environment = "MY_ENVIRONMENT"
name = "MY_FEATURE_TARGET"
account_id = "MY_ACCOUNT_ID"
attributes = { "foo": "bar"
}
}
This example defines a Feature Flag Target named "MY_FEATURE_TARGET" associated with the feature identified as "MY_FEATURE." We specify the organization, project, environment, account ID, and any additional attributes you want to associate with this target.
Harness and Terraform offer extensive options for configuring Feature Flag Targets:
Feature Flags are a fundamental part of modern software development practices, allowing you to effectively control feature rollouts and experimentation. Using the Harness Terraform Provider and the harness_platform_feature_flag resource, you can define, manage, and automate your Feature Flags, ensuring controlled and efficient feature management.
Start using Harness and Terraform to manage your Feature Flags as code today, and empower your development and operations teams with precise control over feature releases and experiments.
Sign up for a free trial of Harness Feature Flags today and start experiencing the benefits of reliable release management.