我正在尝试使用 Terraform 创建 AWS EC2 实例。
$ terraform apply
执行上述命令后得到以下输出。
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
虽然 EC2 实例已创建,但我的基础设施的状态并未保存,您可以在控制台输出的最后一行中注意到。
最佳答案
在拼命寻找解决方案后,我碰巧检查了放置 terraform 文件的目录的访问权限。
主目录的权限设置为只读。我做了适当的更改,现在 terraform apply 工作得很好。
关于amazon-ec2 - 无法保存状态 : open terraform. tfstate:权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40539038/