Comments (11)
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.
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.
yeah thats how I found its vim-terraform issue
from vim-terraform.
@ivan85viv I cannot reproduce - my system works fine.
from vim-terraform.
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.
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.
from vim-terraform.
Let me know if I need to re-open this issue.
from vim-terraform.
@pgporada Somehow I missed this - its High Sierra (10.13) my vim is also version 8.1.450
from vim-terraform.
I think I have a similar problem:
If I edit a .tf when changing dir to a symlinked path, TerraformFmt doesn't work:
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.
I'm having the exact same issue as described by @diegombeltran
from vim-terraform.
Related Issues (20)
- Is there a possibility to handle .hcl files HOT 1
- Allow hot-swapping of g:terraform_align HOT 3
- Format on save not working HOT 2
- Maintainer/Contributor
- Syntax highlighting for string interpolation should not match double dollar sign HOT 1
- automatic alignment does too much when we have blocks within blocks
- Add ability to autoformat hcl files on save HOT 2
- vim does not redraws after the terraform fmt HOT 3
- :wq (save and quit) takes 5 seconds when vim-terraform is loaded HOT 5
- Folding Not Working HOT 6
- Error detected while proccesing function <SNR>214_VimCloseCallBack[11]..<SNR>214_VimExitCallBack[22] HOT 4
- Question - TerraformFMT HOT 3
- terraform_fmt_on_save not working with in after/ftplugin/terraform.vim HOT 1
- FR: Use terraform syntax highlighting for terraform template .tftpl files HOT 5
- .tf filetype detection seems broken in more recent Vim/NeoVim versions? HOT 3
- Block comments converting to highlighted during navigation HOT 2
- Indenter overly detecting block comments inside of a heredoc HOT 1
- :Terraform command is absent HOT 1
- Enable commands for .hcl files HOT 1
- Add tenv / opentofu support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-terraform.