Code Monkey home page Code Monkey logo

Comments (11)

Joshua-Rowe avatar Joshua-Rowe commented on June 11, 2024 6

I had the exact same issue where I got to the Deploy a Single Web Server example on page 39. After typing the updated program, I ran terraform graph to look at the dependencies and got the error: main.tf: At 29:1: heredoc not terminated. An inital search brought me here, but I was unable to resolve the problem with the information listed in this issue. However, a few more searches and I came across this issue in the Terraform repo: hashicorp/terraform/issues/4835 where phinze says: the consistent behavior I found was that the heredoc terminates only when a line contains the terminator with no trailing space.. After removing a trailing space after the second EOF, I did not have any more issues.

from terraform-up-and-running-code.

advissor avatar advissor commented on June 11, 2024 1

Indeed, the issue was caused by a trailing space after EOD

EOF
EOD

After removing trailing space, the issue was solved

from terraform-up-and-running-code.

brikis98 avatar brikis98 commented on June 11, 2024

Which example are you actually running? Could you post the full code? There is no chapter2/single_server/main.tf in this repo.

Also, the examples in this repo have not yet been updated to work with Terraform 0.9, which is enforced via the required_version setting. Even if I remove that check from code/terraform/02-intro-to-terraform-syntax/one-webserver/main.tf, the plan command works just fine with Terraform 0.9.3. Is it possible you have a copy/paste error?

from terraform-up-and-running-code.

syl20bnr avatar syl20bnr commented on June 11, 2024

I type the code myself without relying on the code in this repo so sorry if the issue is not about the provided code itself.

This issue is related to #12 where you can find the code I use. The reason why there is no hyphen in #12 is because of this parsing error.

The parsing disappear if the closing statement is -EOF instead of EOF. I'll try it as soon as possible when I have a computer available.

from terraform-up-and-running-code.

brikis98 avatar brikis98 commented on June 11, 2024

Sounds good. Keep me posted.

from terraform-up-and-running-code.

syl20bnr avatar syl20bnr commented on June 11, 2024

I tried with the following code:

# Single Server Deployment

provider "aws" {
  region = "us-east-1"
}

resource "aws_security_group" "webserver" {
  name = "terraform-example-webserver"
  ingress {
    from_port = 8080
    to_port = 8080
    protocol = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_instance" "example" {
  tags {
    Name = "terraform-example"
  }
  ami = "ami-f4cc1de2"
  instance_type = "t2.micro"
  vpc_security_group_ids = ["${aws_security_group.webserver.id}"]
  user_data = <<-EOF
    #!/bin/bash
    echo "Hello, Terraform!" > index.html
    nohup busybox httpd -f -p 8080 &
    -EOF
}

It is parsed just fine by terraform but the web server does not kick in.

That's weird, I just downloaded the binary for macOS from the Terraform website which gave me the version 0.9.3.

I looked into the doc and I could only find this url https://www.terraform.io/docs/configuration/syntax.html where it is mentioned:

Multiline strings can use shell-style "here doc" syntax, with the string starting with a marker like <<EOF and then the string ending with EOF on a line of its own. The lines of the string and the end marker must not be indented.

from terraform-up-and-running-code.

brikis98 avatar brikis98 commented on June 11, 2024

The syntax is <<-EOF...EOF as shown in this example.

from terraform-up-and-running-code.

syl20bnr avatar syl20bnr commented on June 11, 2024

There are something really weird with what happened. I was able to reproduce the parsing error 100% of the time then I copy pasted the example from the repo, no parsing error! Then I undo the copy paste to go back to the version with parsing error and....... impossible to reproduce it, it just works. I'm really puzzled, my best bet was a whitespace between <<-and EOF and when I fixed it I may have not saved the file so I thought it was broken, but still.... I tried several time.

Anyway let's close the issue, sorry for losing your time.

As I was not able to find it in the official documentation, it could be a good thing to add a mention of it for an update of the book. In the meantime I submitted a PR to add documentation for it: hashicorp/hcl#195

from terraform-up-and-running-code.

brikis98 avatar brikis98 commented on June 11, 2024

Yea, the heredoc stuff is whitespace sensitive, so if some tab or space got caught in the mix, it might break things in a way that's hard to see.

Good call on the HCL PR!

from terraform-up-and-running-code.

fr34k8 avatar fr34k8 commented on June 11, 2024

this was also my error.. thanks @Joshua-Rowe

from terraform-up-and-running-code.

slysenko1 avatar slysenko1 commented on June 11, 2024

trailing spaces it is - thank you

from terraform-up-and-running-code.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.