Code Monkey home page Code Monkey logo

Comments (11)

svanharmelen avatar svanharmelen commented on June 5, 2024 2

After playing around a bit, this turns out to be related to some logic[1][2] in Terraform that always tries to use relative paths in combination with how vim uses paths.

You can see the problem by running :pwd and :echo system('pwd'). Both commands will show different paths which is the root cause of this problem.

I think the easiest way to fix this is to make sure the terraform command is executed from the same directory by changing line 10:

- let output = system('terraform fmt -write ' . l:tmpfile)
+ let output = system('cd "' . resolve(expand('%:p:h')) . '" && terraform fmt -no-color -write ' . l:tmpfile)

Shall I make a PR for that @pgporada? Or do you prefer the solution @dimbleby suggested? Personally I think this solution is a bit more robust and any error messages displayed look just a bit cleaner/nicer. I'll just make a PR and let you decide.

[1] https://github.com/hashicorp/terraform/blob/master/command/fmt.go#L125
[2] https://github.com/hashicorp/terraform/blob/master/command/meta_config.go#L25

from vim-terraform.

lsc avatar lsc commented on June 5, 2024

This sounds like a vim configuration issue, not a vim-terraform specific one.

Have you tried to reproduce this without vim-terraform loaded ?

from vim-terraform.

ivan85viv avatar ivan85viv commented on June 5, 2024

yeah thats how I found its vim-terraform issue

from vim-terraform.

sedlund avatar sedlund commented on June 5, 2024

@ivan85viv I cannot reproduce - my system works fine.

from vim-terraform.

pgporada avatar pgporada commented on June 5, 2024

I'm curious if @ivan85viv has or had set let g:terraform_fmt_on_save=1 because that function will run terraform fmt -write ${TEMPFILE} which may be the cause of the symlink destruction. I'm investigating.

Edit: After testing, it's not due to let g:terraform_fmt_on_save=1. This was my test

cat << EOF > variables.tf
variable "var1" {
default = "example"
}
EOF
mkdir test && cd test
ln -s ../variables.tf variables.tf
vim variables.tf
:let g:terraform_fmt_on_save=1
:wq
ls -al
ls -al ../

from vim-terraform.

ivan85viv avatar ivan85viv commented on June 5, 2024

thanks for commenting ... no I do not have it set ... the only thing I set is let g:terraform_align=1 For the record this is my vimrc

" osx/mac and backspace movements enabling
set backspace=indent,eol,start

" remember history
set history=1000

execute pathogen#infect()
filetype plugin indent on

colorscheme delek

"# basic options
syntax on
set laststatus=2
" Enable display of matching open/close
set showmatch
set showmode

" Set the terminal title when editing
set title

" " Enable auto-indenting
set autoindent
"filetype plugin indent on

" Turn tabs into spaces
"set expandtab



" Search settings
set hlsearch " Highlight results
set ignorecase " Ignore casing of searches
set incsearch " Start showing results as you type
set smartcase " Be smart about case sensitivity when searching

" Backup settings
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
set undodir=~/.vim/undo

" Plugin Settings
let g:terraform_align=1

I just did the same steps you did and I can see that the sym link is destroyed and it becomes a file under the test dir.

from vim-terraform.

pgporada avatar pgporada commented on June 5, 2024

from vim-terraform.

pgporada avatar pgporada commented on June 5, 2024

Let me know if I need to re-open this issue.

from vim-terraform.

ivan85viv avatar ivan85viv commented on June 5, 2024

@pgporada Somehow I missed this - its High Sierra (10.13) my vim is also version 8.1.450

from vim-terraform.

diegombeltran avatar diegombeltran commented on June 5, 2024

I think I have a similar problem:

If I edit a .tf when changing dir to a symlinked path, TerraformFmt doesn't work:
imagen

If I edit the same file in the same location but without entering the symlinked path (By using absolute path or even the symlink but out of the path), it works.

Example->
/home/user/git/terraform/module.ec2/main.tf
/home/user/ec2/main.tf (ec2 is a symlink which points to the path above)

vim /home/user/git/terraform/module.ec2/main.tf---> terraformFmt works
vim /home/user/ec2/main.tf---> terraformFmt works
cd /home/user/ec2 and then vim main.tf---> terraformFmt doesn't work

Let me know If I should open another issue

from vim-terraform.

svanharmelen avatar svanharmelen commented on June 5, 2024

I'm having the exact same issue as described by @diegombeltran

from vim-terraform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.