Giter VIP home page Giter VIP logo

terraform-provider-sleuth's Introduction

Terraform Provider for Sleuth

Latest release

This repository is a Terraform provider for Sleuth, allowing a team to manage Sleuth configuration via Terraform instead of having to click around in the UI.

Requirements

or

Known Limitations

  • No support for New Relic as impact source provider
  • No support for custom impact sources
  • Limited support for multiple integrations of same type

Building The Provider

  1. Clone the repository
  2. Enter the repository directory
  3. Build the provider using the Go install command:
$ go install .

Quick Starts

terraform-provider-sleuth's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

terraform-provider-sleuth's Issues

Unable to destroy environment resources with single environment projects

Terraform Version

Terraform v1.5.3
on darwin_arm64

Provider registry.terraform.io/sleuth-io/sleuth v0.4.3

Affected Resource(s)

sleuth_environment
sleuth_project

Terraform Configuration Files

resource "sleuth_project" "project" {
  name           = "some_repo_project"
  build_provider = "GITHUB"
}

resource "sleuth_environment" "environments" {
  project_slug = "${sleuth_project.project.slug}"
  name         = "Production"
  color        = "#2F7604"
}

Debug Output

Debug output

Expected Behavior

Running terraform destroy --auto-approve should destroy the environment and project in sleuth and remove them from the state file.

Actual Behavior

The destroy errors out with the error Error: Missing when trying to destroy the environment resource. This blocks the project from being destroyed due to the dependancy tree.

Steps to Reproduce

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

  1. terraform apply --auto-approve
  2. terraform destroy --auto-approve

datadog is not one of the available choices

Terraform Version

t -version
OpenTofu v1.6.2
on darwin_arm64
+ provider registry.opentofu.org/hashicorp/aws v5.46.0
+ provider registry.opentofu.org/sleuth-io/sleuth v0.4.7

Affected Resource(s)

  • sleuth_metric_impact_source

Terraform Configuration Files

resource "sleuth_metric_impact_source" "ingress" {
  project_slug     = "my-project"
  environment_slug = "production"
  name             = "my-service"
  provider_type    = "datadog"
  query            = "sum:nginx_ingress.controller.requests{service:my-service}"
  less_is_better   = false
}

Error Output

Error: Errors creating impact source:  [{Field:auth Messages:[Select a valid choice. datadog is not one of the available choices.]}]

Expected Behavior

According to the documentation, resource should be created

Actual Behavior

Fails

Steps to Reproduce

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

  1. terraform init
  2. terraform apply -auto-approve

Environment mapping issue

Hi there,

I have created a module for the project creation. Deployed one project was ok, but when I added a new project below it tried to update the existing one where no changes were done. During debugging it came up that the sequence of env mapping does matter. We have it in for each loop so the sequence was changed every time when the deployment was triggered. Is such behavior expected or it is a bug?

Terraform Version

Terraform v1.3.7

Affected Resource(s)

  • environment_mappings

Module definition

locals {
repository_owner = "xxxxxxx"
}

resource "sleuth_project" "project" {
name = var.project_name
issue_tracker_provider_type = "JIRA"

lifecycle {
prevent_destroy = true
}
}

resource "sleuth_environment" "env_qa" {
project_slug = sleuth_project.project.slug
name = "qa"
color = "#ff0000"
}

resource "sleuth_environment" "env_pre" {
project_slug = sleuth_project.project.slug
name = "preprod"
color = "#0000ff"
}

resource "sleuth_code_change_source" "sleuth-terraform-provider" {
for_each = var.repositories

project_slug = sleuth_project.project.id
name = each.key
repository {
name = each.key
owner = local.repository_owner
provider = "GITHUB"
url = "https://github.com/${local.repository_owner}/${each.key}"
}

environment_mappings {
environment_slug = sleuth_environment.env_pre.slug
branch = each.value
}

environment_mappings {
environment_slug = "${lower(var.project_name)}/production"
branch = each.value
}

environment_mappings {
environment_slug = sleuth_environment.env_qa.slug
branch = each.value
}

deploy_tracking_type = "manual"
collect_impact = true
include_in_dashboard = true

depends_on = [
sleuth_environment.env_qa,
sleuth_environment.env_pre
]
}


### The output of  TF Fplan 
 Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following
symbols:
  ~ update in-place

Terraform will perform the following actions:

  # module.xxxxxx.sleuth_code_change_source.sleuth-terraform-provider["xxxxxx"] will be updated in-place
  ~ resource "sleuth_code_change_source" "sleuth-terraform-provider" {
        id                   = "xxx/xxx"
        name                 = "xxx"
        # (6 unchanged attributes hidden)

      ~ environment_mappings {
          ~ environment_slug = "xxx/preprod" -> "xxx/qa"
            # (1 unchanged attribute hidden)
        }
      ~ environment_mappings {
          ~ environment_slug = "xxx/production" -> "xxx/preprod"
            # (1 unchanged attribute hidden)
        }
      ~ environment_mappings {
          ~ environment_slug = "xxx/qa" -> "xxx/production"
            # (1 unchanged attribute hidden)
        }

        # (2 unchanged blocks hidden)
    }

### Steps to Reproduce
To reproduce is enough to run tf plan

Terraform import of sleuth_code_change_source does not pull in repository information

Terraform Version

Terraform v1.5.6
on darwin_arm64

  • provider registry.terraform.io/sleuth-io/sleuth v0.4.3

Affected Resource(s)

Please list the resources as a list, for example:

  • sleuth_code_change_source

Terraform Configuration Files

resource "sleuth_code_change_source" "webapp_webapp" {
  #
}

Expected Behavior

Running terraform import sleuth_code_change_source.webapp_webapp webapp/webapp should provide the state file filled out with the proper information.

Actual Behavior

The repository was generated as a blank array in the JSON of the .tfstate file after the import as seen in the output below

   {
      "mode": "managed",
      "type": "sleuth_code_change_source",
      "name": "webapp_webapp",
      "provider": "provider[\"registry.terraform.io/sleuth-io/sleuth\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "auto_tracking_delay": 0,
            "build_mappings": [],
            "collect_impact": true,
            "deploy_tracking_type": "manual",
            "environment_mappings": [
              {
                "branch": "main",
                "environment_slug": "development-2",
                "id": "webapp/development-2"
              },
              {
                "branch": "main",
                "environment_slug": "production",
                "id": "webapp/production"
              },
              {
                "branch": "main",
                "environment_slug": "development",
                "id": "webapp/development"
              }
            ],
            "id": "webapp/webapp",
            "include_in_dashboard": true,
            "name": "Webapp",
            "notify_in_slack": true,
            "path_prefix": "",
            "project_slug": "webapp",
            "repository": []
          },
          "sensitive_attributes": [],
        }
      ]
    },

Steps to Reproduce

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

  1. terraform import sleuth_code_change_source.webapp_webapp webapp/webapp

Add a new resource for associating `sleuth_code_change_source` to `environments` to enable iteration

Firstly, thank you for this project and Sleuth itself - love it.

Feature Request

This is a feature request as we would like a new resource sleuth_code_change_source_environment in order to associate/map environments to sleuth_code_change_source resources without having to explicitly include environments as we do currently.

Why

We have numerous repositories that are not uniform and unfortunately do not have uniformly named environments. We use a configuration file to generate projects and repositories and would like to do the same with our Sleuth integration. As it stands we are unable to loop through our project repositories and correctly associate environments for code deployments with this resource.

For example, an environment could have a variation on its name such as prod, production or may not include an environment of a specific type at all.

Current Behaviour

If we use a configuration file as input and create resources via loops we currently have to explicitly encode environment mappings.

resource "sleuth_code_change_source" "sleuth-terraform-provider" {
  for_each   = local.code_changes

  project_slug = each.value.slug
  name         = each.value.name
  repository { ... }

  // We cannot iterate through the below i.e. for_each = each.value.envs
  environment_mappings {
    environment_slug = "dev"
    branch = "main"
  }

  environment_mappings {
    environment_slug = "prod"
    branch = "main"
  }

  environment_mappings {
    environment_slug = "uat"
    branch = "main"
  }
}

New Behaviour

We would like to create a sleuth_code_change_source without environments and then associate those via a loop with an appropriate map i.e. code_change_envs = { 'dev' = { ... }, 'prod' = { ... }, 'uat' = { ... } } inside a seperate resource block sleuth_code_change_source_environment.

resource "sleuth_code_change_source" "code_changes" {
  for_each   = local.code_changes

  project_slug = each.value.slug
  name         = each.value.name
  repository { ... }
}

resource "sleuth_code_change_source_environment" "code_change_envs" {
  for_each   = local.code_change_envs

  project_slug = each.value.project_slug
  environment_slug = each.value.env_slug
  branch = each.value.branch
}

Maybe it's me

I'm not a Terraform guru so perhaps there is a much simpler answer that I have missed on how this can be achieved. If that is the case I apologise for the time lost here.

Versions

Sleuth - 0.5.1-dev
Terraform - 1.8.1

Platform: darwin_arm64 not supported

I am not able to use the provider on Mac M1/M2. Currently downloading rosetta as a potential workaround.

Terraform Version

terraform -v 
Terraform v1.3.4
on darwin_arm64

Your version of Terraform is out of date! The latest version
is 1.3.9. You can update by downloading from https://www.terraform.io/downloads.html

Affected Resource(s)

Provider not setup for Mac Silion

Terraform Configuration Files

terraform {
  required_version = ">= 0.13.0"

  required_providers {
    sleuth = {
      source = "sleuth-io/sleuth"
      version = "~> 0.2.0"
    }
  }
}

Debug Output

Initializing provider plugins...
- Finding sleuth-io/sleuth versions matching "~> 0.2.0"...
╷
│ Error: Incompatible provider version
│ 
│ Provider registry.terraform.io/sleuth-io/sleuth v0.2.1 does not have a package available for your current platform, darwin_arm64.
│ 
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of this provider may have different
│ platforms supported.
╵

Expected Behavior

Provider should download to mac silicon

Actual Behavior

Error saying darwin not supported.

Steps to Reproduce

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

  1. terraform init

Cross compile for Darwin ARM64

Now the Apple M1 Mac's are quite common and this provider won't install via terraform init due to the missing binary.

Removed project raises an error and causes Terraform to error instead of replacing the missing resource

We are seeing errors like the following (as detailed in the support request):

Error: Project with slug `my-awesome-project` not found

If someone removes or renames a project in Sleuth that's been managed via Terraform. I think this is due to the following:

proj, err := c.GetProject(&projectSlug)
if err != nil {
return diag.FromErr(err)
}
setProjectFields(d, proj)

Raising an error, which errors the whole terraform plan over the correct way to set the Id to an empty string.

d.SetId("")

Sleuth not discovering CircleCI jobs or branches when building code_change_source with Terraform provider.

Hi there,

Thank you for opening an issue. Please note that we try to keep the Terraform issue tracker reserved for bug reports and feature requests. For general usage questions, please see: https://www.terraform.io/community.html.

Terraform Version

0.3.5

Affected Resource(s)

Please list the resources as a list, for example:

  • code_change_source

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

Terraform Configuration Files

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.

Panic Output

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

Expected Behavior

when creating a code_change_source resource with a environment and build mappings to a main branch of a CircleCI project I would expect circleci jobs to be discoverable. It seems that they aren't in the same way that is seen in the Sleuth UI when integrating with CircleCI.

Actual Behavior

The resource is created. The github repo is found, but the branch stays unspecified and CircleCI cannot find the builds/jobs for the given project.

Steps to Reproduce

Applied code_change_source.
Went into the UI and edited the code_change_source manually as follows:

  • change the repo to a different repository
  • change back to the original repository/branch/circleci job and save
  • re-initialize the code_change_source at which point everything looks as expected

However, when I re-apply the terraform I am shown that the envrionment_slug is being changed in the following way:

sleuth_code_change_source.code_change_source will be updated in-place

~ resource "sleuth_code_change_source" "code_change_source" {
id = "planet-express/up-platform-demo-app"
name = "up-platform-demo-app"
# (6 unchanged attributes hidden)

  ~ build_mappings {
      ~ environment_slug = "planet-express/production" -> "production"
        # (3 unchanged attributes hidden)
    }

  ~ environment_mappings {
      ~ environment_slug = "planet-express/production" -> "production"
        # (1 unchanged attribute hidden)
    }

    # (1 unchanged block hidden)
}

Plan: 0 to add, 1 to change, 0 to destroy.

it would seem that the environment slug is different when it comes from terraform compared to when it is set via the UI in that it also contains the project_slug

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.