0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【terraform import】「Error 409: Your previous request to create the named bucket succeeded and you already own it., conflict」となる場合の対処法

Posted at

エラー内容

既にGUIやgcloudコマンドなどで作成済みのリソースをTerraformで作成しようとした際にコンフリクトが起きて、terraform applyがエラーになります。

以下がtfstateを配置するバケットを定義した状態でapplyしようとした例です。

Error: googleapi: Error 409: Your previous request to create the named bucket succeeded and you already own it., conflict
│
│   with google_storage_bucket.store_of_tfstate,
│   on gcs.tf line 1, in resource "google_storage_bucket" "store_of_tfstate":
│    1: resource "google_storage_bucket" "store_of_tfstate" {

対処方法

terraform importコマンドを使用して対象のリソースをTerraform管理に取り込みます。

$ terraform import google_storage_bucket.store_of_tfstate your-bucket

google_storage_bucket.store_of_tfstate: Importing from ID "your-bucket"...
google_storage_bucket.store_of_tfstate: Import prepared!
  Prepared google_storage_bucket for import
google_storage_bucket.store_of_tfstate: Refreshing state... [id=your-bucket]

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.

再度applyすると成功します。

$ terraform applly
Apply complete! Resources: 0 added, 1 changed, 0 destroyed.
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?