2

I am trying my hand at creating AWS EC2 instances using Terraform.

$ terraform apply

I got the following output after executing the above command.

aws_instance.example: Creating...
  ami:                         "" => "ami-2d39803a"
  associate_public_ip_address: "" => "<computed>"
  availability_zone:           "" => "<computed>"
  ebs_block_device.#:          "" => "<computed>"
  ephemeral_block_device.#:    "" => "<computed>"
  instance_state:              "" => "<computed>"
  instance_type:               "" => "t2.micro"
  key_name:                    "" => "<computed>"
  network_interface_id:        "" => "<computed>"
  placement_group:             "" => "<computed>"
  private_dns:                 "" => "<computed>"
  private_ip:                  "" => "<computed>"
  public_dns:                  "" => "<computed>"
  public_ip:                   "" => "<computed>"
  root_block_device.#:         "" => "<computed>"
  security_groups.#:           "" => "<computed>"
  source_dest_check:           "" => "true"
  subnet_id:                   "" => "<computed>"
  tenancy:                     "" => "<computed>"
  vpc_security_group_ids.#:    "" => "<computed>"
aws_instance.example: Still creating... (10s elapsed)
aws_instance.example: Still creating... (20s elapsed)
aws_instance.example: Still creating... (30s elapsed)
aws_instance.example: Creation complete
Failed to save state: open terraform.tfstate: permission denied

Although, the EC2 instance gets created, but the state of my infrastructure is not saved as you can note in the last line in the console output.

srajappa
  • 484
  • 8
  • 19

1 Answers1

3

After trying desperately to find a solution, I happened to check the access permission of the directory in which my terraform files were placed.

The permission of the home directory was set to read only. I made appropriate changes and now terraform apply works just fine.

srajappa
  • 484
  • 8
  • 19