Skip to content

Commit

Permalink
fix: skip interpolation of array of strings if the style of node is l…
Browse files Browse the repository at this point in the history
…iteral (#5157)

Resolves #5155

Literal style helps to break a string into new lines.

In Copilot version v1.29 we supported interpolation of sequence of strings. There is caveat here
If the manifest has `Literal Style`(Blocked Scalar)  node i.e 

for example if the manifest contains

```yaml
labels: 
  "test": |
      ["label1","label2"]
```

This will lead to unmarshal errors.



By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the Apache 2.0 License.
  • Loading branch information
KollaAdithya authored Aug 8, 2023
1 parent 8e39e52 commit dc4ecbe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion internal/pkg/manifest/interpolate.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (i *Interpolator) applyInterpolation(node *yaml.Node) error {
return err
}
var s []string
if err = json.Unmarshal([]byte(interpolated), &s); err == nil && len(s) != 0 {
if err = json.Unmarshal([]byte(interpolated), &s); err == nil && len(s) != 0 && node.Style != yaml.LiteralStyle {
seqNode := &yaml.Node{
Kind: yaml.SequenceNode,
}
Expand Down
16 changes: 16 additions & 0 deletions internal/pkg/manifest/interpolate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ image:
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/backend-service/#image-build
location: ${0accountID}.dkr.${repo-provider}.${region}.amazonaws.com/vault/${COPILOT_ENVIRONMENT_NAME}:${tag}
port: 80
labels: |
["label1","label2"]
"com.datadoghq.ad.instances": |
[
{
"prometheus_url": "http://metrics",
}
]
cpu: 256#${CPU}
memory: 512 # ${Memory}
Expand Down Expand Up @@ -89,6 +97,14 @@ image:
# Docker build arguments. For additional overrides: https://aws.github.io/copilot-cli/docs/manifest/backend-service/#image-build
location: ${0accountID}.dkr.${repo-provider}..amazonaws.com/vault/test:latest
port: 80
labels: |
["label1","label2"]
"com.datadoghq.ad.instances": |
[
{
"prometheus_url": "http://metrics",
}
]
cpu: 256#512
memory: 512 # ${Memory}
variables:
Expand Down

0 comments on commit dc4ecbe

Please sign in to comment.