brikis98 / terraform-up-and-running-code

Code samples for the book "Terraform: Up & Running" by Yevgeniy Brikman
http://www.terraformupandrunning.com/
MIT License
2.87k stars 1.92k forks source link

Fix "expected length of user_data" error when applying the example #37

Closed Mayeu closed 4 years ago

Mayeu commented 4 years ago

Hello :wave:

When running the ASG example in the chapter 6 I am getting an error on the length of the user_data:

➜ terraform apply
data.aws_vpc.default: Refreshing state...
data.aws_subnet_ids.default: Refreshing state...

Error: expected length of user_data to be in the range (1 - 16384), got

  on ../../modules/cluster/asg-rolling-deploy/main.tf line 1, in resource "aws_launch_configuration" "example":
   1: resource "aws_launch_configuration" "example" {

This error also shows up using your version of the code so I assumed this was not due to typos on my side.

I have fixed this error replacing the default value of this variable with "Hello World".

brikis98 commented 4 years ago

Oh, interesting... You can't set user data to an empty string anymore? That would be a recent change...

Does it work if you set the default to null?

jfontanoza commented 4 years ago

Same issue, using terraform 0.12.6 and provider.aws 2.28.1.

Setting the default for user_data in the asg-rolling-deploy module to null instead of the empty string does work, and no user_data hash is present in the apply/plan output for the asg resource.

According to https://github.com/terraform-providers/terraform-provider-aws/pull/4037, the minimum length validation requirement when the user_data resource is present was added last year in the v1.12 release.

brikis98 commented 4 years ago

Thx for pointing this out! I fixed it in a few places in: https://github.com/brikis98/terraform-up-and-running-code/commit/ddb296550c83bd85fc42028a9e842c9aa4f07808.

Mayeu commented 4 years ago

Thank you for the fix, I did not thought of trying null instead of an empty string :+1: