claudie icon indicating copy to clipboard operation
claudie copied to clipboard

Bug: Unterminated template string

Open bernardhalas opened this issue 11 months ago • 6 comments

Current Behaviour

Getting the following error:

terraformer-8495c979b8-c8j59 terraformer 2024-03-14T02:34:09Z WRN ../go/internal/command/cmd.go:145 > Retrying command terraform apply --auto-approve --parallelism=8... (2/5) module=terraformer
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       ╷
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ Error: Invalid multi-line string
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ 
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │   on vienna-2-fewhjx0-azure-1-provider.tf line 3, in provider "azurerm":
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │    3:   subscription_id = "80839dc0-2dcc-4ed1-8c8b-f208da773517
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │    4: "
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ 
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ Quoted strings may not be split over multiple lines. To produce a
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ multi-line string, either use the \n escape to represent a newline
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ character or use the "heredoc" multi-line template syntax.
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       ╵
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       ╷
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ Error: Unterminated template string
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ 
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │   on vienna-2-fewhjx0-azure-1-provider.tf line 3, in provider "azurerm":
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │    3:   subscription_id = "80839dc0-2dcc-4ed1-8c8b-f208da773517
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │    4: "
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ 
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       │ No closing marker was found for the string.
terraformer-8495c979b8-c8j59 terraformer vienna-2-fewhjx0       ╵
terraformer-8495c979b8-c8j59 terraformer 2024-03-14T02:34:09Z WRN ../go/internal/command/cmd.go:92 > Error encountered while executing terraform apply --auto-approve --parallelism=8 : exit status 1 module=terraformer

Expected Behaviour

The input manifest should be processed successfully

Steps To Reproduce

Applying the manifest:

apiVersion: claudie.io/v1beta1
kind: InputManifest
metadata:
  name: vienna-2
  namespace: claudie
  labels:
    app.kubernetes.io/part-of: claudie
spec:
  providers:
    - name: azure-1
      providerType: azure
      secretRef:
        name: azure-secret-1
        namespace: claudie
    - name: oci-1
      providerType: oci
      secretRef:
        name: oci-secret-1
        namespace: claudie
  nodePools:
    dynamic:
      - name: control-azure
        providerSpec:
          name: azure-1
          region: West Europe
          zone: "1"
        count: 2
        serverType: Standard_B2s
        image: Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts:22.04.202212120
      - name: compute-1-azure
        providerSpec:
          name: azure-1
          region: Germany West Central
          zone: "1"
        count: 2
        serverType: Standard_B2s
        image: Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts:22.04.202212120
        storageDiskSize: 50
      - name: compute-2-azure
        providerSpec:
          name: azure-1
          region: West Europe
          zone: "1"
        count: 2
        serverType: Standard_B2s
        image: Canonical:0001-com-ubuntu-minimal-jammy:minimal-22_04-lts:22.04.202212120
        storageDiskSize: 50
  kubernetes:
    clusters:
      - name: vienna-2
        version: v1.26.0
        network: 192.168.2.0/24
        pools:
          control:
            - control-azure
          compute:
            - compute-2-azure
            - compute-1-azure

bernardhalas avatar Mar 14 '24 02:03 bernardhalas

I now see where the issue is, the provider configuration - after the subscription ID there is a new line

cloudziu avatar Mar 14 '24 06:03 cloudziu

@bernardhalas, this is more of a user error, you have created a secret that has a whitespace (newline) at the end of the subscription ID (input manifest that you posted is ok syntactically).

To minimize this kind of error we could trim the whitespace when reading the secrets

Despire avatar Mar 19 '24 15:03 Despire

I'll validate if the newline was coming from the azure provider secret. @Despire thanks for the hint.

bernardhalas avatar Mar 22 '24 13:03 bernardhalas

any updates @bernardhalas ?

Despire avatar Apr 02 '24 07:04 Despire

This can be reproduced for examply by executing:

echo "....secret...." | base64

to correctly base64 the secret without the implicit newline from echo:

echo -n "...secret..." | base64

Despire avatar May 17 '24 10:05 Despire

Hi, this was indeed a problem on the side of a user. While using Claudie recently it appeared a few more times. I'd like to propose trimming the secret values, to ensure copy/paste whitespace and newline chars don't create errors which are difficult to fix.

Btw, in case someone comes across an error and suspects the issue being caused by a trailing newline char, this helps:

kubectl get secret name-of-secret -o go-template='
{{range $k,$v := .data}}{{printf "%s: " $k}}{{if not $v}}{{$v}}{{else}}{{$v | base64decode}}{{end}}{{"\n"}}{{end}}'

(ref)

bernardhalas avatar May 17 '24 12:05 bernardhalas