【问题标题】:Terraform Replace - Regex Find and string AppendTerraform Replace - 正则表达式查找和字符串追加
【发布时间】:2022-11-02 20:35:19
【问题描述】:

我需要使用 Terraform 替换正则表达式来进行模式匹配和追加。

到目前为止,我已经能够写这个:

> replace("repo:company/example:environment:sandbox", "/(<=environment:)(.*)+(=:)/", "1_deplopy")

“回购:公司/示例:环境:沙盒”

问题是它附加在错误的空间中

"repo:company/example:environment:sandbox"

它应该是

"repo:company/example:environment:sandbox_deplopy"

3 种类型变量的示例,其中 2 种需要更改

repo:company/example:environment:sandbox:job_workflow_ref:test.yaml
repo:company/example:environment:sandbox
repo:company/example:*

有没有人可以帮助改进这个工作?

它附加在模式的开头,而不是结尾

replace("repo:company/example:environment:sandbox", "/(environment:*:)/", "_deplopy$1")
"repo:company/example:_deplopyenvironment:sandbox"

谢谢

【问题讨论】:

  • 到目前为止,您在 Terraform 中尝试过什么?您没有在您的问题中显示任何 Terraform 尝试,因此它只是要求人们将代码从一种工具翻译到另一种工具,这往往会导致投票失败/接近投票,就像要求人们这样做一样你的工作。请展示您的尝试,以及问题中的任何错误或意外行为。
  • 抱歉@MarkB,我已经添加了我的正​​则表达式

标签: regex sed terraform


【解决方案1】:
> replace("repo:company/example:environment:sandbox", "/(environment:[^:]+)/", "$${1}_deplopy")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-05
    • 2021-09-15
    • 2012-05-28
    • 1970-01-01
    • 2021-05-18
    • 1970-01-01
    • 2016-05-16
    • 2012-05-12
    相关资源
    最近更新 更多