Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 1.5.1 release #53

Merged
merged 31 commits into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
dadc281
Prep for migration release (#75)
ldhenry Jul 31, 2020
843e397
Merge branch 'master' of github.com:launchdarkly/terraform-provider-l…
ldhenry Aug 3, 2020
43d9057
Add GH actions for release (#76)
ldhenry Aug 3, 2020
a1e36d5
Automatically add changelog entry to release (#77)
ldhenry Aug 3, 2020
0b33f62
Update go.mod and automatically set version header (#78)
ldhenry Aug 3, 2020
5aae790
Merge branch 'master' of github.com:launchdarkly/terraform-provider-l…
ldhenry Aug 3, 2020
fad8a7b
Add access tokens (#79)
Aug 21, 2020
d3dc2db
Release 1.4.0 (#80)
Aug 21, 2020
e11b96a
Ensure ommitted optional feature_flag_environment properties do not m…
ldhenry Sep 8, 2020
ad47f94
Merge branch 'master' of github.com:launchdarkly/terraform-provider-l…
ldhenry Sep 8, 2020
e2e7496
Merge branch 'master' of github.com:launchdarkly/terraform-provider-l…
ldhenry Sep 8, 2020
b459f74
Imiller/ch78293/make terraform project data source (#73)
sloloris Sep 15, 2020
a06a122
replace travis with circleCI to run full tests (#84)
sloloris Sep 18, 2020
e7c84ce
Imiller/ch78864/make environment data source (#83)
sloloris Sep 21, 2020
0fd4b76
Imiller/ch87115/make feature flag data source (#85)
sloloris Sep 21, 2020
69b6bc8
Imiller/ch88747/make feature flag environment a data source (#86)
sloloris Sep 22, 2020
7ee7355
fix error typo (#89)
sloloris Sep 22, 2020
06c45ef
Resolve issues with nested environments (#87)
ldhenry Sep 22, 2020
ad940f6
Imiller/ch87117/make webhook data source (#88)
sloloris Sep 24, 2020
a7089cf
Imiller/ch87116/make segment data source (#91)
sloloris Sep 24, 2020
e9b12b7
Add nested environments documentation (#90)
ldhenry Sep 28, 2020
f6249d3
Use GetOKExists for off_variation and improve feature_flag_environmen…
ldhenry Sep 28, 2020
ddfeabb
Add a json feature flag example with default variations (#94)
ldhenry Sep 28, 2020
ee4abc3
Imiller/ch90407/write docs for new data sources (#92)
sloloris Sep 29, 2020
913494a
merge conflict in changelog
sloloris Sep 29, 2020
33a97b7
Imiller/ch96679/figure out provider configuration for terraform (#96)
sloloris Jan 7, 2021
11a4651
Add support for number and boolean targeting rule clause values (#98)
ldhenry Mar 16, 2021
84bd635
Merge branch 'master' of github.com:launchdarkly/terraform-provider-l…
ldhenry Mar 16, 2021
8f86292
Fix percentage rollout weight in example (#99)
ldhenry Mar 16, 2021
8652c16
Prepare 1.5.1 release
ldhenry Mar 16, 2021
1d28943
correct year
ldhenry Mar 16, 2021
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
24 changes: 15 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [1.5.1] (March 16, 2021)

BUG FIXES:

- Fixed a bug preventing number and boolean values in targeting rules clauses from working. The new `value_type` attribute must be set in order to utilize number and boolean values. All values for a given targeting rule clause must be of the same type. [#51](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/51)

## [1.5.0] (September 29, 2020)

FEATURES:
Expand Down Expand Up @@ -74,13 +80,13 @@ BUG_FIXES:

BUG_FIXES:

- Improve handling of API rate limits. [#26](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/26)
- Improve handling of API rate limits. [#26](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/26)

## [1.3.0] (May 05, 2020)

FEATURES:

- Added `default_on_variation` and `default_off_variation` to `launchdarkly_feature_flag`. These optional attributes can be used to set the default targeting behavior for flags in newly created environments. [#10](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/10) [#18](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/18)
- Added `default_on_variation` and `default_off_variation` to `launchdarkly_feature_flag`. These optional attributes can be used to set the default targeting behavior for flags in newly created environments. [#10](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/10) [#18](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/18)

BUG_FIXES:

Expand All @@ -95,13 +101,13 @@ FEATURES:
BUG_FIXES:

- Fix non-empty plan after creating a `launchdarkly_team_member` with a custom role.
- Handle missing user target variations in `launchdarkly_feature_flag_environment` [#23](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/23)
- Handle missing user target variations in `launchdarkly_feature_flag_environment` [#23](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/23)

## [1.2.1] (April 14, 2020)

BUG_FIXES:

- Fix import bug in `launchdarkly_project` introduced in 1.2.0 [#21](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/21)
- Fix import bug in `launchdarkly_project` introduced in 1.2.0 [#21](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/21)

NOTES:

Expand All @@ -112,12 +118,12 @@ NOTES:
FEATURES:

- Add new resource `launchdarkly_destination`. This resource is used to manage LaunchDarkly data export destinations.
- Add `policy_statements` to `launchdarkly_webhook` and `launchdarkly_custom_role` [#16](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/16).
- Add `policy_statements` to `launchdarkly_webhook` and `launchdarkly_custom_role` [#16](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/16).

BUG_FIXES:

- Fixed bug preventing large number variations from being saved in the state correctly. [#14](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/14)
- Fixed bug in import validation. [#19](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/19)
- Fixed bug preventing large number variations from being saved in the state correctly. [#14](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/14)
- Fixed bug in import validation. [#19](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/19)

NOTES:

Expand Down Expand Up @@ -153,7 +159,7 @@ BUG FIXES:

FEATURES:

- Add tags attribute to `resource_launchdarkly_environment`. [#5](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/5)
- Add tags attribute to `resource_launchdarkly_environment`. [#5](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/5)
- Add `maintainer_id` input validation.

ENHANCEMENTS:
Expand All @@ -162,7 +168,7 @@ ENHANCEMENTS:

BUG FIXES:

- Allow flag `maintainer_id` to be unset. [#6](https://github.com/terraform-providers/terraform-provider-launchdarkly/issues/6)
- Allow flag `maintainer_id` to be unset. [#6](https://github.com/launchdarkly/terraform-provider-launchdarkly/issues/6)
- Fix typo in initialization error message. Thanks @jen20
- Flags created with invalid schema are deleted instead of left dangling.

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

---

Clone repository to: `$GOPATH/src/github.com/terraform-providers/terraform-provider-launchdarkly`
Clone repository to: `$GOPATH/src/github.com/launchdarkly/terraform-provider-launchdarkly`

```sh
$ git clone [email protected]:terraform-providers/terraform-provider-launchdarkly $GOPATH/src/github.com/terraform-providers/terraform-provider-launchdarkly
$ git clone [email protected]:launchdarkly/terraform-provider-launchdarkly $GOPATH/src/github.com/launchdarkly/terraform-provider-launchdarkly
```

Enter the provider directory and build the provider

```sh
$ cd $GOPATH/src/github.com/terraform-providers/terraform-provider-launchdarkly
$ cd $GOPATH/src/github.com/launchdarkly/terraform-provider-launchdarkly
$ make build
```

Expand Down
34 changes: 28 additions & 6 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,57 @@
# terraform-provider-launchdarkly examples
Example LD project configured using the LD Terraform provider

Example LaunchDarkly project configured using the LaunchDarkly Terraform provider

## Overview

This repository contains a series of directories containing detailed examples of how to configure LaunchDarkly via the Terraform provider. [Click here](https://www.terraform.io/docs/providers/launchdarkly/index.html) for the official documentation on the Terraform website. A description of the examples included here can be found in the [Contents](#contents) section.

> ! TAKE NOTE! Running `terraform apply` on any of these directories with your auth credentials will result in real resources being created that may cost real money. These are meant to be used as examples only and LaunchDarkly is not responsible for any costs incurred via testing.

Before getting started with the LaunchDarkly Terraform provider, make sure you have Terraform correctly installed and configured. For more on this, see the [Setup](#setup) section.

## Contents

- [full_config](./full_config) contains an example of a simple but fully fleshed-out LaunchDarkly [project](https://docs.launchdarkly.com/home/managing-flags/projects) configuration, including [environments](https://docs.launchdarkly.com/home/managing-flags/environments), [feature flags](https://docs.launchdarkly.com/home/managing-flags), [team members](https://docs.launchdarkly.com/home/account-security/managing-your-team), [roles](https://docs.launchdarkly.com/home/account-security/custom-roles), and [segments](https://docs.launchdarkly.com/home/managing-users/segments). It also provides an example of how to organize a more complex configuration with multiple resources.
- [multiple_projects](./multiple_projects) contains an example of the simultaneous configuration of multiple [projects](https://docs.launchdarkly.com/home/managing-flags/projects) and associated [environments](https://docs.launchdarkly.com/home/managing-flags/environments) and [flags](https://docs.launchdarkly.com/home/managing-flags) in a single file.
- [custom_role](./custom_role) contains an example of how to configure a [custom role](https://docs.launchdarkly.com/home/account-security/custom-roles) within LaunchDarkly using Terraform.
- [custom_role](./custom_role) contains an example of how to configure a [custom role](https://docs.launchdarkly.com/home/account-security/custom-roles) within LaunchDarkly using Terraform.
- [feature_flags](./feature_flags) contains a full range of flag examples, covering both [flag variation types](https://docs.launchdarkly.com/home/managing-flags/flag-variations) and complex [targeting rules](https://docs.launchdarkly.com/home/managing-flags/targeting-users).
- [webhook](./webhook) contains an example of a [LaunchDarkly webhook](https://docs.launchdarkly.com/integrations/webhooks) configuration to send LD event notifications to an external endpoint.

- For an example of how to configure your provider if using Terraform version 0.13 or above, please see the [terraform_0.13](./terraform_0.13).

## Setup

### Install Terraform
First and foremost, you need to make sure you have Terraform installed on the machine you will be applying the configurations from and that you meet the requirements listed on the [project readme](https://github.com/terraform-providers/terraform-provider-launchdarkly#requirements). For instructions on how to install Terraform, [see here](https://learn.hashicorp.com/terraform/getting-started/install.html).

First and foremost, you need to make sure you have Terraform installed on the machine you will be applying the configurations from and that you meet the requirements listed on the [project readme](https://github.com/launchdarkly/terraform-provider-launchdarkly#requirements). For instructions on how to install Terraform, [see here](https://learn.hashicorp.com/terraform/getting-started/install.html).

### Configure LD Credentials
Before getting started with the LaunchDarkly provider, you need to ensure you have your LaunchDarkly credentials properly set up. All you will need for this is a LaunchDarkly access token, which you can create via the LaunchDarkly platform under Account settings > Authorization.

Before getting started with the LaunchDarkly provider, you need to ensure you have your LaunchDarkly credentials properly set up. All you will need for this is a LaunchDarkly access token, which you can create via the LaunchDarkly platform under Account settings > Authorization.

Once you have your access token in hand, there are several ways to set variables within your Terraform context. For the sake of ease, we've set the access token as an environmental variable named `LAUNCHDARKLY_ACCESS_TOKEN`. The provider configuration will then automatically access it from your environment so that your provider config should only have to contain

```
provider "launchdarkly" {
version = "~> 1.0"
}
```
Some resources or attributes, such as [webhook policy_statements](./webhook/example.tf), that were added later may require a later version; check the [changelog](https://github.com/terraform-providers/terraform-provider-launchdarkly/blob/master/CHANGELOG.md) for more information on versions.

If you would prefer to define your variables some other way, see [Terraform's documentation on input variables](https://learn.hashicorp.com/terraform/getting-started/variables) for some other ways to do so.
> ! TAKE NOTE! If you are using Terraform version 0.13 or above, your provider block will be nested inside of your `terraform` block as seen below.

```
terraform {
required_providers {
launchdarkly = {
source = "launchdarkly/launchdarkly"
version = "~> 1.5"
}
}
required_version = ">= 0.13"
}
```

Some resources or attributes, such as [webhook policy_statements](./webhook/example.tf), that were added later may require a provider version later than 1.0; check the [changelog](https://github.com/launchdarkly/terraform-provider-launchdarkly/blob/master/CHANGELOG.md) for more information on versions.

If you would prefer to define your variables some other way, see [Terraform's documentation on input variables](https://learn.hashicorp.com/terraform/getting-started/variables) for some other ways to do so.
4 changes: 2 additions & 2 deletions examples/feature_flags/targeting_example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ resource "launchdarkly_feature_flag_environment" "prereq_flag" {
# The rules block of this resource determines that the 0-index variation ("string1") will
# be served to users whose names start with the letters a-e.
# flag_fallthrough describes the default to serve if none of the other rules apply:
# in this case, the percentage of users who will be served each variation (must sum to 1000000).
# in this case, the percentage of users who will be served each variation (must sum to 100000).
# Use of the bucket_by attribute ensures that all users with the same company will be served the
# same variation within the rollout buckets.
resource "launchdarkly_feature_flag_environment" "user_targeting_flag" {
Expand Down Expand Up @@ -62,4 +62,4 @@ resource "launchdarkly_feature_flag_environment" "user_targeting_flag" {
rollout_weights = [60000, 30000, 10000]
bucket_by = "company"
}
}
}
8 changes: 8 additions & 0 deletions examples/terraform_0.13/project.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
resource "launchdarkly_project" "tf_13_example" {
key = "tf-13-example"
name = "Terraform 13 Example"

tags = [
"terraform"
]
}
9 changes: 9 additions & 0 deletions examples/terraform_0.13/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_providers {
launchdarkly = {
source = "launchdarkly/launchdarkly"
version = "~> 1.5"
}
}
required_version = ">= 0.13"
}
124 changes: 111 additions & 13 deletions launchdarkly/clause_helper.go
Original file line number Diff line number Diff line change
@@ -1,33 +1,57 @@
package launchdarkly

import (
"fmt"
"reflect"
"strconv"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
ldapi "github.com/launchdarkly/api-client-go"
)

const (
BOOL_CLAUSE_VALUE = "boolean"
STRING_CLAUSE_VALUE = "string"
NUMBER_CLAUSE_VALUE = "number"
)

func clauseSchema() *schema.Schema {
return &schema.Schema{
Type: schema.TypeList,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"attribute": {
ATTRIBUTE: {
Type: schema.TypeString,
Required: true,
},
"op": {
OP: {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateOp(),
},
"values": {
VALUES: {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Required: true,
},
"negate": {
VALUE_TYPE: {
Type: schema.TypeString,
Default: STRING_CLAUSE_VALUE,
Optional: true,
ValidateFunc: validation.StringInSlice(
[]string{
BOOL_CLAUSE_VALUE,
STRING_CLAUSE_VALUE,
NUMBER_CLAUSE_VALUE,
},
false,
),
},
NEGATE: {
Type: schema.TypeBool,
Required: true,
},
Expand All @@ -36,27 +60,101 @@ func clauseSchema() *schema.Schema {
}
}

func clauseFromResourceData(val interface{}) ldapi.Clause {
func clauseFromResourceData(val interface{}) (ldapi.Clause, error) {
clauseMap := val.(map[string]interface{})
c := ldapi.Clause{
Attribute: clauseMap[ATTRIBUTE].(string),
Op: clauseMap[OP].(string),
Negate: clauseMap[NEGATE].(bool),
}
c.Values = append(c.Values, clauseMap[VALUES].([]interface{})...)
return c
valueType := clauseMap[VALUE_TYPE].(string)
values, err := clauseValuesFromResourceData(clauseMap[VALUES].([]interface{}), valueType)
if err != nil {
return c, err
}
c.Values = values
return c, nil
}

func clauseValuesFromResourceData(schemaValues []interface{}, valueType string) ([]interface{}, error) {
typedValues := make([]interface{}, 0, len(schemaValues))
for _, schemaValue := range schemaValues {
strValue, ok := schemaValue.(string)
if !ok {
return nil, fmt.Errorf("invalid clause value: %v", schemaValue)
}
v, err := clauseValueFromResourceData(strValue, valueType)
if err != nil {
return nil, err
}
typedValues = append(typedValues, v)
}
return typedValues, nil
}

func clauseValueFromResourceData(strValue string, valueType string) (interface{}, error) {
switch valueType {
case STRING_CLAUSE_VALUE:
return strValue, nil
case BOOL_CLAUSE_VALUE:
return convertBoolStringToBool(strValue)
case NUMBER_CLAUSE_VALUE:
return convertNumberStringToFloat(strValue)
}
return nil, fmt.Errorf("invalid clause value type %q", valueType)
}

func convertBoolStringToBool(boolStr string) (bool, error) {
switch boolStr {
case "true":
return true, nil
case "false":
return false, nil
}
return false, fmt.Errorf("invalid boolean string %q", boolStr)
}

func convertNumberStringToFloat(numStr string) (float64, error) {
num, err := strconv.ParseFloat(numStr, 64)
if err != nil {
return num, fmt.Errorf("invalid number string %q", numStr)
}
return num, nil
}

func clausesToResourceData(clauses []ldapi.Clause) interface{} {
func clausesToResourceData(clauses []ldapi.Clause) (interface{}, error) {
transformed := make([]interface{}, len(clauses))

for i, c := range clauses {
var err error
var valueType string
strValues := make([]interface{}, 0, len(c.Values))
for _, v := range c.Values {
valueType, err = inferClauseValueTypeFromValue(v)
if err != nil {
return transformed, err
}
strValues = append(strValues, stringifyValue(v))
}
transformed[i] = map[string]interface{}{
ATTRIBUTE: c.Attribute,
OP: c.Op,
VALUES: c.Values,
NEGATE: c.Negate,
ATTRIBUTE: c.Attribute,
OP: c.Op,
VALUES: strValues,
VALUE_TYPE: valueType,
NEGATE: c.Negate,
}
}
return transformed
return transformed, nil
}

func inferClauseValueTypeFromValue(value interface{}) (string, error) {
switch value.(type) {
case bool:
return BOOL_CLAUSE_VALUE, nil
case string:
return STRING_CLAUSE_VALUE, nil
case float64:
return NUMBER_CLAUSE_VALUE, nil
}
return "", fmt.Errorf("unknown clause value type: %q", reflect.TypeOf(value))
}
Loading