简体   繁体   English

具有此 ID 的 Terraform 资源不存在

[英]Terraform resource with this ID doesn't exist

I'm trying to import the existing s3 bucket to my terraform using the below commands我正在尝试使用以下命令将现有的 s3 存储桶导入我的 terraform

$ terraform import aws_s3_bucket.test-bucket test-bucket200

Here is my code:这是我的代码:

resource "aws_s3_bucket" "test-bucket" {
  bucket = "test-bucket200"
}   

resource "aws_s3_bucket_public_access_block" "test-bucket-acl" {
  bucket = "${aws_s3_bucket.test-bucket.id}"

  block_public_acls   = false
  block_public_policy = false
  
}

While importing aws_s3_bucket_public_access_block (after the bucket import) throwing me the error在导入aws_s3_bucket_public_access_block (在存储桶导入之后)向我抛出错误

$ terraform import aws_s3_bucket_public_access_block.test-bucket-acl test-bucket200

Terraform detected a resource with this ID doesn't exist. Please verify the ID is correct. You cannot import non-existent.resources using Terraform import.

However my state shows但是我的状态显示

$ terraform state show
id                                     = test-bucket200
arn                                    = arn:aws:s3:::test-bucket200

What am I doing wrong here?我在这里做错了什么? Is this due to the older version?这是旧版本的原因吗?

$ terraform version
Terraform v0.11.13
+ provider.aws v2.10.0

Thanks in Advance!提前致谢!

What am I doing wrong here?我在这里做错了什么? Is this due to the older version?这是旧版本的原因吗?

I don't think its due to older version.我不认为这是由于旧版本。 I just tried to replicate the issue with v0.11.13 and v2.10.0 but had no issues .我只是试图用v0.11.13v2.10.0复制这个问题,但没有问题

./terraform import aws_s3_bucket.test-bucket test-bucket2003333                                                                                                                                           
aws_s3_bucket.test-bucket: Importing from ID "test-bucket2003333"...                                                                                                                                                        
aws_s3_bucket.test-bucket: Import complete!                                                                                                                                                                                 
  Imported aws_s3_bucket (ID: test-bucket2003333)                                                                                                                                                                           
aws_s3_bucket.test-bucket: Refreshing state... (ID: test-bucket2003333)                                                                                                                                                     

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

and

./terraform import aws_s3_bucket_public_access_block.test-bucket-acl test-bucket2003333
aws_s3_bucket_public_access_block.test-bucket-acl: Importing from ID "test-bucket2003333"...
aws_s3_bucket_public_access_block.test-bucket-acl: Import complete!
  Imported aws_s3_bucket_public_access_block (ID: test-bucket2003333)
aws_s3_bucket_public_access_block.test-bucket-acl: Refreshing state... (ID: test-bucket2003333)

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Your commands seems fine.你的命令看起来不错。 It appears something else is happening, not apparent from your question.似乎发生了其他事情,从您的问题中看不出来。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Terraform - 如果数据源不存在则不创建资源 - Terraform - don't create resource if data source does not exist 实例ID不存在 - Instance ID doesn't exist aws resourcegroupstaggingapi 检索不存在的资源 - aws resourcegroupstaggingapi retrieving resource that doesn't exist Terraform:如果参数存储值不存在,则使用默认变量 - Terraform: Use default variable if parameter store value doesn't exist Terraform 导入 - 查找资源 ID - Terraform Import - finding the resource id 当 object 不存在时,使用 terraform 无法安全读取 s3_bucket_object - Fail safe reading s3_bucket_object with terraform when object doesn't exist 在 Terraform 中如何引用另一个资源中一个资源的 ID? - In Terraform how to reference ID's of one resource in another resource? Terraform 配置未使用其他文件中的 output 来获取已创建的资源,而是尝试重新创建它并失败(安全组 ID) - Terraform config isn't using output from other file for already created resource, instead tries to recreate it and fails (security group id) Terraform:从aws_instance资源获取volume_id - Terraform: Getting volume_id from aws_instance resource Terraform For_Each:如何引用创建的资源 ID - Terraform For_Each: How to reference created resource ID
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM