2

So I tried to spin up an EC2 instance using Terraform on my Mac (which is running Sierra and Terraform 0.11.5) but keep getting a few errors:

Command: terraform plan

Error: Error parsing /Users/*****/terraform/aws.tf: At 1:11: illegal char

Command: terraform show

Error: Failed to load backend: Error loading backend config: Error parsing /Users/******/terraform/aws.tf: At 1:11: illegal char

Here is what my file looks like:

provider "aws" {
    region = "us-east-1"
    access_key = ""
    secret_key = "********"
}

resource "aws_key_pair" "nick-key" {
    key_name = "nick-key"
    public_key = "ssh-rsa ********************************************"
}

resource "aws_instance" "web" {
    ami = "ami-1853ac65"
    instance_type = "t2.micro"
    key_name = "${aws_key_pair.nick-key.key_name}"

I put * in place of the real information used in the file in case anyone was wondering. Any help would be greatly appreciated!! Thank you in advance!

3
  • Also, this is the tutorial I was using to do this project but feel like he left crucial steps out and thats maybe why I'm having issues? youtube.com/watch?v=mQ9QDESqZ9o Commented Apr 5, 2018 at 12:50
  • 2
    is this the whole file? its missing a curly brace at the end Commented Apr 5, 2018 at 16:16
  • Oh man, the missing curly was exactly why it wasn't working smh. It's always the simplest thing I seem to miss. Thank you Stephen! Commented Apr 6, 2018 at 21:02

2 Answers 2

4

To answer the question but also provide feedback on how to ensure your format is correct.

As mentioned in the comment the example is missing a closing curly brace

resource "aws_instance" "web" {
    ami = "ami-1853ac65"
    instance_type = "t2.micro"
    key_name = "${aws_key_pair.nick-key.key_name}"
}

Terraform has a validate command that will check for these formatting issues. If you run on the example above you will see

$ terraform validate
Error: Error parsing test.tf: object expected closing RBRACE got: EOF
Sign up to request clarification or add additional context in comments.

Comments

0

Ensure you are calling the correct version of terraform from the terminal.

I had a parsing error like this when using terraform v11, to run scripts written for terraform v12.

Sometimes this can be easily done if you have two versions of terraform installed.

Make sure you have set up each alias in your bash profile (or appropriate shell profile file) and are using the correct command.

I tend to have the following set up in my working environment:

alias terraform='/usr/local/bin/terraform'  #points to terraform 12 installation
alias terraform11='/usr/local/bin/terraform11'  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.