You need to enable JavaScript to run this app.
导航
其他命令
最近更新时间:2022.07.01 10:39:23首次发布时间:2022.05.17 12:06:31

terraform validate

用于快速检查配置文件中的语法错误,无需执行terraform plan/apply命令即可定位错误的详细位置和原因。

  • 检验正确时,回显如下:
    $ terraform validate
    Success! The configuration is valid.
    
  • 检验错误时,回显如下:
    $ terraform validate
    Error: Missing required argument
    
      on main.tf line 1, in resource "volcengine_vpc" "foo":
       1: resource "volcengine_vpc" "foo" {
    
    The argument "cidr_block" is required, but no definition was found.
    
    
    Error: Unsupported argument
    
      on main.tf line 3, in resource "volcengine_vpc" "foo":
       3:   cidr = "172.16.0.0/16"
    
    An argument named "cidr" is not expected here. Did you mean "id"?
    

terraform fmt

用于格式化当前目录及子目录下的所有的.tf文件,使代码风格统一。

terraform graph

用于根据配置文件、执行计划可视化的输出资源间依赖关系,且输出为DOT格式数据。

$ terraform graph
digraph {
        compound = "true"
        newrank = "true"
        subgraph "root" {
                "[root] provider.volcengine" [label = "provider.volcengine", shape = "diamond"]
                "[root] volcengine_security_group.foo1" [label = "volcengine_security_group.foo1", shape = "box"]
                "[root] volcengine_subnet.foo1" [label = "volcengine_subnet.foo1", shape = "box"]
                "[root] volcengine_subnet.foo2" [label = "volcengine_subnet.foo2", shape = "box"]
                "[root] volcengine_vpc.foo" [label = "volcengine_vpc.foo", shape = "box"]
                "[root] meta.count-boundary (EachMode fixup)" -> "[root] volcengine_security_group.foo1"
                "[root] provider.volcengine (close)" -> "[root] volcengine_security_group.foo1"
                "[root] root" -> "[root] meta.count-boundary (EachMode fixup)"
                "[root] root" -> "[root] provider.volcengine (close)"
                "[root] volcengine_security_group.foo1" -> "[root] volcengine_subnet.foo1"
                "[root] volcengine_security_group.foo1" -> "[root] volcengine_subnet.foo2"
                "[root] volcengine_subnet.foo1" -> "[root] volcengine_vpc.foo"
                "[root] volcengine_subnet.foo2" -> "[root] volcengine_vpc.foo"
                "[root] volcengine_vpc.foo" -> "[root] provider.volcengine"
        }
}

执行dot命令可以将输出结果转换为可视化图表:

$ 根据操作系统不同 安装 graphviz
$ terraform graph | dot -Tsvg > test.svg

terraform import

用于将存量资源导入state文件,命令为:terraform import <资源类型>.<资源名称> <资源ID>

$ terraform import volcengine_vpc.foo vpc-mjhlf3gs61hc5smt1ajya7ct
volcengine_vpc.foo: Importing from ID "vpc-mjhlf3gs61hc5smt1ajya7ct"...
volcengine_vpc.foo: Import prepared!
  Prepared volcengine_vpc for import
volcengine_vpc.foo: Refreshing state... [id=vpc-mjhlf3gs61hc5smt1ajya7ct]

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

terraform taint

用于手动将资源标记为污染状态 (tainted),标记后再次执行terraform apply命令时,Terraform会删除并重建该资源,命令为:terraform taint <资源类型>.<资源名称>。

$ terraform taint volcengine_subnet.foo
Resource instance volcengine_subnet.foo has been marked as tainted.

标记后执行terraform show命令可以看到相应资源已变为污染状态 (tainted):

$ terraform show
...
# volcengine_subnet.foo: (tainted)
resource "volcengine_subnet" "foo" {
  ...
}

terraform untaint

用于手动取消资源的污染状态 (tainted),使其恢复到正常状态,即terraform taint命令的逆操作,命令为:terraform untaint <资源类型>.<资源名称>

$ terraform untaint volcengine_subnet.foo
Resource instance volcengine_subnet.foo has been successfully untainted.

terraform console

用于打开交互式的控制台,并在控制台中进行表达式及内置函数的体验和测试。

$ terraform console
> length("Hello,world!")
12