如何在安全组描述中使用Heredoc

时间:2019-01-14 00:58:58

标签: amazon-web-services terraform aws-security-group terraform-provider-aws

尝试一下:

resource "aws_security_group" "mysg" {
  description = <<EOF
this is a very long descirpltion slkfjsldkfjsdf
skdfjlskdfjlksdjlfksdjlfksjdlfksjdlfkjsdlkfjsldkf
sdlkfjsldkfjsldkfjsldkfjlksdjflskdfjlksdjflksdjflksdf
EOF
}

得到这个

* aws_security_group.mysq: Error creating Security Group: InvalidParameterValue: Invalid security group description. Valid descriptions are strings less than 256 characters from the following set:  a-zA-Z0-9. _-:/()#,@[]+=&;{}!$*

它完全在char限制之内,我认为其加回车符还是什么?我如何不将换行符添加到字符串?

我还尝试了-的变种,但无济于事https://github.com/hashicorp/hcl/issues/144

2 个答案:

答案 0 :(得分:0)

作为您粘贴的链接,last comment提供了解决方法。

resource "aws_security_group" "mysg" {
  description = <<-EOF
this is a very long descirpltion slkfjsldkfjsdf
skdfjlskdfjlksdjlfksdjlfksjdlfksjdlfkjsdlkfjsldkf
sdlkfjsldkfjsldkfjsldkfjlksdjflskdfjlksdjflksdjflksdf
-EOF
}

这是空转输出

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  + aws_security_group.mysg
      id:                     <computed>
      arn:                    <computed>
      description:            "this is a very long descirpltion slkfjsldkfjsdf\nskdfjlskdfjlksdjlfksdjlfksjdlfksjdlfkjsdlkfjsldkf\nsdlkfjsldkfjsldkfjsldkfjlksdjflskdfjlksdjflksdjflksdf\n"
      egress.#:               <computed>
      ingress.#:              <computed>
      name:                   <computed>
      owner_id:               <computed>
      revoke_rules_on_delete: "false"
      vpc_id:                 <computed>


Plan: 1 to add, 0 to change, 0 to destroy.

答案 1 :(得分:0)

是的,似乎使用heredoc打破了此处的长度限制。您只能使用heredoc,但如果您需要Verbosity……

添加一个名为description.txt的文件,您的作品受到祝福:

例如

This is a very long descirpltion slkfjsldkfjsdf
skdfjlskdfjlksdjlfksdjlfksjdlfksjdlfkjsdlkfjsldkf
sdlkfjsldkfjsldkfjsldkfjlksdjflskdfjlksdjflksdjflksdf

然后将您的代码更改为:

data "local_file" "foo" {
    filename = "${path.module}/description.txt"
}

resource "aws_security_group" "mysg" {
  description = "${data.local_file.foo.content}"
}

填满靴子。