Looks good tested on my end with a simple local resource.
Created a simple module which creates one file.
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.4.0"
}
}
}
resource "local_file" "file" {
filename = "${path.module}/destination"
source = "${path.module}/source"
}
Ran an init + apply.
local_file.swamp: Refreshing state... [id=5291767cb169477c0a03c53439ec85c8dc3aaf46]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# local_file.file will be created
+ resource "local_file" "file" {
+ content_base64sha256 = (known after apply)
+ content_base64sha512 = (known after apply)
+ content_md5 = (known after apply)
+ content_sha1 = (known after apply)
+ content_sha256 = (known after apply)
+ content_sha512 = (known after apply)
+ directory_permission = "0777"
+ file_permission = "0777"
+ filename = "./destination"
+ id = (known after apply)
+ source = "./source"
}
Plan: 1 to add, 0 to change, 0 to destroy.
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
local_file.file: Creating...
local_file.file: Creation complete after 0s [id=5291767cb169477c0a03c53439ec85c8dc3aaf46]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Updated the file to remove the local_file resource and added removed block. I’m guessing lifecycle + destroy is a new argument.
terraform {
required_providers {
local = {
source = "hashicorp/local"
version = "2.4.0"
}
}
}
# resource "local_file" "file" {
# filename = "${path.module}/destination"
# source = "${path.module}/source"
# }
removed {
from = local_file.file
lifecycle {
destroy = false
}
}
Ran an apply and got the proper feedback.
local_file.file: Refreshing state... [id=5291767cb169477c0a03c53439ec85c8dc3aaf46]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
Terraform will perform the following actions:
# local_file.file will no longer be managed by Terraform, but will not be destroyed
# (destroy = false is set in the configuration)
. resource "local_file" "file" {
- content_base64sha256 = "N+FgMd5soTK/NPAhWpf9OwVevfnr6DOVhD8CTislQ5s=" -> null
- content_base64sha512 = "/uaHo4s7YXkWFCLPOobf2izKhUbZtBKmlE3fnEfjM5kFzN4MAC4e8IK+Yl6QlbuqBPnpiI36dGCgtCX/7lVBCw==" -> null
- content_md5 = "f352cac61c815fe9d44770e65345367d" -> null
- content_sha1 = "5291767cb169477c0a03c53439ec85c8dc3aaf46" -> null
- content_sha256 = "37e16031de6ca132bf34f0215a97fd3b055ebdf9ebe83395843f024e2b25439b" -> null
- content_sha512 = "fee687a38b3b6179161422cf3a86dfda2cca8546d9b412a6944ddf9c47e3339905ccde0c002e1ef082be625e9095bbaa04f9e9888dfa7460a0b425ffee55410b" -> null
- directory_permission = "0777" -> null
- file_permission = "0777" -> null
- filename = "./destination" -> null
- id = "5291767cb169477c0a03c53439ec85c8dc3aaf46" -> null
- source = "./source" -> null
}
Plan: 0 to add, 0 to change, 0 to destroy.
╷
│ Warning: Some objects will no longer be managed by Terraform
│
│ If you apply this plan, Terraform will discard its tracking information for the following objects, but it will not delete them:
│ - local_file.file
│
│ After applying this plan, Terraform will no longer manage these objects. You will need to import them into Terraform to manage them again.
╵
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Very simple test, but might try more robust workings. Do other meta arguments work?
-provider, for_each, etc?
Update :
Did something a bit funkier and got a good result.
Tested creating an ECR resource via the AWS provider.
But then added a deleted block and an import block to the code.
Added a awscc_ecr_repository resource to see if I could migrate the resource from one provider to the next.
So config was :
terraform {
required_providers {
awscc = {
source = "hashicorp/awscc"
version = "0.66.0"
}
aws = {
source = "hashicorp/aws"
version = "5.29.0"
}
}
}
Had an initial ecr_repository :
resource "aws_ecr_repository" "this" {
name = "delete-test"
image_tag_mutability = "MUTABLE"
image_scanning_configuration {
scan_on_push = true
}
}
After creating, I commented out the old aws_ecr_repository, added a removed block, added an import block, and then added an awscc_ecr_repository resource.
# resource "aws_ecr_repository" "this" {
# name = "delete-test"
# image_tag_mutability = "MUTABLE"
# image_scanning_configuration {
# scan_on_push = true
# }
# }
removed {
from = aws_ecr_repository.this
lifecycle {
destroy = false
}
}
import {
id = "delete-test"
to = awscc_ecr_repository.this
}
resource "awscc_ecr_repository" "this" {
repository_name = "delete-test"
image_tag_mutability = "MUTABLE"
image_scanning_configuration = {
scan_on_push = true
}
lifecycle {
ignore_changes = [empty_on_delete, lifecycle_policy, repository_policy_text, tags]
}
}
Ran smoothly on the state removal and import.
awscc_ecr_repository.this: Preparing import... [id=delete-test]
aws_ecr_repository.this: Refreshing state... [id=delete-test]
awscc_ecr_repository.this: Refreshing state... [id=delete-test]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# aws_ecr_repository.this will no longer be managed by Terraform, but will not be destroyed
# (destroy = false is set in the configuration)
. resource "aws_ecr_repository" "this" {
- arn = "arn:aws:ecr:us-east-1:634211456147:repository/delete-test" -> null
- id = "delete-test" -> null
- image_tag_mutability = "MUTABLE" -> null
- name = "delete-test" -> null
- registry_id = "634211456147" -> null
- repository_url = "634211456147.dkr.ecr.us-east-1.amazonaws.com/delete-test" -> null
- tags = {} -> null
- tags_all = {} -> null
- encryption_configuration {
- encryption_type = "AES256" -> null
}
- image_scanning_configuration {
- scan_on_push = true -> null
}
}
# awscc_ecr_repository.this will be updated in-place
# (imported from "delete-test")
~ resource "awscc_ecr_repository" "this" {
arn = "arn:aws:ecr:us-east-1:634211456147:repository/delete-test"
+ empty_on_delete = (known after apply)
encryption_configuration = {
encryption_type = "AES256"
}
id = "delete-test"
image_scanning_configuration = {
scan_on_push = true
}
image_tag_mutability = "MUTABLE"
+ lifecycle_policy = (known after apply)
repository_name = "delete-test"
+ repository_policy_text = (known after apply)
repository_uri = "634211456147.dkr.ecr.us-east-1.amazonaws.com/delete-test"
+ tags = (known after apply)
}
Plan: 1 to import, 0 to add, 1 to change, 0 to destroy.
╷
│ Warning: Some objects will no longer be managed by Terraform
│
│ If you apply this plan, Terraform will discard its tracking information for the following objects, but it will not delete them:
│ - aws_ecr_repository.this
│
│ After applying this plan, Terraform will no longer manage these objects. You will need to import them into Terraform to manage them again.
╵
Do you want to perform these actions?
Terraform will perform the actions described above.
Only 'yes' will be accepted to approve.
Enter a value: yes
awscc_ecr_repository.this: Importing... [id=delete-test]
awscc_ecr_repository.this: Import complete [id=delete-test]
Hope this all helps.
Wrote up a quick post on it as well :