注入 CDKTF 多行令牌值
Inject CDKTF multiline token value
上下文:
- TLS 提供商:SelfSignedCert
- AWS 提供商:ECS Fargate 任务
const cert = new SelfSignedCert(this.stack, `${certName}-sscert`, {
keyAlgorithm: 'RSA',
privateKeyPem: privateKey.privateKeyPem,
subject: [{
commonName,
organization
}],
validityPeriodHours,
allowedUses
});
const containerDefinitionConfig = {
path: {
path: ecsJsonTaskDefPath,
},
args: {
...
'certPem': cert.certPem,
...
}
};
如果我尝试 运行 那样,我会收到以下错误:
Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character '\n' in string literal
我尝试使用:
cert.certPem.replace(/\n/g', '\n')
直接作用于值——毫无意义,因为它是一个标记,而 replace
函数仅适用于标记引用,而不适用于值本身。所以我从上面得到了同样的错误。
Fn.replace(cert.certPem, '/\n/', '\n')
但它在抱怨 Error: '\n' can not be used as value directly since it has unescaped double quotes in it. To safely use the value please use Fn.rawString on your string.
Fn.rawString(cert.certPem)
不会失败,但会将环境变量设置为 "${tls_self_signed_cert.seb-alice-sscert.cert_pem}"
版本:
"cdktf": "^0.9.0",
"terraformProviders": [
"aws@~> 3.74.0",
"random@~> 3.1.0",
"tls@~> 3.1.0"
],
我相信它抱怨替换函数中的第一个 \n:Fn.replace(cert.certPem, Fn.rawString('/\n/'), Fn.rawString('\n'))
上下文:
- TLS 提供商:SelfSignedCert
- AWS 提供商:ECS Fargate 任务
const cert = new SelfSignedCert(this.stack, `${certName}-sscert`, {
keyAlgorithm: 'RSA',
privateKeyPem: privateKey.privateKeyPem,
subject: [{
commonName,
organization
}],
validityPeriodHours,
allowedUses
});
const containerDefinitionConfig = {
path: {
path: ecsJsonTaskDefPath,
},
args: {
...
'certPem': cert.certPem,
...
}
};
如果我尝试 运行 那样,我会收到以下错误:
Error: ECS Task Definition container_definitions is invalid: Error decoding JSON: invalid character '\n' in string literal
我尝试使用:
cert.certPem.replace(/\n/g', '\n')
直接作用于值——毫无意义,因为它是一个标记,而replace
函数仅适用于标记引用,而不适用于值本身。所以我从上面得到了同样的错误。Fn.replace(cert.certPem, '/\n/', '\n')
但它在抱怨Error: '\n' can not be used as value directly since it has unescaped double quotes in it. To safely use the value please use Fn.rawString on your string.
Fn.rawString(cert.certPem)
不会失败,但会将环境变量设置为"${tls_self_signed_cert.seb-alice-sscert.cert_pem}"
版本:
"cdktf": "^0.9.0",
"terraformProviders": [
"aws@~> 3.74.0",
"random@~> 3.1.0",
"tls@~> 3.1.0"
],
我相信它抱怨替换函数中的第一个 \n:Fn.replace(cert.certPem, Fn.rawString('/\n/'), Fn.rawString('\n'))