Difference between revisions of "Terraform import"

From wikieduonline
Jump to navigation Jump to search
 
(38 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
* https://www.terraform.io/docs/cli/import/index.html
+
Before using <code>terraform import</code> ([https://www.terraform.io/docs/cli/import/index.html doc]) you must manually write a resource [[configuration block]] for the resource.
  
 +
*
  
* <code>[[terraform]] import [[aws_instance]].my_foo i-abcd1234</code>
+
* https://discuss.hashicorp.com/t/what-happens-to-imported-resources-on-terraform-destroy/4601
  
* <code>terraform import aws_default_subnet.public_subnet subnet-9d4a7b6c</code>
+
== Examples ==
 +
* <code>[[terraform import --help]]</code>
 +
* <code>[[terraform import aws_instance.my_foo i-abcd1234]]</code> <ref>https://www.terraform.io/docs/cli/import/index.html</ref>
 +
* <code>terraform import [[aws_default_subnet]].public_subnet subnet-9d4a7b6c</code>
 +
* <code>terraform import [[aws_default_vpc]].default vpc-a01106c2</code>
 +
* <code>[[terraform import aws identitystore user.testimport "d-123456789/c12343345-1234-4321-12334-c121212121a"]]</code>
 +
* <code>[[terraform import aws_cloudfront_distribution.distribution E74FTE3EXAMPLE]]</code>
  
== With errors ==
+
== Errors ==
 +
* <code>[[terraform import aws_identitystore_user.testimport testimport]]</code>
 +
 
 +
aws_identitystore_user.testimport: Importing from ID "testimport"...
 +
aws_identitystore_user.testimport: Import prepared!
 +
  Prepared aws_identitystore_user for import
 +
aws_identitystore_user.testimport: Refreshing state... [id=testimport]
 +
 +
│ Error: reading [[AWS SSO Identity Store User]] (testimport): expected a [[resource id]] in the form: identity-store-id/user-id
 +
│ 
 +
 +
 +
 
 +
[[terraform]] import aws_identitystore_user.testimport d-9a672d8036/testimport
 +
aws_identitystore_user.testimport: Importing from ID "d-123456789/testimport"...
 +
aws_identitystore_user.testimport: Import prepared!
 +
  Prepared aws_identitystore_user for import
 +
aws_identitystore_user.testimport: Refreshing state... [id=d-123456789/testimport]
 +
 +
│ Error: reading AWS SSO Identity Store User (d-123456789/testimport): [[operation error identitystore]]:
 +
DescribeUser, [[https response error StatusCode]]: 400, RequestID: 362370f8-3b16-4d14-9e28-64265f76e1a4,
 +
ValidationException:
 +
 +
 +
 +
 
 +
== Errors ==
 
* <code>[[terraform import aws_key_pair.MyNewKeyInTerraform YourExistingKeyName]]</code>
 
* <code>[[terraform import aws_key_pair.MyNewKeyInTerraform YourExistingKeyName]]</code>
 
* <code>[[terraform import aws key pair.MyNewKeyInTerraform YourExistingKeyName2]]</code>
 
* <code>[[terraform import aws key pair.MyNewKeyInTerraform YourExistingKeyName2]]</code>
 
+
* <code>[[Error: Reference to undeclared resource]]</code>
  
 
== Related terms ==
 
== Related terms ==
 
* [[Terraform modules]]
 
* [[Terraform modules]]
* [[Terraform resource]]
+
* [[Terraform resources]]: <code>[[resource]]</code>
 +
* <code>[[terraform.tfstate]]</code>
 +
* [[Terraform activities]]
 +
* <code>[[terraform apply -refresh-only]]</code>
 +
* Cloudformation: <code>[[Cloudformation: --resources-to-import|--resources-to-import]]</code>
 +
* <code>[[terraform state rm]]</code>
 +
* <code>[[import]] block allows import operations to be defined in code</code>
  
 
== See also ==
 
== See also ==
* {{terraform cmd}}
+
* {{tf import}}
* {{terraform}}
+
* {{tf files}}
  
 
[[Category:Terraform]]
 
[[Category:Terraform]]

Latest revision as of 14:15, 1 August 2024

Before using terraform import (doc) you must manually write a resource configuration block for the resource.

Examples[edit]

Errors[edit]

aws_identitystore_user.testimport: Importing from ID "testimport"...
aws_identitystore_user.testimport: Import prepared!
  Prepared aws_identitystore_user for import
aws_identitystore_user.testimport: Refreshing state... [id=testimport]
╷
│ Error: reading AWS SSO Identity Store User (testimport): expected a resource id in the form: identity-store-id/user-id
│  
│ 
╵
terraform import aws_identitystore_user.testimport d-9a672d8036/testimport
aws_identitystore_user.testimport: Importing from ID "d-123456789/testimport"...
aws_identitystore_user.testimport: Import prepared!
  Prepared aws_identitystore_user for import
aws_identitystore_user.testimport: Refreshing state... [id=d-123456789/testimport]
╷
│ Error: reading AWS SSO Identity Store User (d-123456789/testimport): operation error identitystore: 
DescribeUser, https response error StatusCode: 400, RequestID: 362370f8-3b16-4d14-9e28-64265f76e1a4, 
ValidationException: 
│ 
│ 
╵

Errors[edit]

Related terms[edit]

See also[edit]

  • https://www.terraform.io/docs/cli/import/index.html
  • Advertising: