Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support moving from null_resource to terraform_data #35163

Merged
merged 1 commit into from
May 16, 2024

Conversation

bflad
Copy link
Member

@bflad bflad commented May 15, 2024

This change enables the built-in provider's terraform_data managed resource to work with the moved configuration block where the from address is a null_resource managed resource type from the official hashicorp/null provider. It produces no plan differences for typical configurations and specifically helps practitioners from re-running provisioners while moving resource types.

In addition to the unit testing, this was manually tested with the following configurations and outputs:

Initial configuration (no triggers):

terraform {
  required_providers {
    null = {
      source  = "hashicorp/null"
      version = "3.2.2"
    }
  }
}

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

Moved configuration (no triggers):

resource "terraform_data" "example" {
  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

moved {
  from = null_resource.example
  to   = terraform_data.example
}

Moved output (no triggers):

$ terraform apply
terraform_data.example: Refreshing state... [id=892002337455008838]

Terraform will perform the following actions:

  # null_resource.example has moved to terraform_data.example
    resource "terraform_data" "example" {
        id = "892002337455008838"
    }

Plan: 0 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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Initial configuration (with triggers):

terraform {
  required_providers {
    null = {
      source  = "hashicorp/null"
      version = "3.2.2"
    }
  }
}

resource "null_resource" "example" {
  triggers = {
    examplekey = "examplevalue"
  }

  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

Moved configuration (with triggers):

resource "terraform_data" "example" {
  triggers_replace = {
    examplekey = "examplevalue"
  }

  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

moved {
  from = null_resource.example
  to   = terraform_data.example
}

Moved output (with triggers):

$ terraform apply
terraform_data.example: Refreshing state... [id=1651348367769440250]

Terraform will perform the following actions:

  # null_resource.example has moved to terraform_data.example
    resource "terraform_data" "example" {
        id               = "1651348367769440250"
        # (1 unchanged attribute hidden)
    }

Plan: 0 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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Target Release

1.9.0

Draft CHANGELOG entry

ENHANCEMENTS

  • terraform_data: Enabled moved configuration refactoring from the hashicorp/null provider null_resource managed resource

This change enables the built-in provider's `terraform_data` managed resource to work with the `moved` configuration block where the `from` address is a `null_resource` managed resource type from the official `hashicorp/null` provider. It produces no plan differences for typical configurations and specifically helps practitioners from re-running provisioners while moving resource types.

In addition to the unit testing, this was manually tested with the following configurations and outputs:

Initial configuration (no `triggers`):

```terraform
terraform {
  required_providers {
    null = {
      source  = "hashicorp/null"
      version = "3.2.2"
    }
  }
}

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}
```

Moved configuration (no `triggers`):

```terraform
resource "terraform_data" "example" {
  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

moved {
  from = null_resource.example
  to   = terraform_data.example
}
```

Moved output (no `triggers`):

```console
$ terraform apply
terraform_data.example: Refreshing state... [id=892002337455008838]

Terraform will perform the following actions:

  # null_resource.example has moved to terraform_data.example
    resource "terraform_data" "example" {
        id = "892002337455008838"
    }

Plan: 0 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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
```

Initial configuration (with `triggers`):

```terraform
terraform {
  required_providers {
    null = {
      source  = "hashicorp/null"
      version = "3.2.2"
    }
  }
}

resource "null_resource" "example" {
  triggers = {
    examplekey = "examplevalue"
  }

  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}
```

Moved configuration (with `triggers`):

```terraform
resource "terraform_data" "example" {
  triggers_replace = {
    examplekey = "examplevalue"
  }

  provisioner "local-exec" {
    command = "echo 'Hello, World!'"
  }
}

moved {
  from = null_resource.example
  to   = terraform_data.example
}
```

Moved output (with `triggers`):

```console
$ terraform apply
terraform_data.example: Refreshing state... [id=1651348367769440250]

Terraform will perform the following actions:

  # null_resource.example has moved to terraform_data.example
    resource "terraform_data" "example" {
        id               = "1651348367769440250"
        # (1 unchanged attribute hidden)
    }

Plan: 0 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

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
```
@bflad bflad merged commit 0cbab0f into main May 16, 2024
6 checks passed
@bflad bflad deleted the bflad/move_null_resource branch May 16, 2024 19:54
Copy link

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants