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

terraform refresh for local_file does not detect changes to file permissions #87

Open
ScottFred opened this issue Sep 18, 2021 · 1 comment

Comments

@ScottFred
Copy link

ScottFred commented Sep 18, 2021

Many authors that write blog posts, books, tutorials, and training courses about Terraform use the "local_provider" as a fast simple way of helping students start to experiment with Terraform, configuration files, etc. (Based on the Hashicorp documentation some warning is provided that suggests that local files are difficult to work with because of so many variations across operating systems, etc. )

$ terraform version
Terraform v1.0.7
on linux_amd64

Expected Behavior

terraform refresh should detect that the file permissions drifted from desired state

Actual Behavior

terraform refresh has no affect; specifically, it does not update the terraform.tfstate file to indicate the actual/real file permissions of the local file. Therefore, using terraform plan | apply (when drift has occurred) has no effect.

Terraform Configuration Files

resource "local_file" "pet" {
  filename = "pets.txt"
  content = "I love pets!"
  file_permission = "0600"
}

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:
$ terraform init
$ terraform apply

---- Showing terraform created pets.txt with correct filename, permissions, etc

$ ls -l
total 24
-rw-r--r-- 1 Scott staff 143B Sep 18 10:07 local.tf
-rw------- 1 Scott staff 12B Sep 18 11:47 pets.txt
-rw-r--r-- 1 Scott staff 828B Sep 18 11:47 terraform.tfstate

--- Introducing Drift from desired state documented in local.tf

$ chmod 666 pets.txt

--- Showing drift introduced

$ ls -l
total 24
-rw-r--r-- 1 Scott staff 143B Sep 18 10:07 local.tf
-rw-rw-rw- 1 Scott staff 12B Sep 18 11:47 pets.txt
-rw-r--r-- 1 Scott staff 828B Sep 18 11:47 terraform.tfstate

--- Executing terraform refresh to update the terraform.tfstate

$ terraform refresh
local_file.pet: Refreshing state... [id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]

--- Showing that the terraform.tfstate was not updated

$ cat terraform.tfstate

{
  "version": 4,
  "terraform_version": "1.0.7",
  "serial": 1,
  "lineage": "455112ef-4c3f-c33e-9855-cb32af5f5737",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "local_file",
      "name": "pet",
      "provider": "provider[\"registry.terraform.io/hashicorp/local\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "content": "I love pets!",
            "content_base64": null,
            "directory_permission": "0777",
            "file_permission": "0600",    <---- Expected this to be updated
            "filename": "pets.txt",
            "id": "7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68",
            "sensitive_content": null,
            "source": null
          },
          "sensitive_attributes": [],
          "private": "bnVsbA=="
        }
      ]
    }
  ]
}

--- Showing terraform apply has no effect

$ terraform apply
local_file.pet: Refreshing state... [id=7e4db4fbfdbb108bdd04692602bae3e9bd1e1b68]

No changes. Your infrastructure matches the configuration.

Terraform has compared your real infrastructure against your configuration and found no differences, so no changes are needed.

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

Affected Resource(s)

local file

Important Factoids

No special factoids

References

None

@ScottFred ScottFred changed the title terraform refresh does not detect changes to file permissions, ownership terraform refresh does not detect changes to file permissions Sep 18, 2021
@ScottFred ScottFred changed the title terraform refresh does not detect changes to file permissions terraform refresh for local_file does not detect changes to file permissions Sep 18, 2021
@junktext
Copy link

Yup, I can confirm this quirk is still occurring with the following versions of Terraform and the local provider:

Terraform v1.6.6
on linux_amd64
+ provider registry.terraform.io/hashicorp/local v2.4.1

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

No branches or pull requests

2 participants