Giter Site home page Giter Site logo

davidji99 / terraform-provider-split Goto Github PK

View Code? Open in Web Editor NEW
23.0 3.0 8.0 498 KB

Terraform Split provider

Home Page: https://registry.terraform.io/providers/davidji99/split/latest

License: Mozilla Public License 2.0

Makefile 1.07% Go 98.30% Shell 0.63%
splitio split terraform terraform-provider split-testing

terraform-provider-split's Introduction

Terraform Provider Split

This provider is used to configure certain resources supported by Split API.

For provider bugs/questions, please open an issue on this repository.

Documentation

Documentation about resources and data sources can be found here.

Requirements

  • Terraform v0.13.x+
  • Go 1.18 (to build the provider plugin)

Usage

provider "split" {
  version = "~> 0.1.0"
}

Releases

Provider binaries can be found here.

Development

If you wish to work on the provider, you'll first need Go installed on your machine (version 1.12+ is required).

If you wish to bump the provider version, you can do so in the file version/version.go.

Build the Provider

To compile the provider, run make build. This will build the provider and put the provider binary in the $GOPATH/bin directory.

$ make build
...
$ $GOPATH/bin/terraform-provider-split
...

Using the Provider

To use the dev provider with local Terraform, copy the freshly built plugin into Terraform's local plugins directory:

cp $GOPATH/bin/terraform-provider-split ~/.terraform.d/plugins/

Set the split provider without a version constraint:

provider "split" {}

Then, initialize Terraform:

terraform init

Testing

Please see the TESTING guide for detailed instructions on running tests.

Updating or adding dependencies

This project uses Go Modules for dependency management.

This example will fetch a module at the release tag and record it in your project's go.mod and go.sum files. It's a good idea to run go mod tidy afterward and then go mod vendor to copy the dependencies into a vendor/ directory.

If a module does not have release tags, then module@SHA can be used instead.

terraform-provider-split's People

Contributors

bulju avatar davidji99 avatar dependabot[bot] avatar jramosf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

terraform-provider-split's Issues

Tag association

Hi there,

The split API allows tags to be associated with feature flags. Is this something you could support on the split resource?

Getting rate limit from Split API

Hi there,

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

HerokuX Provider Version

Run terraform -v to show core and any provider versions. A sample output could be:

Terraform v1.3.2
+ provider.split v0.6.2

Affected Resource(s)

Please list the resources as a list, for example:

  • split_environment
  • split_user
  • we've tested on these 2 kind of resources, but we suspect that the same issue is affecting all resources

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "split_environment" "this" {
  for_each           = var.environments
  name                = each.value.name
  production       = each.value.production
  workspace_id  = each.value.workspace
}
environments = {
  1 = {
    name       = "Production"
    production = "false"
    workspace  = "REDACTED"
  },

  2 = {
    name       = "QA"
    production = "false"
    workspace  = "REDACTED"
  },

  3 = {
    name       = "Staging"
    production = "false"
    workspace  = "REDACTED"
  },

  4 = {
    name       = "Test"
    production = "false"
    workspace  = "REDACTED"
  },

  5 = {
    name       = "staging-mock"
    production = "false"
    workspace  = "REDACTED"
  },

  6 = {
    name       = "staging"
    production = "false"
    workspace  = "REDACTED"
  },

  7 = {
    name       = "Prod"
    production = "true"
    workspace  = "REDACTED"
  },

  8 = {
    name       = "Staging"
    production = "false"
    workspace  = "REDACTED"
  },

  9 = {
    name       = "Builds"
    production = "true"
    workspace  = "REDACTED"
  },

  10 = {
    name       = "Builds"
    production = "false"
    workspace  = "REDACTED"
  },

  11 = {
    name       = "Prod- Auto"
    production = "true"
    workspace  = "REDACTED"
  },

  12 = {
    name       = "Stg- Auto"
    production = "false"
    workspace  = "REDACTED"
  },

  13 = {
    name       = "Prod"
    production = "true"
    workspace  = "REDACTED"
  },

  14 = {
    name       = "Staging"
    production = "false"
    workspace  = "REDACTED"
  },

  15 = {
    name       = "Prod"
    production = "true"
    workspace  = "REDACTED"
  },

  16 = {
    name       = "Stg"
    production = "false"
    workspace  = "REDACTED"
  },

  17 = {
    name       = "Prod"
    production = "true"
    workspace  = "REDACTED"
  },

  18 = {
    name       = "Stg"
    production = "false"
    workspace  = "REDACTED"
  },

  19 = {
    name       = "appstore"
    production = "true"
    workspace  = "REDACTED"
  },

  20 = {
    name       = "dev"
    production = "false"
    workspace  = "REDACTED"
  },

  21 = {
    name       = "staging"
    production = "false"
    workspace  = "REDACTED"
  },
}


Debug Output

Please provider a link to a GitHub Gist containing the complete debug output: https://www.terraform.io/docs/internals/debugging.html. Please do NOT paste the debug output in the issue; just paste a link to the Gist. Please MAKE SURE to mask any sensitive values.

TBD

Panic Output

If Terraform produced a panic, please provide a link to a GitHub Gist containing the output of the crash.log.

Expected Behavior

What should have happened?

Split resources should be created

Actual Behavior

What actually happened?

We got a rate limit and we received a 429 from Split

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

Terraform apply with more than 20 resources (this number is not precise yet, as the provider doesn't provide actual numbers)

New resource: `split_user_group_association`

You remove a user from a group by using the patch and sending an ‘op’ of ‘remove’ like the below: (note that the order of the group you’re removing does matter so removing group /groups/0 is the first group that the user has, /groups/1 is the second and so on)

[{
"op": "remove",
"path": "/groups/1",
}]

Terraform destroy doesn't delete every resource

Hi there,

Terraform Version

v.1.7.3

HerokuX Provider Version

Terraform v1.7.3
on darwin_arm64
provider registry.terraform.io/davidji99/split v0.12.3

Affected Resource(s)

  • split_environment
  • split_workspace
  • split_traffic_type

If this issue appears to affect multiple resources, it may be an issue with Terraform's core, so please mention this.

Terraform Configuration Files

resource "split_workspace" "foobar" {
  name = "Terraform Test"
  require_title_comments = true
}

data "split_workspace" "foobar" {
  name = "Terraform Test"
}

resource "split_environment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "staging-canary"
  production = false
}

resource "split_traffic_type" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "terraform"
}

data "split_traffic_type" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    name = "terraform"
}

resource "split_split" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "my_terraform_split"
  description = "my terraform split description"
}

resource "split_split_definition" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  split_name = split_split.foobar.name
  environment_id = split_environment.foobar.id

  default_treatment = "treatment_123"
  treatment {
    name = "treatment_123"
    configurations = "{\"key\":\"value\"}"
    description = "my treatment 123"
  }
  treatment {
    name = "treatment_456"
    configurations = "{\"key2\":\"value2\"}"
    description = "my treatment 456"
  }

  default_rule {
    treatment = "treatment_123"
    size = 100
  }
  rule {
    bucket {
      treatment = "treatment_123"
      size = 100
    }
    condition {
      combiner = "AND"
      matcher {
        type = "EQUAL_SET"
        attribute = "test_string"
        strings = ["test_string"]
      }
    }
  }
}

resource "split_segment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "terraform_segment"
  description = "description_of_my_terraform_segment"
}

resource "split_segment_environment_association" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    environment_id = split_environment.foobar.id
    segment_name = split_segment.foobar.name
}

resource "split_environment_segment_keys" "foobar" {
    environment_id = split_environment.foobar.id
    segment_name = split_segment_environment_association.foobar.segment_name
    keys = ["mytestkey1", "mytestkey2"]
}

Debug Output

run-UjbubQYXUZSZ1Dum-plan-log.txt

Expected Behavior

Destroy should have deleted all resources that were created with the apply

Actual Behavior

Destroy was unable to delete resources relating to environment and then eventually the workspace as all the traffic types were still there and also all the feature flags and segments were still there. In order for an environment to be deleted, first all flags, segments, traffic types need to be deleted. Once all environments are deleted, then the workspace can be deleted.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform init
  2. terraform plan
  3. terraform apply
  4. terraform destroy

Segment keys not created when title and comments are required

Hi there,

Terraform Version

v.1.7.3

HerokuX Provider Version

Terraform v1.7.3
on darwin_arm64
provider registry.terraform.io/davidji99/split v0.12.3

Affected Resource(s)

Please list the resources as a list, for example:

  • environment_segment_keys

Terraform Configuration Files

Provided below

Copy-paste your Terraform configurations here

resource "split_workspace" "foobar" {
  name = "Terraform Test"
  require_title_comments = true
}

data "split_workspace" "foobar" {
  name = "Terraform Test"
}

resource "split_environment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "staging-canary"
  production = false
}

resource "split_traffic_type" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  name = "terraform"
}

data "split_traffic_type" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    name = "terraform"
}

resource "split_split" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "my_terraform_split"
  description = "my terraform split description"
}

resource "split_split_definition" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  split_name = split_split.foobar.name
  environment_id = split_environment.foobar.id

  default_treatment = "treatment_123"
  treatment {
    name = "treatment_123"
    configurations = "{\"key\":\"value\"}"
    description = "my treatment 123"
  }
  treatment {
    name = "treatment_456"
    configurations = "{\"key2\":\"value2\"}"
    description = "my treatment 456"
  }

  default_rule {
    treatment = "treatment_123"
    size = 100
  }
  rule {
    bucket {
      treatment = "treatment_123"
      size = 100
    }
    condition {
      combiner = "AND"
      matcher {
        type = "EQUAL_SET"
        attribute = "test_string"
        strings = ["test_string"]
      }
    }
  }
}

resource "split_segment" "foobar" {
  workspace_id = data.split_workspace.foobar.id
  traffic_type_id = data.split_traffic_type.foobar.id
  name = "terraform_segment"
  description = "description_of_my_terraform_segment"
}

resource "split_segment_environment_association" "foobar" {
    workspace_id = data.split_workspace.foobar.id
    environment_id = split_environment.foobar.id
    segment_name = split_segment.foobar.name
}

resource "split_environment_segment_keys" "foobar" {
    environment_id = split_environment.foobar.id
    segment_name = split_segment_environment_association.foobar.segment_name
    keys = ["mytestkey1", "mytestkey2"]
}

Debug Output

Please provider a link to a GitHub Gist containing the complete debug output:
run-nea3BckLYRchxeVz-apply-log.txt

Expected Behavior

The segment should have been created for the respective environment with the keys mentioned with a title and comment.

Actual Behavior

The last resource call gave an error with the segment update call not having the title and comments available and failed to associate the keys on that segment.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform plan
  2. terraform apply

References

Are there any other GitHub issues (open or closed) or Pull Requests that should be linked here? For example:

  • No

provider.terraform-provider-split_v0.10.1: panic: runtime error: invalid memory address or nil pointer dereference

Hi there,

Terraform Version

Terraform v1.4.2
on darwin_arm64
+ provider registry.terraform.io/davidji99/split v0.10.1

Debug Output

https://gist.github.com/6ripley/4fab5da4044e370e9a118748b798c3ac

Panic Output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1044fa33c]

goroutine 182 [running]:
github.com/davidji99/terraform-provider-split/split.resourceSplitSegmentEnvironmentAssociationRead({0x104996980?, 0x14000570630?}, 0x14000194280, {0x1048be7a0?, 0x14000266e80?})
        /home/runner/work/terraform-provider-split/terraform-provider-split/split/resource_split_segment_environment_association.go:136 +0x42c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).read(0x1400019eee0, {0x104996980, 0x14000570630}, 0xd?, {0x1048be7a0, 0x14000266e80})
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:724 +0xec
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).RefreshWithoutUpgrade(0x1400019eee0, {0x104996980, 0x14000570630}, 0x140006032b0, {0x1048be7a0, 0x14000266e80})
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/resource.go:1015 +0x46c
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0x14000250480, {0x104996980?, 0x14000570510?}, 0x14000598e40)
        /home/runner/go/pkg/mod/github.com/hashicorp/terraform-plugin-sdk/[email protected]/helper/schema/grpc_provider.go:613 +0x40c
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0x1400026cdc0, {0x104996980?, 0x1400056fef0?}, 0x14000380fc0)
        /home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/tf5server/server.go:748 +0x3ec
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x104960540?, 0x1400026cdc0}, {0x104996980, 0x1400056fef0}, 0x140001c6a80, 0x0)
        /home/runner/go/pkg/mod/github.com/hashicorp/[email protected]/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:349 +0x174
google.golang.org/grpc.(*Server).processUnaryRPC(0x1400026a1e0, {0x1049994a0, 0x140004029c0}, 0x1400039f9e0, 0x140003c4f30, 0x104e32550, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1340 +0xb90
google.golang.org/grpc.(*Server).handleStream(0x1400026a1e0, {0x1049994a0, 0x140004029c0}, 0x1400039f9e0, 0x0)
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:1713 +0x840
google.golang.org/grpc.(*Server).serveStreams.func1.2()
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:965 +0x88
created by google.golang.org/grpc.(*Server).serveStreams.func1
        /home/runner/go/pkg/mod/google.golang.org/[email protected]/server.go:963 +0x298

Error: The terraform-provider-split_v0.10.1 plugin crashed!

Expected Behavior

Terraform should successfully refresh configuration or throw a useful error.

Actual Behavior

Plugin crashes when refreshing state. After re-creating tfstate file and importing existing resources terraform works for the first time when one of the below commands are issued. When apply with refresh=false is issued, it works for printing planned changes but crashes when applied.
Tried applying less resources per command but once it reaches certain number of resources it fails on refresh every time.

Steps to Reproduce

terraform apply
terraform apply -refresh-only

Important Factoids

Tested with Mac with M1 and with Ubuntu 22.04
Already tried setting up export GODEBUG=asyncpreemptoff=1 on mac, recreating tfstate file from import multiple times, re-initializing terraform.

Any help will be appreciated, thanks!

Type error on split tags

Hi there,

I'm facing issues when importing split_split, when the split has tags.

Terraform Version

Run terraform -v to show the version. If you are not running the latest version of Terraform, please upgrade because your issue may have already been fixed.

HerokuX Provider Version

Terraform v1.3.2
on darwin_arm64
+ provider registry.terraform.io/davidji99/split v0.6.2
+ provider registry.terraform.io/hashicorp/aws v4.8.0

Note: I've tested with split v0.7.0, and I'm getting another error, and I will also put a solution in place for that.

Affected Resource(s)

  • split_split

Terraform Configuration Files

resource "split_split" "this" {
  for_each        = var.splits
  workspace_id    = each.value.workspace
  traffic_type_id = each.value.traffic_type
  name            = each.value.name
  description     = each.value.description
}

splits = {
  1 = {
    name          = "name"
    description   = "description"
    workspace     = "workspace_id"
    traffic_type  = "traffic_type_id"
  },

  2 = {
    name          = "name"
    description   = "description"
    workspace     = "workspace_id"
    traffic_type  = "traffic_type_id"
  },
}

Expected Behavior

What should have happened?
The split should be imported

Actual Behavior

What actually happened?
Terraform crashed because of a type error.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Create a split containing tags
  2. Create the terraform code to import it
  3. terraform import <resource_name> <workspace_id>:<split_id>

Important mentions

Tags is being defined as a list of strings, but the response from the API is returning a list of key/value, as I detail:

> curl -X GET \
  -H 'Content-Type:application/json' \
  -H 'Authorization: Bearer <redacted>' \
  https://api.split.io/internal/api/v2/splits/ws/<redacted>/<redacted>
{"id":"<redacted>","name":<redacted>","description":"<redacted>","trafficType":{"id":"<redacted>","name":"<redacted>"},"creationTime":1604662508084,"tags":[{"name":"<redacted>"}],"owners":[{"id":"<redacted>","type":"<redacted>"},{"id":"<redacted>","type":"<redacted>"}]}%  

Doc Bug - split_workspace data source not documented

Hi there,

I'm really excited to be playing around with the Split Terraform provider. I'd just like to make a quick note that it looks like in the documentation the data source split_workspace is not documented anywhere, and some of the code examples use data split_environment when they should be using data split_workspace Such as this file here or this file here or this one as well

Again - really excited to see your hard work and thank you for what you've done so far.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.