Terraform v0.12.16으로 업그레이드했으며 이제 다음과 같은 많은 메시지가 표시됩니다.
Warning: Interpolation-only expressions are deprecated
on ../modules/test-notifier/test_notifier.tf line 27, in resource "aws_sns_topic_policy" "default":
27: arn = "${aws_sns_topic.default.arn}"
Terraform 0.11 and earlier required all non-constant expressions to be
provided via interpolation syntax, but this pattern is now deprecated. To
silence this warning, remove the "${ sequence from the start and the }"
sequence from the end of this expression, leaving just the inner expression.
Template interpolation syntax is still used to construct strings from
expressions when the template includes multiple interpolation sequences or a
mixture of literal strings and interpolations. This deprecation applies only
to templates that consist entirely of a single interpolation sequence.
이 메시지는 수백 가지가 있습니다. 자동으로 수정하는 방법이 있습니까?
답변
코드를 먼저 업그레이드 했습니까?
Terraform 0.11은 0.12와 호환되지 않으므로 먼저 업그레이드해야합니다.
terraform init
terraform 0.12upgrade
Terraform 코드가 다른 테라 폼 모듈을 호출하는 경우이 테라 폼 모듈도 0.12로 업그레이드했는지 확인하십시오.
답변
Martin Atkins의 terraform-clean-syntax 코드를 사용할 수 있습니다 ( Kevin Burke 덕분에) 에게 힌트를주었습니다)
나는 뻔뻔스럽게 그것을 사용하고 docker 컨테이너 내에 패키지 했으므로 linux_amd64가 아닌 기계 (예 : MacOS)에서 쉽게 실행할 수 있습니다.
https://github.com/NoLedgeTech/terraform-clean-syntax-docker
TL & DR (경고-tf 파일이 업데이트됩니다) :
docker pull pniemiec/terraform-clean-syntax-docker
cd <DIRECTORY_WITH_TF_FILES>
terraform init
terraform plan # This shows a lot of warnings
docker run --rm -v $(pwd):/code -t pniemiec/terraform-clean-syntax-docker
terraform plan # This does not show a lot of warnings :sweat_smile:
답변
이 도구는 시작 및 끝 따옴표와 괄호를 자동으로 제거하여 경고를 수정합니다. https://github.com/apparentlymart/terraform-clean-syntax
go get github.com/apparentlymart/terraform-clean-syntax
terraform-clean-syntax .
답변
보간 구문을 제거하기 위해 notepad ++를 사용했습니다.
정규식 :
^(.*)\${(.*)}
replace_with :
\1\2
답변
또는 간단한 sed를 사용할 수 있습니다.
sed -i 's/\"\${/\"/g;s/}\"/\"/g' main.tf
답변
