tech:cloud_-_terraform_import
Différences
Ci-dessous, les différences entre deux révisions de la page.
| tech:cloud_-_terraform_import [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:cloud_-_terraform_import [2026/05/29 17:54] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Cloud - Terraform import - OpenTofu import | ||
| + | |||
| + | ## Importation d'une instance dans le " | ||
| + | |||
| + | `import.tf` | ||
| + | ~~~ | ||
| + | provider " | ||
| + | profile | ||
| + | region | ||
| + | } | ||
| + | |||
| + | resource " | ||
| + | # (resource arguments) | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | terraform import aws_instance.inst1 i-0127e23e987f1f08a | ||
| + | ~~~ | ||
| + | |||
| + | ## Création de la définition de notre instance | ||
| + | |||
| + | ~~~bash | ||
| + | terraform state list | ||
| + | terraform state show -no-color aws_instance.inst1 > aws_instance-inst1.tf | ||
| + | |||
| + | mv import.tf import.tf.bak | ||
| + | |||
| + | terraform fmt aws_instance-inst1.tf | ||
| + | ~~~ | ||
| + | |||
| + | Créer ce fichier | ||
| + | `region.tf` | ||
| + | ~~~ | ||
| + | provider " | ||
| + | access_key = "" | ||
| + | secret_key = "" | ||
| + | region = " | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ### Correction du code | ||
| + | |||
| + | ~~~bash | ||
| + | terraform plan -target=aws_instance.inst1 2>&1 | grep Err | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: " | ||
| + | Error: : invalid or unknown key: id | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Commenter les ligner en erreur (" | ||
| + | |||
| + | `aws_instance-inst1.tf` | ||
| + | ~~~ | ||
| + | # aws_instance.inst1: | ||
| + | resource " | ||
| + | ami = " | ||
| + | #arn = " | ||
| + | associate_public_ip_address | ||
| + | availability_zone | ||
| + | # | ||
| + | # | ||
| + | disable_api_termination | ||
| + | ebs_optimized | ||
| + | get_password_data | ||
| + | #id = " | ||
| + | # | ||
| + | instance_type | ||
| + | ipv6_address_count | ||
| + | ipv6_addresses | ||
| + | key_name | ||
| + | monitoring | ||
| + | # | ||
| + | # | ||
| + | private_ip | ||
| + | # | ||
| + | # | ||
| + | security_groups | ||
| + | source_dest_check | ||
| + | subnet_id | ||
| + | tags = { | ||
| + | " | ||
| + | } | ||
| + | tenancy | ||
| + | volume_tags = {} | ||
| + | vpc_security_group_ids = [ | ||
| + | " | ||
| + | ] | ||
| + | |||
| + | credit_specification { | ||
| + | cpu_credits = " | ||
| + | } | ||
| + | |||
| + | # root_block_device { | ||
| + | # delete_on_termination = true | ||
| + | # iops = 100 | ||
| + | # volume_id | ||
| + | # volume_size | ||
| + | # volume_type | ||
| + | # } | ||
| + | |||
| + | timeouts {} | ||
| + | } | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | #terraform plan -target=aws_instance.inst1 | ||
| + | terraform apply | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | ~~~ | ||
| + | Error: Error launching source instance: UnsupportedOperation: | ||
| + | status code: 400, request id: e6bb04ea-3f2a-47d7-a140-98d12857ceed | ||
| + | ~~~ | ||
| + | |||
| + | Commenter les lignes " | ||
| + | |||
| + | ~~~bash | ||
| + | terraform plan | grep 'known after apply' | ||
| + | #terraform taint aws_instance.inst1 | ||
| + | terraform state rm aws_instance.inst1 | ||
| + | terraform apply | ||
| + | ~~~ | ||
| + | |||
