codefresh-io / terraform-provider-codefresh

Terraform provider for the Codefresh API
https://registry.terraform.io/providers/codefresh-io/codefresh
Mozilla Public License 2.0
18 stars 24 forks source link

Cannot create pipeline from string #59

Open kpurdon opened 3 years ago

kpurdon commented 3 years ago

It's unclear if this is possible or not, but the code/docs seems to indicate I should be able to do it. I'm generating code in terraform and yaml encoding it to pass to terraform.

resource "codefresh_pipeline" "schedule_all" {
  for_each = toset(["syndio/syndio", "syndio/ce"])

  name = "${codefresh_project.syndio_codefresh_project.name}/Schedule All (${each.key}) Pipelines"

  original_yaml_string = yamlencode({
    version = "1.0"
    stages  = ["deploy"]
    steps = {
      schedule_all_pipelines = {
        type  = "parallel"
        title = "Schedule All Pipelines"
        steps = { for p in local.pipelines : lower(replace("schedule_${p.name}", " ", "_")) => {
          title = "Schedule ${p.name}"
          stage = "deploy"
          type  = "codefresh-run"
          arguments = {
            PIPELINE_ID = "${codefresh_project.syndio_codefresh_project.name}/${p.name}"
            DETACH      = true
            BRANCH      = "$${{CF_BRANCH}}"
            SHA         = "$${{CF_REVISION}}"
            TRIGGER_ID  = each.key
          }
        } if p.repo == each.key }
      }
    }
  })

  spec {
    concurrency = 1
    pack_id     = local.machine_types["small"]

    trigger {
      name          = each.key
      description   = "Manual Branch Trigger"
      type          = "git"
      provider      = "github"
      repo          = each.key
      disabled      = true
      context       = "syndio"
      branch_regex  = "/.*/gi"
      comment_regex = "/.*/gi"
      events = [
        "push.heads"
      ]
    }
  }
}

this generates an API request which faills w/ the following error

module.syndio_codefresh.codefresh_pipeline.schedule_all["syndio/syndio"]: Creating...
module.syndio_codefresh.codefresh_pipeline.schedule_all["syndio/ce"]: Creating...

Error: 500 Internal Server Error, {"status":500,"code":"1001","name":"INTERNAL_SERVER_ERROR","message":"500 - {\"message\":\"Error: Can't get project; caused by Error: Can't get project\"}","context":{}}

Error: 500 Internal Server Error, {"status":500,"code":"1001","name":"INTERNAL_SERVER_ERROR","message":"500 - {\"message\":\"Error: Can't get project; caused by Error: Can't get project\"}","context":{}}

one of the api request bodies sent to codefresh is

Headers: 

{
  "correlationId": "7b00cd5a3f39c17a3b2a09ba94138efa, 7b00cd5a3f39c17a3b2a09ba94138efa"
}

Body: 

{
  "metadata": {
    "name": "Staging/Deploy All (syndio/ce)",
    "labels": {},
    "originalYamlString": "\"deploy_all_pipelines\":\n  \"steps\":\n    \"steps\":\n      \"schedule_payeq_deploy\":\n        \"arguments\":\n          \"BRANCH\": \"${{CF_BRANCH}}\"\n          \"DETACH\": true\n          \"PIPELINE_ID\": \"Staging/PayEQ Deploy\"\n          \"SHA\": \"${{CF_REVISION}}\"\n          \"TRIGGER_ID\": \"syndio/ce\"\n        \"stage\": \"deploy\"\n        \"title\": \"Schedule PayEQ Deploy\"\n        \"type\": \"codefresh-run\"\n  \"title\": \"Schedule All Pipelines\"\n  \"type\": \"parallel\"\n\"stages\":\n- \"deploy\"\n\"version\": \"1.0\"\n"
  },
  "spec": {
    "triggers": [
      {
        "name": "syndio/ce",
        "description": "Manual Branch Trigger",
        "type": "git",
        "repo": "syndio/ce",
        "events": [
          "push.heads"
        ],
        "branchRegex": "/.*/gi",
        "branchRegexInput": "regex",
        "commentRegex": "/.*/gi",
        "provider": "github",
        "disabled": true,
        "context": "syndio"
      }
    ],
    "concurrency": 1,
    "steps": {},
    "stages": [
      "deploy"
    ],
    "runtimeEnvironment": {},
    "hooks": {}
  }
}

This looks incorrect when compared to working requests from the codefresh cli. Since giving a spec directly (not repo sourced) doesn't seem to be exposed in any way other than giving the original_yaml_string and letting the provider handle it.

kpurdon commented 3 years ago

Of note I'm using an up to date fork of this provider since https://github.com/codefresh-io/terraform-provider-codefresh/pull/44 is still not reviewed/merged.

mattmelgard commented 2 years ago

Hey @denis-codefresh, Any chance this might have already been fixed? This one has also been open for a while.