Closed
Description
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.