尝试使用 Docker 镜像的 Terraform 在 Windows 上

The aim

我想在Windows上执行Terraform,但不想安装该命令,所以我想是否可以通过Docker镜像来解决。

那里让我陷入困境… wǒ …)

Docker镜像

 

因为是由HashiCorp创建的,所以可以放心。

用法上,

docker run -i -t hashicorp/terraform:latest plan

尽管有所提及,但这容易引导误解。

执行。

在查看教程时进行操作。
https://learn.hashicorp.com/tutorials/terraform/install-cli?in=terraform/aws-get-started

在合适的目录下创建一个名为main.tf的文件。


C:\dev\test\teraform>docker run -i -t  hashicorp/terraform:latest init
Terraform initialized in an empty directory!

The directory has no Terraform configuration files. You may begin working
with Terraform immediately by creating Terraform configuration files.    

C:\dev\test\teraform>

失败……汗流满面。

在查询时,似乎没有人遇到过与我相同的问题。。。
https://stackoverflow.com/questions/62250930/terraform-official-docker-image-cant-see-my-files

C:\dev\test\teraform>docker run -v "c:\dev\test\teraform":/work -w /work hashicorp/terraform:latest init

Initializing the backend...

Initializing provider plugins...
- Reusing previous version of kreuzwerker/docker from the dependency lock file
- Using previously-installed kreuzwerker/docker v2.16.0

Terraform has been successfully initialized!

You may now begin working with Terraform. Try running "terraform plan" to see  
any changes that are required for your infrastructure. All Terraform commands  
should now work.

If you ever set or change modules or backend configuration for Terraform,      
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.

C:\dev\test\teraform>

办到了! !)

bannerAds