diff --git a/.go-version b/.go-version index 1b92e588..f5b00dc2 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.19.3 +1.20.3 diff --git a/docs/data-sources/audit_log_subscription.md b/docs/data-sources/audit_log_subscription.md index 8f68bca5..eac9873c 100644 --- a/docs/data-sources/audit_log_subscription.md +++ b/docs/data-sources/audit_log_subscription.md @@ -28,7 +28,7 @@ data "launchdarkly_audit_log_subscription" "test" { ### Required - `id` (String) The audit log subscription ID. -- `integration_key` (String) The integration key. Supported integration keys are `cloudtrail`, `datadog`, `dynatrace`, `elastic`, `grafana`, `honeycomb`, `logdna`, `msteams`, `new-relic-apm`, `signalfx`, `slack`, and `splunk`. +- `integration_key` (String) The integration key. Supported integration keys are `chronosphere`, `cloudtrail`, `datadog`, `dynatrace`, `elastic`, `grafana`, `honeycomb`, `logdna`, `msteams`, `new-relic-apm`, `signalfx`, `slack`, and `splunk`. ### Read-Only diff --git a/docs/data-sources/feature_flag.md b/docs/data-sources/feature_flag.md index abc0d2ac..8df6a170 100644 --- a/docs/data-sources/feature_flag.md +++ b/docs/data-sources/feature_flag.md @@ -30,6 +30,11 @@ data "launchdarkly_feature_flag" "example" { - `key` (String) The unique feature flag key that references the flag in your application code. - `project_key` (String) The feature flag's project key. +### Optional + +- `maintainer_id` (String) The feature flag maintainer's 24 character alphanumeric team member ID. `maintainer_team_key` cannot be set if `maintainer_id` is set. If neither is set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer. +- `maintainer_team_key` (String) The key of the associated team that maintains this feature flag. `maintainer_id` cannot be set if `maintainer_team_key` is set + ### Read-Only - `archived` (Boolean) Specifies whether the flag is archived or not. Note that you cannot create a new flag that is archived, but can update a flag to be archived. @@ -39,7 +44,6 @@ data "launchdarkly_feature_flag" "example" { - `description` (String) The feature flag's description. - `id` (String) The ID of this resource. - `include_in_snippet` (Boolean, Deprecated) Specifies whether this flag should be made available to the client-side JavaScript SDK using the client-side Id. This value gets its default from your project configuration if not set. `include_in_snippet` is now deprecated. Please migrate to `client_side_availability.using_environment_id` to maintain future compatibility. -- `maintainer_id` (String) The feature flag maintainer's 24 character alphanumeric team member ID. If not set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer. - `name` (String) The feature flag's human-readable name - `tags` (Set of String) Tags associated with your resource. - `temporary` (Boolean) Specifies whether the flag is a temporary flag. diff --git a/docs/resources/audit_log_subscription.md b/docs/resources/audit_log_subscription.md index fb30d813..682e0fc6 100644 --- a/docs/resources/audit_log_subscription.md +++ b/docs/resources/audit_log_subscription.md @@ -41,7 +41,7 @@ resource "launchdarkly_audit_log_subscription" "example" { ### Required - `config` (Map of String) The set of configuration fields corresponding to the value defined for `integration_key`. Refer to the `formVariables` field in the corresponding `integrations//manifest.json` file in [this repo](https://github.com/launchdarkly/integration-framework/tree/master/integrations) for a full list of fields for the integration you wish to configure. **IMPORTANT**: Please note that Terraform will only accept these in snake case, regardless of the case shown in the manifest. -- `integration_key` (String) The integration key. Supported integration keys are `cloudtrail`, `datadog`, `dynatrace`, `elastic`, `grafana`, `honeycomb`, `logdna`, `msteams`, `new-relic-apm`, `signalfx`, `slack`, and `splunk`. A change in this field will force the destruction of the existing resource and the creation of a new one. +- `integration_key` (String) The integration key. Supported integration keys are `chronosphere`, `cloudtrail`, `datadog`, `dynatrace`, `elastic`, `grafana`, `honeycomb`, `logdna`, `msteams`, `new-relic-apm`, `signalfx`, `slack`, and `splunk`. A change in this field will force the destruction of the existing resource and the creation of a new one. - `name` (String) A human-friendly name for your audit log subscription viewable from within the LaunchDarkly Integrations page. - `on` (Boolean) Whether or not you want your subscription enabled, i.e. to actively send events. - `statements` (Block List, Min: 1) A block representing the resources to which you wish to subscribe. (see [below for nested schema](#nestedblock--statements)) diff --git a/docs/resources/feature_flag.md b/docs/resources/feature_flag.md index b20092c0..dd311843 100644 --- a/docs/resources/feature_flag.md +++ b/docs/resources/feature_flag.md @@ -97,7 +97,8 @@ resource "launchdarkly_feature_flag" "json_example" { - `defaults` (Block List, Max: 1) A block containing the indices of the variations to be used as the default on and off variations in all new environments. Flag configurations in existing environments will not be changed nor updated if the configuration block is removed. (see [below for nested schema](#nestedblock--defaults)) - `description` (String) The feature flag's description. - `include_in_snippet` (Boolean, Deprecated) Specifies whether this flag should be made available to the client-side JavaScript SDK using the client-side Id. This value gets its default from your project configuration if not set. `include_in_snippet` is now deprecated. Please migrate to `client_side_availability.using_environment_id` to maintain future compatibility. -- `maintainer_id` (String) The feature flag maintainer's 24 character alphanumeric team member ID. If not set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer. +- `maintainer_id` (String) The feature flag maintainer's 24 character alphanumeric team member ID. `maintainer_team_key` cannot be set if `maintainer_id` is set. If neither is set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer. +- `maintainer_team_key` (String) The key of the associated team that maintains this feature flag. `maintainer_id` cannot be set if `maintainer_team_key` is set - `tags` (Set of String) Tags associated with your resource. - `temporary` (Boolean) Specifies whether the flag is a temporary flag. - `variations` (Block List) An array of possible variations for the flag (see [below for nested schema](#nestedblock--variations)) diff --git a/go.mod b/go.mod index 644a5c66..632b5538 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/bgentry/speakeasy v0.1.0 // indirect - github.com/cloudflare/circl v1.3.3 // indirect + github.com/cloudflare/circl v1.3.7 // indirect github.com/dave/dst v0.26.2 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fatih/color v1.13.0 // indirect @@ -52,7 +52,7 @@ require ( github.com/huandu/xstrings v1.3.2 // indirect github.com/imdario/mergo v0.3.13 // indirect github.com/jackc/sqlfmt v0.1.1-0.20191221211249-d576133216e1 // indirect - github.com/launchdarkly/api-client-go/v12 v12.0.0 + github.com/launchdarkly/api-client-go/v14 v14.0.0 github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.16 // indirect github.com/mitchellh/cli v1.1.5 // indirect @@ -73,13 +73,13 @@ require ( github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/zclconf/go-cty v1.13.2 // indirect - golang.org/x/crypto v0.14.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect golang.org/x/mod v0.11.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/oauth2 v0.7.0 // indirect - golang.org/x/sys v0.13.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.6.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect diff --git a/go.sum b/go.sum index 5a7305f8..49035c9a 100644 --- a/go.sum +++ b/go.sum @@ -133,8 +133,8 @@ github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6D github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cloudflare/circl v1.1.0/go.mod h1:prBCrKB9DV4poKZY1l9zBXg2QJY7mvgRvtMxxK7fi4I= -github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs= -github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= +github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= +github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -515,8 +515,8 @@ github.com/kunwardeep/paralleltest v1.0.3/go.mod h1:vLydzomDFpk7yu5UX02RmP0H8QfR github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/kyoh86/exportloopref v0.1.8/go.mod h1:1tUcJeiioIs7VWe5gcOObrux3lb66+sBqGZrRkMwPgg= -github.com/launchdarkly/api-client-go/v12 v12.0.0 h1:GiP3gvsLddl9VpFoz8JARP8MQi/0gsQSTg7scyIpJKY= -github.com/launchdarkly/api-client-go/v12 v12.0.0/go.mod h1:gAIb6T7YFMu8qb5V4nVwvYfe3sWQHg0SNr0kWL10KNA= +github.com/launchdarkly/api-client-go/v14 v14.0.0 h1:fZfi5zKwgjpaOgK4NKcU5mJT2C8sYsR8nnuJYTaFvNU= +github.com/launchdarkly/api-client-go/v14 v14.0.0/go.mod h1:K7ejD5nn9ar94p/5qrQ0t9iJygdIQyH70U9M9rYvw5Y= github.com/ldez/gomoddirectives v0.2.2/go.mod h1:cpgBogWITnCfRq2qGoDkKMEVSaarhdBr6g8G04uz6d0= github.com/ldez/tagliatelle v0.3.0/go.mod h1:8s6WJQwEYHbKZDsp/LjArytKOG8qaMrKQQ3mFukHs88= github.com/leonklingele/grouper v1.1.0/go.mod h1:uk3I3uDfi9B6PeUjsCKi6ndcf63Uy7snXgR4yDYQVDY= @@ -863,8 +863,8 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc= -golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1086,12 +1086,12 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220209214540-3681064d5158/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= -golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -1101,8 +1101,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/launchdarkly/approvals_helper.go b/launchdarkly/approvals_helper.go index bfacd584..21f73ba4 100644 --- a/launchdarkly/approvals_helper.go +++ b/launchdarkly/approvals_helper.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type approvalSchemaOptions struct { diff --git a/launchdarkly/audit_log_subscription_configs_generated.go b/launchdarkly/audit_log_subscription_configs_generated.go index 392688a0..18ce8def 100644 --- a/launchdarkly/audit_log_subscription_configs_generated.go +++ b/launchdarkly/audit_log_subscription_configs_generated.go @@ -3,6 +3,24 @@ package launchdarkly var SUBSCRIPTION_CONFIGURATION_FIELDS = map[string]IntegrationConfig{ + "chronosphere": { + "receiverURL": { + AllowedValues: []string{}, + DefaultValue: nil, + Description: "Your Chronosphere receiver URL. Should look like https://{MY_COMPANY}.chronosphere.io/api/v1/data/events/receiver/launchdarkly", + IsOptional: false, + IsSecret: false, + Type: "string", + }, + "secretToken": { + AllowedValues: []string{}, + DefaultValue: nil, + Description: "Enter your Chronosphere secret token.", + IsOptional: false, + IsSecret: true, + Type: "string", + }, + }, "cloudtrail": { "accountId": { AllowedValues: []string{}, diff --git a/launchdarkly/clause_helper.go b/launchdarkly/clause_helper.go index 8b7bd4c8..e1ab1bc4 100644 --- a/launchdarkly/clause_helper.go +++ b/launchdarkly/clause_helper.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) const ( diff --git a/launchdarkly/clause_helper_test.go b/launchdarkly/clause_helper_test.go index 96e1f4bd..38f64976 100644 --- a/launchdarkly/clause_helper_test.go +++ b/launchdarkly/clause_helper_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/config.go b/launchdarkly/config.go index d522c866..2e4b11d8 100644 --- a/launchdarkly/config.go +++ b/launchdarkly/config.go @@ -11,7 +11,7 @@ import ( "time" retryablehttp "github.com/hashicorp/go-retryablehttp" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) //nolint:staticcheck // The version string gets updated at build time using -ldflags diff --git a/launchdarkly/custom_properties_helper.go b/launchdarkly/custom_properties_helper.go index be808990..4845e047 100644 --- a/launchdarkly/custom_properties_helper.go +++ b/launchdarkly/custom_properties_helper.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // https://docs.launchdarkly.com/home/connecting/custom-properties diff --git a/launchdarkly/custom_properties_helper_test.go b/launchdarkly/custom_properties_helper_test.go index a493be10..c940dc5d 100644 --- a/launchdarkly/custom_properties_helper_test.go +++ b/launchdarkly/custom_properties_helper_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_audit_log_subscription_test.go b/launchdarkly/data_source_launchdarkly_audit_log_subscription_test.go index 6e48e13c..4b742215 100644 --- a/launchdarkly/data_source_launchdarkly_audit_log_subscription_test.go +++ b/launchdarkly/data_source_launchdarkly_audit_log_subscription_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_environment_test.go b/launchdarkly/data_source_launchdarkly_environment_test.go index ecf236dc..41eb4324 100644 --- a/launchdarkly/data_source_launchdarkly_environment_test.go +++ b/launchdarkly/data_source_launchdarkly_environment_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_feature_flag_environment_test.go b/launchdarkly/data_source_launchdarkly_feature_flag_environment_test.go index 4db1b580..b0566526 100644 --- a/launchdarkly/data_source_launchdarkly_feature_flag_environment_test.go +++ b/launchdarkly/data_source_launchdarkly_feature_flag_environment_test.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_feature_flag_test.go b/launchdarkly/data_source_launchdarkly_feature_flag_test.go index f6d0dbac..f1ed7a4e 100644 --- a/launchdarkly/data_source_launchdarkly_feature_flag_test.go +++ b/launchdarkly/data_source_launchdarkly_feature_flag_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_flag_trigger_test.go b/launchdarkly/data_source_launchdarkly_flag_trigger_test.go index 574fdb61..16ab4b45 100644 --- a/launchdarkly/data_source_launchdarkly_flag_trigger_test.go +++ b/launchdarkly/data_source_launchdarkly_flag_trigger_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_metric_test.go b/launchdarkly/data_source_launchdarkly_metric_test.go index e4d12667..f8a17da0 100644 --- a/launchdarkly/data_source_launchdarkly_metric_test.go +++ b/launchdarkly/data_source_launchdarkly_metric_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) @@ -39,7 +39,7 @@ func testAccDataSourceMetricScaffold(client *Client, betaClient *Client, project } // Add the additional context kinds to the project contextKindPayload := ldapi.UpsertContextKindPayload{Name: randomizationUnit} - _, _, err = betaClient.ld.ContextsBetaApi.PutContextKind(betaClient.ctx, project.Key, randomizationUnit).UpsertContextKindPayload(contextKindPayload).Execute() + _, _, err = client.ld.ContextsApi.PutContextKind(client.ctx, project.Key, randomizationUnit).UpsertContextKindPayload(contextKindPayload).Execute() if err != nil { return nil, err } diff --git a/launchdarkly/data_source_launchdarkly_project_test.go b/launchdarkly/data_source_launchdarkly_project_test.go index bc245602..99d1d977 100644 --- a/launchdarkly/data_source_launchdarkly_project_test.go +++ b/launchdarkly/data_source_launchdarkly_project_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_relay_proxy_configuration_test.go b/launchdarkly/data_source_launchdarkly_relay_proxy_configuration_test.go index b1955dbd..e0dd813f 100644 --- a/launchdarkly/data_source_launchdarkly_relay_proxy_configuration_test.go +++ b/launchdarkly/data_source_launchdarkly_relay_proxy_configuration_test.go @@ -7,7 +7,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_segment_test.go b/launchdarkly/data_source_launchdarkly_segment_test.go index a3c0bba3..12ce2281 100644 --- a/launchdarkly/data_source_launchdarkly_segment_test.go +++ b/launchdarkly/data_source_launchdarkly_segment_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_team.go b/launchdarkly/data_source_launchdarkly_team.go index c1a3895b..adc552f1 100644 --- a/launchdarkly/data_source_launchdarkly_team.go +++ b/launchdarkly/data_source_launchdarkly_team.go @@ -88,7 +88,7 @@ func dataSourceTeamRead(ctx context.Context, d *schema.ResourceData, meta interf projects := make([]string, len(team.Projects.Items)) for i, v := range team.Projects.Items { - projects[i] = *v.Key + projects[i] = v.Key } customRoleKeys := make([]string, len(team.Roles.Items)) diff --git a/launchdarkly/data_source_launchdarkly_team_member.go b/launchdarkly/data_source_launchdarkly_team_member.go index 035d7fa9..9b4fc594 100644 --- a/launchdarkly/data_source_launchdarkly_team_member.go +++ b/launchdarkly/data_source_launchdarkly_team_member.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func memberSchema() map[string]*schema.Schema { diff --git a/launchdarkly/data_source_launchdarkly_team_member_test.go b/launchdarkly/data_source_launchdarkly_team_member_test.go index dba22c2d..de30a4a9 100644 --- a/launchdarkly/data_source_launchdarkly_team_member_test.go +++ b/launchdarkly/data_source_launchdarkly_team_member_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_team_members.go b/launchdarkly/data_source_launchdarkly_team_members.go index e06aadfe..ad529da6 100644 --- a/launchdarkly/data_source_launchdarkly_team_members.go +++ b/launchdarkly/data_source_launchdarkly_team_members.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func dataSourceTeamMembers() *schema.Resource { diff --git a/launchdarkly/data_source_launchdarkly_team_members_test.go b/launchdarkly/data_source_launchdarkly_team_members_test.go index 59d39b82..c3dae39c 100644 --- a/launchdarkly/data_source_launchdarkly_team_members_test.go +++ b/launchdarkly/data_source_launchdarkly_team_members_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_team_test.go b/launchdarkly/data_source_launchdarkly_team_test.go index 568079b9..fbce3492 100644 --- a/launchdarkly/data_source_launchdarkly_team_test.go +++ b/launchdarkly/data_source_launchdarkly_team_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/data_source_launchdarkly_webhook_test.go b/launchdarkly/data_source_launchdarkly_webhook_test.go index c9a0688b..5e597f78 100644 --- a/launchdarkly/data_source_launchdarkly_webhook_test.go +++ b/launchdarkly/data_source_launchdarkly_webhook_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/default_variations_helper.go b/launchdarkly/default_variations_helper.go index 9922ad4f..74cc06d9 100644 --- a/launchdarkly/default_variations_helper.go +++ b/launchdarkly/default_variations_helper.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func defaultVariationsFromResourceData(d *schema.ResourceData) (*ldapi.Defaults, error) { diff --git a/launchdarkly/default_variations_helper_test.go b/launchdarkly/default_variations_helper_test.go index fafd49b6..7272492f 100644 --- a/launchdarkly/default_variations_helper_test.go +++ b/launchdarkly/default_variations_helper_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/environments_helper.go b/launchdarkly/environments_helper.go index 9a9e8bc6..025b39e0 100644 --- a/launchdarkly/environments_helper.go +++ b/launchdarkly/environments_helper.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type environmentSchemaOptions struct { diff --git a/launchdarkly/environments_helper_test.go b/launchdarkly/environments_helper_test.go index 39a06fdc..f592387f 100644 --- a/launchdarkly/environments_helper_test.go +++ b/launchdarkly/environments_helper_test.go @@ -3,7 +3,7 @@ package launchdarkly import ( "testing" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/fallthrough_helper.go b/launchdarkly/fallthrough_helper.go index c6c1b5b3..94e952c2 100644 --- a/launchdarkly/fallthrough_helper.go +++ b/launchdarkly/fallthrough_helper.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // In the LD model, this corresponds to the VariationOrRollout type diff --git a/launchdarkly/feature_flag_environment_helper.go b/launchdarkly/feature_flag_environment_helper.go index ddceb73f..6d278d91 100644 --- a/launchdarkly/feature_flag_environment_helper.go +++ b/launchdarkly/feature_flag_environment_helper.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type featureFlagEnvSchemaOptions struct { diff --git a/launchdarkly/feature_flags_helper.go b/launchdarkly/feature_flags_helper.go index 72eeb634..bbe15587 100644 --- a/launchdarkly/feature_flags_helper.go +++ b/launchdarkly/feature_flags_helper.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type featureFlagSchemaOptions struct { @@ -34,10 +34,19 @@ func baseFeatureFlagSchema(options featureFlagSchemaOptions) map[string]*schema. }, MAINTAINER_ID: { Type: schema.TypeString, - Optional: !options.isDataSource, + Optional: true, Computed: true, - Description: "The feature flag maintainer's 24 character alphanumeric team member ID. If not set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer.", + Description: "The feature flag maintainer's 24 character alphanumeric team member ID. `maintainer_team_key` cannot be set if `maintainer_id` is set. If neither is set, it will automatically be or stay set to the member ID associated with the API key used by your LaunchDarkly Terraform provider or the most recently-set maintainer.", ValidateDiagFunc: validateID(), + ConflictsWith: []string{MAINTAINER_TEAM_KEY}, + }, + MAINTAINER_TEAM_KEY: { + Type: schema.TypeString, + Optional: true, + Computed: true, + Description: "The key of the associated team that maintains this feature flag. `maintainer_id` cannot be set if `maintainer_team_key` is set", + ValidateDiagFunc: validateKeyAndLength(int(1), int(256)), + ConflictsWith: []string{MAINTAINER_ID}, }, DESCRIPTION: { Type: schema.TypeString, @@ -166,9 +175,11 @@ func featureFlagRead(ctx context.Context, d *schema.ResourceData, raw interface{ _ = d.Set(CLIENT_SIDE_AVAILABILITY, clientSideAvailability) _ = d.Set(INCLUDE_IN_SNIPPET, CSA.UsingEnvironmentId) - // Only set the maintainer ID if is specified in the schema - _, ok := d.GetOk(MAINTAINER_ID) - if ok { + // Only set the maintainer if is specified in the schema + _, maintainerIdOk := d.GetOk(MAINTAINER_ID) + _, maintainerTeamKeyOk := d.GetOk(MAINTAINER_TEAM_KEY) + if maintainerIdOk || maintainerTeamKeyOk { + _ = d.Set(MAINTAINER_TEAM_KEY, flag.MaintainerTeamKey) _ = d.Set(MAINTAINER_ID, flag.MaintainerId) } diff --git a/launchdarkly/helper.go b/launchdarkly/helper.go index 0b638225..4db10d50 100644 --- a/launchdarkly/helper.go +++ b/launchdarkly/helper.go @@ -8,7 +8,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) var randomRetrySleepSeeded = false diff --git a/launchdarkly/keys.go b/launchdarkly/keys.go index a91efd3c..e3850730 100644 --- a/launchdarkly/keys.go +++ b/launchdarkly/keys.go @@ -65,6 +65,7 @@ const ( LAST_NAME = "last_name" MAINTAINERS = "maintainers" MAINTAINER_ID = "maintainer_id" + MAINTAINER_TEAM_KEY = "maintainer_team_key" MEMBER_IDS = "member_ids" MIN_NUM_APPROVALS = "min_num_approvals" MOBILE_KEY = "mobile_key" diff --git a/launchdarkly/metrics_helper.go b/launchdarkly/metrics_helper.go index 0cc935f3..9b926215 100644 --- a/launchdarkly/metrics_helper.go +++ b/launchdarkly/metrics_helper.go @@ -10,7 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func baseMetricSchema(isDataSource bool) map[string]*schema.Schema { diff --git a/launchdarkly/policies_helper.go b/launchdarkly/policies_helper.go index f82575ec..da3c0263 100644 --- a/launchdarkly/policies_helper.go +++ b/launchdarkly/policies_helper.go @@ -5,7 +5,7 @@ import ( "sort" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func policyArraySchema() *schema.Schema { diff --git a/launchdarkly/policy_statements_helper.go b/launchdarkly/policy_statements_helper.go index 64b9e1b3..2c7c5135 100644 --- a/launchdarkly/policy_statements_helper.go +++ b/launchdarkly/policy_statements_helper.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // policyStatementSchemaOptions is used to help with renaming 'policy_statements' to statements for the launchdarkly_webhook resource. diff --git a/launchdarkly/policy_statements_helper_test.go b/launchdarkly/policy_statements_helper_test.go index 225a7f4d..ceec38cf 100644 --- a/launchdarkly/policy_statements_helper_test.go +++ b/launchdarkly/policy_statements_helper_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/prerequisite_helper.go b/launchdarkly/prerequisite_helper.go index 82c67203..5e9b094c 100644 --- a/launchdarkly/prerequisite_helper.go +++ b/launchdarkly/prerequisite_helper.go @@ -5,7 +5,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func prerequisitesSchema(isDataSource bool) *schema.Schema { diff --git a/launchdarkly/project_helper.go b/launchdarkly/project_helper.go index 04efde50..0c7af42a 100644 --- a/launchdarkly/project_helper.go +++ b/launchdarkly/project_helper.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func projectRead(ctx context.Context, d *schema.ResourceData, meta interface{}, isDataSource bool) diag.Diagnostics { @@ -125,7 +125,7 @@ func getAllEnvironments(client *Client, projectKey string) (ldapi.Environments, envPage, resp, err := client.ld.EnvironmentsApi.GetEnvironmentsByProject( client.ctx, projectKey).Limit(pageLimit).Offset(currentPage * pageLimit).Execute() if err != nil { - return *ldapi.NewEnvironments(), resp, err + return *ldapi.NewEnvironments(envItems), resp, err } envItems = append(envItems, envPage.Items...) if len(envItems) >= int(envPage.GetTotalCount()) { @@ -133,8 +133,7 @@ func getAllEnvironments(client *Client, projectKey string) (ldapi.Environments, } } - envs := *ldapi.NewEnvironments() - envs.SetItems(envItems) + envs := *ldapi.NewEnvironments(envItems) envs.SetTotalCount(int32(len(envItems))) return envs, nil, nil } diff --git a/launchdarkly/resource_launchdarkly_access_token.go b/launchdarkly/resource_launchdarkly_access_token.go index 56362467..7a6c2ce1 100644 --- a/launchdarkly/resource_launchdarkly_access_token.go +++ b/launchdarkly/resource_launchdarkly_access_token.go @@ -14,7 +14,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceAccessToken() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_audit_log_subscription.go b/launchdarkly/resource_launchdarkly_audit_log_subscription.go index 60aacc06..c7e69a26 100644 --- a/launchdarkly/resource_launchdarkly_audit_log_subscription.go +++ b/launchdarkly/resource_launchdarkly_audit_log_subscription.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceAuditLogSubscription() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_custom_role.go b/launchdarkly/resource_launchdarkly_custom_role.go index 2597b436..fd9c83c9 100644 --- a/launchdarkly/resource_launchdarkly_custom_role.go +++ b/launchdarkly/resource_launchdarkly_custom_role.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceCustomRole() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_destination.go b/launchdarkly/resource_launchdarkly_destination.go index 7358dded..4783552e 100644 --- a/launchdarkly/resource_launchdarkly_destination.go +++ b/launchdarkly/resource_launchdarkly_destination.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceDestination() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_environment.go b/launchdarkly/resource_launchdarkly_environment.go index cb4068be..4b84b7b7 100644 --- a/launchdarkly/resource_launchdarkly_environment.go +++ b/launchdarkly/resource_launchdarkly_environment.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceEnvironment() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_feature_flag.go b/launchdarkly/resource_launchdarkly_feature_flag.go index 568233fa..abad64e0 100644 --- a/launchdarkly/resource_launchdarkly_feature_flag.go +++ b/launchdarkly/resource_launchdarkly_feature_flag.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceFeatureFlag() *schema.Resource { @@ -109,7 +109,7 @@ func resourceFeatureFlagCreate(ctx context.Context, d *schema.ResourceData, meta // ld's api does not allow some fields to be passed in during flag creation so we do an update: // https://apidocs.launchdarkly.com/tag/Feature-flags#operation/postFeatureFlag - updateDiags := resourceFeatureFlagUpdate(ctx, d, metaRaw) + updateDiags := featureFlagUpdate(ctx, d, metaRaw, true) if updateDiags.HasError() { // if there was a problem in the update state, we need to clean up completely by deleting the flag _, deleteErr := client.ld.FeatureFlagsApi.DeleteFeatureFlag(client.ctx, projectKey, key).Execute() @@ -131,6 +131,10 @@ func resourceFeatureFlagRead(ctx context.Context, d *schema.ResourceData, metaRa } func resourceFeatureFlagUpdate(ctx context.Context, d *schema.ResourceData, metaRaw interface{}) diag.Diagnostics { + return featureFlagUpdate(ctx, d, metaRaw, false) +} + +func featureFlagUpdate(ctx context.Context, d *schema.ResourceData, metaRaw interface{}, isCreate bool) diag.Diagnostics { client := metaRaw.(*Client) key := d.Get(KEY).(string) projectKey := d.Get(PROJECT_KEY).(string) @@ -191,10 +195,50 @@ func resourceFeatureFlagUpdate(ctx context.Context, d *schema.ResourceData, meta patch.Patch = append(patch.Patch, patchReplace("/defaults", defaults)) } - // Only update the maintainer ID if is specified in the schema - maintainerID, ok := d.GetOk(MAINTAINER_ID) - if ok { - patch.Patch = append(patch.Patch, patchReplace("/maintainerId", maintainerID.(string))) + // Only update the maintainer fields if is specified in the schema + if d.HasChange(MAINTAINER_ID) || d.HasChange(MAINTAINER_TEAM_KEY) { + flag, res, err := client.ld.FeatureFlagsApi.GetFeatureFlag(client.ctx, projectKey, key).Execute() + if isStatusNotFound(res) || err != nil { + return diag.Errorf("error getting flag %q in project %q for update: %s", key, projectKey, handleLdapiErr(err)) + } + maintainerId, maintainerIdOk := d.GetOk(MAINTAINER_ID) + maintainerTeamKey, maintainerTeamKeyOk := d.GetOk(MAINTAINER_TEAM_KEY) + + if maintainerIdOk && maintainerTeamKeyOk { + if d.HasChange(MAINTAINER_ID) { + if maintainerId != "" { + patch.Patch = append(patch.Patch, patchReplace("/maintainerId", maintainerId.(string))) + if flag.MaintainerTeamKey != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerTeamKey")) + } + } else if flag.MaintainerId != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerId")) + } + } + if d.HasChange(MAINTAINER_TEAM_KEY) { + if maintainerTeamKey != "" { + patch.Patch = append(patch.Patch, patchReplace("/maintainerTeamKey", maintainerTeamKey.(string))) + if flag.MaintainerId != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerId")) + } + } else if flag.MaintainerTeamKey != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerTeamKey")) + } + } + if d.HasChange(MAINTAINER_ID) && d.HasChange(MAINTAINER_TEAM_KEY) { + fmt.Println("BOTH HAVE CHANGE SOMETHING IS WRONG") + } + } else if maintainerIdOk { + patch.Patch = append(patch.Patch, patchReplace("/maintainerId", maintainerId.(string))) + if flag.MaintainerTeamKey != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerTeamKey")) + } + } else if maintainerTeamKeyOk { + patch.Patch = append(patch.Patch, patchReplace("/maintainerTeamKey", maintainerTeamKey.(string))) + if flag.MaintainerId != nil { + patch.Patch = append(patch.Patch, patchRemove("/maintainerId")) + } + } } _, _, err = client.ld.FeatureFlagsApi.PatchFeatureFlag(client.ctx, projectKey, key).PatchWithComment(patch).Execute() diff --git a/launchdarkly/resource_launchdarkly_feature_flag_environment.go b/launchdarkly/resource_launchdarkly_feature_flag_environment.go index 061c6680..9344d3ff 100644 --- a/launchdarkly/resource_launchdarkly_feature_flag_environment.go +++ b/launchdarkly/resource_launchdarkly_feature_flag_environment.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceFeatureFlagEnvironment() *schema.Resource { @@ -251,6 +251,10 @@ func resourceFeatureFlagEnvironmentDelete(ctx context.Context, d *schema.Resourc // Set off variation to match default with how a rule is created offVariation := len(flag.Variations) - 1 + if flag.Defaults != nil { + // if flag defaults are set we want to make sure it reverts to those + offVariation = int(flag.Defaults.OffVariation) + } comment := "Terraform" patch := ldapi.PatchWithComment{ diff --git a/launchdarkly/resource_launchdarkly_feature_flag_environment_test.go b/launchdarkly/resource_launchdarkly_feature_flag_environment_test.go index 53db6909..076919ce 100644 --- a/launchdarkly/resource_launchdarkly_feature_flag_environment_test.go +++ b/launchdarkly/resource_launchdarkly_feature_flag_environment_test.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) @@ -568,6 +568,74 @@ resource "launchdarkly_feature_flag_environment" "rules_custom_context" { bucket_by = "account_id" } } +` + + testAccDefaultOffVariation = ` + resource "launchdarkly_feature_flag" "off_variation_test" { + project_key = launchdarkly_project.test.key + key = "off-variation-test-flag" + name = "off variation test" + variation_type = "boolean" + + variations { + value = false + } + + variations { + value = true + } + + defaults { + off_variation = 0 + on_variation = 1 + } + + client_side_availability { + using_environment_id = true + } + } +` + + testAccDefaultOffVariationOnDelete = ` +resource "launchdarkly_feature_flag" "off_variation_test" { + project_key = launchdarkly_project.test.key + key = "off-variation-test-flag" + name = "off variation test" + variation_type = "boolean" + + variations { + value = false + } + + variations { + value = true + } + + defaults { + off_variation = 0 + on_variation = 1 + } + + client_side_availability { + using_environment_id = true + } +} + +resource "launchdarkly_feature_flag_environment" "off_variation_test_configuration" { + flag_id = launchdarkly_feature_flag.off_variation_test.id + env_key = "test" + on = true + off_variation = 0 + + targets { + values = ["context-value"] + variation = 1 + } + + fallthrough { + variation = 0 + } +} ` ) @@ -924,12 +992,9 @@ func TestAccFeatureFlagEnvironment_ContextTargets(t *testing.T) { projectKey := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) client, err := newClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false, DEFAULT_HTTP_TIMEOUT_S) require.NoError(t, err) - // TODO at some point the context kind API will no longer be in beta and we will want to update/remove this - betaClient, err := newBetaClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false, DEFAULT_HTTP_TIMEOUT_S) - require.NoError(t, err) accountContextKind := "account" otherContextKind := "other" - err = testAccProjectWithCustomContextKindScaffold(client, betaClient, projectKey, []string{accountContextKind}) + err = testAccProjectWithCustomContextKindScaffold(client, projectKey, []string{accountContextKind}) require.NoError(t, err) defer func() { err := testAccProjectScaffoldDelete(client, projectKey) @@ -1072,6 +1137,52 @@ func TestAccFeatureFlagEnvironment_ContextTargets(t *testing.T) { }) } +func TestAccFeatureFlagEnvironment_OffVariationResetsToCorrectDefaultOnDelete(t *testing.T) { + projectKey := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) + globalFlagResourceName := "launchdarkly_feature_flag.off_variation_test" + resourceName := "launchdarkly_feature_flag_environment.off_variation_test_configuration" + flagKey := "off-variation-test-flag" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { + testAccPreCheck(t) + }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: withRandomProject(projectKey, testAccDefaultOffVariationOnDelete), + Check: resource.ComposeTestCheckFunc( + testAccCheckFeatureFlagEnvironmentExists(resourceName), + resource.TestCheckResourceAttr(resourceName, ON, "true"), + resource.TestCheckResourceAttr(resourceName, OFF_VARIATION, "0"), + resource.TestCheckResourceAttr(resourceName, "fallthrough.0.variation", "0"), + resource.TestCheckResourceAttr(resourceName, TRACK_EVENTS, "false"), + resource.TestCheckResourceAttr(globalFlagResourceName, "defaults.0.off_variation", "0"), + resource.TestCheckResourceAttr(globalFlagResourceName, "defaults.0.on_variation", "1"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + { + Config: withRandomProject(projectKey, testAccDefaultOffVariation), + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr(globalFlagResourceName, "defaults.0.off_variation", "0"), + resource.TestCheckResourceAttr(globalFlagResourceName, "defaults.0.on_variation", "1"), + testAccCheckFeatureFlagEnvironmentDefaults(t, projectKey, flagKey), + ), + }, + { + ResourceName: globalFlagResourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckFeatureFlagEnvironmentExists(resourceName string) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[resourceName] @@ -1099,7 +1210,21 @@ func testAccCheckFeatureFlagEnvironmentExists(resourceName string) resource.Test } } -func testAccProjectWithCustomContextKindScaffold(client *Client, betaClient *Client, projectKey string, contextKindKeys []string) error { +// this is a bespoke helper function to check that the env config's off variation +// has defaulted to the expected global config variation (in this case 0) +func testAccCheckFeatureFlagEnvironmentDefaults(t *testing.T, projectKey, flagKey string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client, err := newClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false, DEFAULT_HTTP_TIMEOUT_S) + require.NoError(t, err) + flag, _, err := client.ld.FeatureFlagsApi.GetFeatureFlag(client.ctx, projectKey, flagKey).Execute() + require.NoError(t, err) + envConfig := flag.Environments["test"] + require.Equal(t, int32(0), *envConfig.OffVariation) + return nil + } +} + +func testAccProjectWithCustomContextKindScaffold(client *Client, projectKey string, contextKindKeys []string) error { projectBody := ldapi.ProjectPost{ Name: "Context Kind Test Project", Key: projectKey, @@ -1110,7 +1235,7 @@ func testAccProjectWithCustomContextKindScaffold(client *Client, betaClient *Cli } for _, key := range contextKindKeys { - err := addContextKindToProject(betaClient, projectKey, key) + err := addContextKindToProject(client, projectKey, key) if err != nil { return err } diff --git a/launchdarkly/resource_launchdarkly_feature_flag_test.go b/launchdarkly/resource_launchdarkly_feature_flag_test.go index 937e8734..50bcf9cb 100644 --- a/launchdarkly/resource_launchdarkly_feature_flag_test.go +++ b/launchdarkly/resource_launchdarkly_feature_flag_test.go @@ -137,6 +137,32 @@ resource "launchdarkly_feature_flag" "json" { } ` + testAccFeatureFlagWithTeamMaintainer = ` + resource "launchdarkly_team_member" "test" { + email = "%s+wbteste2e@launchdarkly.com" + first_name = "first" + last_name = "last" + role = "admin" + custom_roles = [] + } + + resource "launchdarkly_team" "test_team" { + key = "%s" + name = "test team" + description = "Team to manage team project" + member_ids = [launchdarkly_team_member.test.id] + custom_role_keys = [] + } + + resource "launchdarkly_feature_flag" "maintained" { + project_key = launchdarkly_project.test.key + key = "maintained-flag" + name = "Maintained feature flag" + variation_type = "boolean" + maintainer_team_key = launchdarkly_team.test_team.key + } + ` + // The email must be set with a random name using fmt.Sprintf for this test to work since LD does // not support creating members with the same email address more than once. testAccFeatureFlagWithMaintainer = ` @@ -821,6 +847,20 @@ func TestAccFeatureFlag_WithMaintainer(t *testing.T) { }, Providers: testAccProviders, Steps: []resource.TestStep{ + { + Config: withRandomProject(projectKey, fmt.Sprintf(testAccFeatureFlagWithTeamMaintainer, randomName, randomName)), + Check: resource.ComposeTestCheckFunc( + testAccCheckProjectExists("launchdarkly_project.test"), + testAccCheckMemberExists("launchdarkly_team_member.test"), + testAccCheckFeatureFlagExists(resourceName), + resource.TestCheckResourceAttr(resourceName, NAME, "Maintained feature flag"), + resource.TestCheckResourceAttr(resourceName, KEY, "maintained-flag"), + resource.TestCheckResourceAttr(resourceName, PROJECT_KEY, projectKey), + resource.TestCheckResourceAttr(resourceName, MAINTAINER_ID, ""), + resource.TestCheckResourceAttrPair(resourceName, MAINTAINER_TEAM_KEY, "launchdarkly_team.test_team", "id"), + resource.TestCheckResourceAttrPair(resourceName, MAINTAINER_TEAM_KEY, "launchdarkly_team.test_team", "key"), + ), + }, { Config: withRandomProject(projectKey, fmt.Sprintf(testAccFeatureFlagWithMaintainer, randomName)), Check: resource.ComposeTestCheckFunc( @@ -831,6 +871,7 @@ func TestAccFeatureFlag_WithMaintainer(t *testing.T) { resource.TestCheckResourceAttr(resourceName, KEY, "maintained-flag"), resource.TestCheckResourceAttr(resourceName, PROJECT_KEY, projectKey), resource.TestCheckResourceAttrPair(resourceName, MAINTAINER_ID, "launchdarkly_team_member.test", "id"), + resource.TestCheckResourceAttr(resourceName, MAINTAINER_TEAM_KEY, ""), ), }, { diff --git a/launchdarkly/resource_launchdarkly_flag_trigger.go b/launchdarkly/resource_launchdarkly_flag_trigger.go index 22976a2f..fb42accd 100644 --- a/launchdarkly/resource_launchdarkly_flag_trigger.go +++ b/launchdarkly/resource_launchdarkly_flag_trigger.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceFlagTrigger() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_metric.go b/launchdarkly/resource_launchdarkly_metric.go index f899bce3..c765b110 100644 --- a/launchdarkly/resource_launchdarkly_metric.go +++ b/launchdarkly/resource_launchdarkly_metric.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // Our required fields for metrics depend on the value of the 'kind' enum. diff --git a/launchdarkly/resource_launchdarkly_metric_test.go b/launchdarkly/resource_launchdarkly_metric_test.go index 5491b9a9..89d88bb0 100644 --- a/launchdarkly/resource_launchdarkly_metric_test.go +++ b/launchdarkly/resource_launchdarkly_metric_test.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/require" ) @@ -90,7 +90,7 @@ resource "launchdarkly_metric" "custom" { // We can't update project experimentation settings in Terraform yet because they rely on beta endpoints. For now we will // make individual API calls to scaffold the project, contexts, and experimentation settings. -func scaffoldProjectWithExperimentationSettings(betaClient *Client, projectKey string, randomizationUnits []string) error { +func scaffoldProjectWithExperimentationSettings(client *Client, betaClient *Client, projectKey string, randomizationUnits []string) error { projectBody := ldapi.NewProjectPost(projectKey, projectKey) project, _, err := betaClient.ld.ProjectsApi.PostProject(betaClient.ctx).ProjectPost(*projectBody).Execute() if err != nil { @@ -105,7 +105,7 @@ func scaffoldProjectWithExperimentationSettings(betaClient *Client, projectKey s } // Add the additional context kinds to the project contextKindPayload := ldapi.UpsertContextKindPayload{Name: randomizationUnit} - _, _, err = betaClient.ld.ContextsBetaApi.PutContextKind(betaClient.ctx, project.Key, randomizationUnit).UpsertContextKindPayload(contextKindPayload).Execute() + _, _, err = client.ld.ContextsApi.PutContextKind(betaClient.ctx, project.Key, randomizationUnit).UpsertContextKindPayload(contextKindPayload).Execute() if err != nil { return err } @@ -209,11 +209,13 @@ func TestAccMetric_WithRandomizationUnits(t *testing.T) { projectKey := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) resourceName := "launchdarkly_metric.custom" + client, err := newClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false, DEFAULT_HTTP_TIMEOUT_S) + require.NoError(t, err) // In order to add additional randomization units we need to update the project's context kind and // experimentation settings. Because this can only be done using beta endpoints we can't set this up via Terraform. betaClient, err := newBetaClient(os.Getenv(LAUNCHDARKLY_ACCESS_TOKEN), os.Getenv(LAUNCHDARKLY_API_HOST), false, DEFAULT_HTTP_TIMEOUT_S) require.NoError(t, err) - err = scaffoldProjectWithExperimentationSettings(betaClient, projectKey, []string{"user", "request", "organization"}) + err = scaffoldProjectWithExperimentationSettings(client, betaClient, projectKey, []string{"user", "request", "organization"}) require.NoError(t, err) defer func() { diff --git a/launchdarkly/resource_launchdarkly_project.go b/launchdarkly/resource_launchdarkly_project.go index 106a0e25..296f7867 100644 --- a/launchdarkly/resource_launchdarkly_project.go +++ b/launchdarkly/resource_launchdarkly_project.go @@ -7,8 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // We assign a custom diff in cases where the customer has not assigned a default for CSA or IIS in config @@ -71,7 +70,7 @@ func resourceProject() *schema.Resource { Required: true, Description: "The project's unique key", ForceNew: true, - ValidateDiagFunc: validation.ToDiagFunc(validateKeyAndLength(1, 100)), + ValidateDiagFunc: validateKeyAndLength(1, 100), }, NAME: { Type: schema.TypeString, diff --git a/launchdarkly/resource_launchdarkly_relay_proxy_configuration.go b/launchdarkly/resource_launchdarkly_relay_proxy_configuration.go index 18ade267..d4e03dcc 100644 --- a/launchdarkly/resource_launchdarkly_relay_proxy_configuration.go +++ b/launchdarkly/resource_launchdarkly_relay_proxy_configuration.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceRelayProxyConfig() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_segment.go b/launchdarkly/resource_launchdarkly_segment.go index a59ba0a7..ca38f7d9 100644 --- a/launchdarkly/resource_launchdarkly_segment.go +++ b/launchdarkly/resource_launchdarkly_segment.go @@ -7,7 +7,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceSegment() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_team.go b/launchdarkly/resource_launchdarkly_team.go index 06076591..876b3830 100644 --- a/launchdarkly/resource_launchdarkly_team.go +++ b/launchdarkly/resource_launchdarkly_team.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceTeam() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_team_member.go b/launchdarkly/resource_launchdarkly_team_member.go index 6f969f4e..412c86e7 100644 --- a/launchdarkly/resource_launchdarkly_team_member.go +++ b/launchdarkly/resource_launchdarkly_team_member.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceTeamMember() *schema.Resource { diff --git a/launchdarkly/resource_launchdarkly_webhook.go b/launchdarkly/resource_launchdarkly_webhook.go index 9e97cda7..ef3f1920 100644 --- a/launchdarkly/resource_launchdarkly_webhook.go +++ b/launchdarkly/resource_launchdarkly_webhook.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func resourceWebhook() *schema.Resource { diff --git a/launchdarkly/resource_team_role_mapping.go b/launchdarkly/resource_team_role_mapping.go index 836fe09a..ac9205c8 100644 --- a/launchdarkly/resource_team_role_mapping.go +++ b/launchdarkly/resource_team_role_mapping.go @@ -11,7 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/types" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) var ( diff --git a/launchdarkly/rollout_helper.go b/launchdarkly/rollout_helper.go index 51fec4fb..17437e7f 100644 --- a/launchdarkly/rollout_helper.go +++ b/launchdarkly/rollout_helper.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func rolloutSchema() *schema.Schema { diff --git a/launchdarkly/rule_helper.go b/launchdarkly/rule_helper.go index 0ddbf343..7b65623d 100644 --- a/launchdarkly/rule_helper.go +++ b/launchdarkly/rule_helper.go @@ -6,7 +6,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func rulesSchema(isDataSource bool) *schema.Schema { diff --git a/launchdarkly/segment_rule_helper.go b/launchdarkly/segment_rule_helper.go index 30cfcb48..d90ccc71 100644 --- a/launchdarkly/segment_rule_helper.go +++ b/launchdarkly/segment_rule_helper.go @@ -3,7 +3,7 @@ package launchdarkly import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type segmentRulesSchemaOptions struct { diff --git a/launchdarkly/segment_rule_helper_test.go b/launchdarkly/segment_rule_helper_test.go index 02f9906e..474b2072 100644 --- a/launchdarkly/segment_rule_helper_test.go +++ b/launchdarkly/segment_rule_helper_test.go @@ -3,7 +3,7 @@ package launchdarkly import ( "testing" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/launchdarkly/segments_helper.go b/launchdarkly/segments_helper.go index b019d0dc..90eb4afa 100644 --- a/launchdarkly/segments_helper.go +++ b/launchdarkly/segments_helper.go @@ -8,7 +8,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) type segmentSchemaOptions struct { diff --git a/launchdarkly/target_helper.go b/launchdarkly/target_helper.go index 7d7bf766..55eab49a 100644 --- a/launchdarkly/target_helper.go +++ b/launchdarkly/target_helper.go @@ -4,7 +4,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) func baseTargetsSchema(isDataSource bool) map[string]*schema.Schema { diff --git a/launchdarkly/target_helper_test.go b/launchdarkly/target_helper_test.go index 50e13c6a..770e5ead 100644 --- a/launchdarkly/target_helper_test.go +++ b/launchdarkly/target_helper_test.go @@ -3,7 +3,7 @@ package launchdarkly import ( "testing" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" ) diff --git a/launchdarkly/test_utils.go b/launchdarkly/test_utils.go index 8cc7ed3b..ed5a67d9 100644 --- a/launchdarkly/test_utils.go +++ b/launchdarkly/test_utils.go @@ -3,7 +3,7 @@ package launchdarkly import ( "fmt" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) // testAccProjectScaffoldCreate creates a project with the given project parameters @@ -46,14 +46,12 @@ func testAccFeatureFlagScaffold(client *Client, projectKey string, flagBody ldap } -// since this API is still in beta, we need to make sure we always pass a beta client -// you can do this by calling newBetaClient() instead of newClient() -func addContextKindToProject(betaClient *Client, projectKey string, contextKind string) error { +func addContextKindToProject(client *Client, projectKey string, contextKind string) error { hideInTargeting := false contextKindBody := *ldapi.NewUpsertContextKindPayload(contextKind) contextKindBody.HideInTargeting = &hideInTargeting - _, _, err := betaClient.ld.ContextsBetaApi.PutContextKind(betaClient.ctx, projectKey, contextKind).UpsertContextKindPayload(contextKindBody).Execute() + _, _, err := client.ld.ContextsApi.PutContextKind(client.ctx, projectKey, contextKind).UpsertContextKindPayload(contextKindBody).Execute() if err != nil { return fmt.Errorf("failed to create context kind %s on project %s for test scaffolding: %s", contextKind, projectKey, err.Error()) } diff --git a/launchdarkly/validation_helper.go b/launchdarkly/validation_helper.go index 909df5d0..0c8f7c56 100644 --- a/launchdarkly/validation_helper.go +++ b/launchdarkly/validation_helper.go @@ -29,14 +29,14 @@ func validateKey() schema.SchemaValidateDiagFunc { // https://github.com/hashicorp/terraform-plugin-sdk/issues/734 // //nolint:staticcheck // SA1019 TODO: return SchemaValidateDiagFunc type -func validateKeyAndLength(minLength, maxLength int) schema.SchemaValidateFunc { - return validation.All( +func validateKeyAndLength(minLength, maxLength int) schema.SchemaValidateDiagFunc { + return validation.ToDiagFunc(validation.All( validation.StringMatch( regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_.-]*$`), "Must contain only letters, numbers, '.', '-', or '_' and must start with an alphanumeric", ), validation.StringLenBetween(minLength, maxLength), - ) + )) } func validateID() schema.SchemaValidateDiagFunc { diff --git a/launchdarkly/variations_helper.go b/launchdarkly/variations_helper.go index 3d738646..5752bd2a 100644 --- a/launchdarkly/variations_helper.go +++ b/launchdarkly/variations_helper.go @@ -9,7 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/structure" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" ) const ( diff --git a/launchdarkly/variations_helper_test.go b/launchdarkly/variations_helper_test.go index a92d704e..328d6e4f 100644 --- a/launchdarkly/variations_helper_test.go +++ b/launchdarkly/variations_helper_test.go @@ -4,7 +4,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" - ldapi "github.com/launchdarkly/api-client-go/v12" + ldapi "github.com/launchdarkly/api-client-go/v14" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/usage-examples/v2/feature_flags/README.md b/usage-examples/v2/feature_flag/README.md similarity index 100% rename from usage-examples/v2/feature_flags/README.md rename to usage-examples/v2/feature_flag/README.md diff --git a/usage-examples/v2/feature_flags/flag_types_example.tf b/usage-examples/v2/feature_flag/flag_types_example.tf similarity index 100% rename from usage-examples/v2/feature_flags/flag_types_example.tf rename to usage-examples/v2/feature_flag/flag_types_example.tf diff --git a/usage-examples/v2/feature_flags/setup.tf b/usage-examples/v2/feature_flag/setup.tf similarity index 100% rename from usage-examples/v2/feature_flags/setup.tf rename to usage-examples/v2/feature_flag/setup.tf diff --git a/usage-examples/v2/feature_flags/targeting_example.tf b/usage-examples/v2/feature_flag/targeting_example.tf similarity index 100% rename from usage-examples/v2/feature_flags/targeting_example.tf rename to usage-examples/v2/feature_flag/targeting_example.tf diff --git a/usage-examples/v2/feature_flags/versions.tf b/usage-examples/v2/feature_flag/versions.tf similarity index 100% rename from usage-examples/v2/feature_flags/versions.tf rename to usage-examples/v2/feature_flag/versions.tf diff --git a/usage-examples/v2/team/.terraform.lock.hcl b/usage-examples/v2/team/.terraform.lock.hcl new file mode 100644 index 00000000..019bbe9d --- /dev/null +++ b/usage-examples/v2/team/.terraform.lock.hcl @@ -0,0 +1,24 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/launchdarkly/launchdarkly" { + version = "2.17.0" + constraints = "~> 2.0" + hashes = [ + "h1:9gIGT/uMX3Rnded491wTelUP0gJzPyPYitN2OFha/cU=", + "zh:071d4f142e605f50cb6d92867d79c10f9b00f5c91e563362f6fec31c5e15a526", + "zh:1ae7c0c1d62dad189f09f269f6211c945483b2d2ecbe8049800011dbd4afaab8", + "zh:1e68d9bf1bba05f7ac7a124150df148d3b8b7a31f9b3c33fa4012a6dfb66307d", + "zh:29d6af5680d7300aa81ccc363e80253da2da8097f219124ff06f2ed84953a073", + "zh:2c7320e36d6404363c01d551612f6545d1ce668f5a0ebc3d93c87b9aa8b20534", + "zh:34f7e976e94541f7f08b4aa9ede10ac1a91e7558931f2e89f0f238bd25e0c2b8", + "zh:3c272f148b5d0605945b95d716e3a0174bcd21e9330ecf58cd4c37f245470811", + "zh:3c8aab26ab0134ac639ef87daa6677072cda96e1cdab07b14a537ef1d5ad5f7d", + "zh:44b825d44b7f55939809b07d6783e39a9a7506ea58822edd89b5bc4facf3874e", + "zh:47c6f9a8a854cf66d11f1b46e05223af38f99a45d93f1a5bd0a261c353f70326", + "zh:6f1105ef01d8c0829d490b2f3a3a45336d4502f619cf062377b2bdb4f83f2091", + "zh:8f02afe11bc6383a9aaceb5ec76fe0e0202e28f030b3b0240b2b6cfcd48fd1ad", + "zh:c93701bfd3c45eaf95800e8ca58e6994019e8d7b4117761e0a39d008e9141086", + "zh:ed782b2ac035e1812d0452ca0af98d3438abed87ebfc9f274d54013ead4c00fd", + ] +} diff --git a/usage-examples/v2/team/main.tf b/usage-examples/v2/team/main.tf new file mode 100644 index 00000000..a68539d1 --- /dev/null +++ b/usage-examples/v2/team/main.tf @@ -0,0 +1,61 @@ +resource "launchdarkly_project" "team_project" { + key = "proj-team-maintainer" + name = "Terraform Team Maintainer Project" + # configure a production environment + environments { + name = "A Production Environment" + key = "production" + color = "123456" + tags = [ + "terraform" + ] + } + + tags = [ + "terraform" + ] +} + +resource "launchdarkly_feature_flag" "team_flag" { + project_key = launchdarkly_project.team_project.key + key = "team-flag" + name = "team-maintained flag" + description = "A basic boolean flag maintained by a team" + variation_type = "boolean" + + maintainer_team_key = launchdarkly_team.test_team.id +} + +resource "launchdarkly_custom_role" "test_team" { + key = "test-team-custom-role" + name = "test team role" + + policy_statements { + effect = "allow" + resources = ["proj/proj-team-maintainer:env/production:flag/*"] + actions = ["*"] + } +} + +resource "launchdarkly_team_member" "member_1" { + email = "member1@company.com" + first_name = "Katie" + last_name = "Lee" + role = "writer" +} + +resource "launchdarkly_team_member" "member_2" { + email = "member2@company.com" + first_name = "Meishan" + last_name = "Xie" + role = "writer" +} + +resource "launchdarkly_team" "test_team" { + key = "test-team" + name = "test team" + description = "Team to manage team project" + member_ids = [launchdarkly_team_member.member_1.id, launchdarkly_team_member.member_2.id] + custom_role_keys = ["test-team-custom-role"] +} + diff --git a/usage-examples/v2/team/versions.tf b/usage-examples/v2/team/versions.tf new file mode 100644 index 00000000..5d1469ca --- /dev/null +++ b/usage-examples/v2/team/versions.tf @@ -0,0 +1,13 @@ +terraform { + required_providers { + launchdarkly = { + source = "launchdarkly/launchdarkly" + } + } + required_version = ">= 0.13" +} + +provider "launchdarkly" { + access_token = var.launchdarkly_access_token +} +