python-terraform icon indicating copy to clipboard operation
python-terraform copied to clipboard

Error: Argument or block definition required

Open ash-b opened this issue 5 years ago • 7 comments

tf = Terraform(working_dir='/var/www/html/terraform')
tf.plan(no_color=IsFlagged, refresh=False, capture_output=True)

after running this script we are getting

Error: Argument or block definition required

Python Version - 3.6.8 Terraform v0.12.10

  • provider.aws v2.31.0

ash-b avatar Oct 11 '19 05:10 ash-b

anyone?

ash-b avatar Oct 16 '19 07:10 ash-b

Without visibility into the actual TF plan I cannot help. This error would more than likely still occur if you ran the TF plan manually without wrapping with python-terraform, I would recommend running a tf fmt on the plan and see if that tells you where your error is.

Spikeophant avatar Oct 16 '19 20:10 Spikeophant

 provider "aws" {
  access_key = "${var.access_key}"
  secret_key = "${var.secret_key}"
  region     = "${var.aws_region}"
}

resource "aws_instance" "scm_instances" {
  ami           = "ami-xxxxxxxxxxxxxxxxx"
  instance_type = "t2.micro"
  subnet_id     = "subnet-xxxxxxxxxxxxxxxxxxxxxx"
  vpc_security_group_ids  = ["sg-0xxxxxxxxxxxxxxxxxxxxx"]
  associate_public_ip_address = true
  key_name = "ec2-instances"
  root_block_device {
  volume_type = "gp2"
  volume_size = "50"
  delete_on_termination = "true"
  }
tags = {
Name = "${var.instance_name}"
}
}
output "instance_id" {
  value = "${aws_instance.scm_instances.id}"
}

output "ip" {
 value       = "aws_instance.ip.public_ip"
}

This is the main.tf file

ash-b avatar Oct 17 '19 05:10 ash-b

At a glance the output for IP is incorrect, you need to use a valid identifier. If you run this plan with Terraform directly do you get the same error?

Spikeophant avatar Oct 17 '19 15:10 Spikeophant

No it works perfectly if hit manually!! Even if you remove the output section still get the same error

ash-b avatar Oct 17 '19 17:10 ash-b

I will put a test together and take a deeper look, I don't see anything offhand that would be causing this unless they changed something in TF 0.12.10.

Spikeophant avatar Oct 21 '19 19:10 Spikeophant

I would like to give more details about the error!! i tried on different terraform versions like 0.12.0, 0.12.12 (latest one), still getting the same error. also i get the following error

terraform.tfstate is not exist

before

Error: Argument or block definition required

ash-b avatar Oct 24 '19 12:10 ash-b