Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Bug]: Issue with codefresh_pipeline resource where original_yaml_string uses YAML anchors & aliases #152

Closed
nathanzanon opened this issue Sep 11, 2024 · 1 comment · Fixed by #153
Assignees
Labels
bug Something isn't working

Comments

@nathanzanon
Copy link

nathanzanon commented Sep 11, 2024

What happened?

In our pipeline definitions we're using YAML anchors (and aliases) to avoid repetition.

When using a codefresh_pipeline resource where the file original_yaml_string contains YAML anchors and aliases the apply fails with:

╷
│ Error: error while converting 'steps' YAML to JSON: yaml: unknown anchor 'my_common_envs' referenced
│ 
│   with codefresh_pipeline.indicators,
│   on main.tf line 49, in resource "codefresh_pipeline" "indicators":
│   49: resource "codefresh_pipeline" "indicators" {
│ 
╵

The YAML pipeline definitions I'm using to validate this are the examples in the documentation. So these work fine when configuring through the Codefresh console/GUI, and they also pass validation

❯ codefresh validate plain.yaml
Yaml is valid!

❯ codefresh validate indicators.yaml
Yaml is valid!

Version

Seems to be broken in >= 0.4.0, including current latest 0.10.1
Works in <= 0.3.1

Relevant Terraform Configuration

main.tf

terraform {
  required_version = "1.9.5"

  backend "local" {}

  required_providers {
    codefresh = {
      source  = "codefresh-io/codefresh"
      version = "0.3.1"   # works
      #version = "0.4.0"  # broken
      #version = "0.10.1" # broken
    }
  }
}

provider "codefresh" {
  api_url = "${var.codefresh_api_url}/api"
  token   = var.codefresh_token
}

variable "codefresh_api_url" {
  description = "Codefresh authentication token"
  type        = string
}

variable "codefresh_token" {
  description = "Codefresh authentication token"
  type        = string
}

locals {
  codefresh_project_name = "testing"
}

resource "codefresh_pipeline" "plain" {

  name = "${local.codefresh_project_name}/example-plain"

  original_yaml_string = file("${path.module}/plain.yaml")

  spec {
    variables = {
      TIME = timestamp() # force update of resource on every plan/apply
    }
  }

}

resource "codefresh_pipeline" "indicators" {

  name = "${local.codefresh_project_name}/example-indicators"

  original_yaml_string = file("${path.module}/indicators.yaml")

  spec {
    variables = {
      TIME = timestamp() # force update of resource on every plan/apply
    }
  }

}

plain.yaml

version: "1.0"
steps:
  preLoadDatabase:
    title: Loading Data
    image: alpine
    commands:
      - printenv
      - echo "Loading DB"
    environment: &my_common_envs
      - MYSQL_HOST=mysql
      - MYSQL_USER=user
      - MYSQL_PASS=password
      - MYSQL_PORT=3351
  runTests:
    title: Integration tests
    image: alpine
    commands:
      - printenv
      - echo "Running tests"
    environment: *my_common_envs # Same MYSQL_HOST, MYSQL_USER etc.

indicators.yaml

version: "1.0"

indicators:
  - environment: &my_common_envs
      - MYSQL_HOST=mysql
      - MYSQL_USER=user
      - MYSQL_PASS=password
      - MYSQL_PORT=3351

steps:
  preLoadDatabase:
    title: Loading Data
    image: alpine
    commands:
      - printenv
      - echo "Loading DB"
    environment: *my_common_envs # Same MYSQL_HOST, MYSQL_USER etc.
  runTests:
    title: Integration tests
    image: alpine
    commands:
      - printenv
      - echo "Running tests"
    environment: *my_common_envs # Same MYSQL_HOST, MYSQL_USER etc.
@ilia-medvedev-codefresh
Copy link
Contributor

@nathanzanon thank you very much for reporting the issue!
The fix has been included in version 0.11.0 of the provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants