- Learning DevOps
- Mikael Krief
- 178字
- 2021-06-24 12:32:08
Validating the code
Along the same lines, Terraform has a command that validates the code and allows us to detect possible errors before executing the plan or apply command.
Let's take the example of this code extract:
resource "azurerm_public_ip" "pip" {
name = var.ip-name
location = var.location
resource_group_name = "${azurerm_resource_group.rg.name}"
allocation_method = "Dynamic"
domain_name_label = "bookdevops"
}
In the name property, we use an ip-name variable that has not been declared or instantiated with any value.
Executing the terraform plan command would return an error:

And because of this error, in a CI/CD process, it could delay the deployment of the infrastructure.
In order to detect errors in the Terraform code as early as possible in the development cycle, execute the following command, which validates all Terraform files in the directory:
terraform validate
The following screenshot shows the execution of this command:

We observe the same error as the one returned by the plan command.
We have just seen Terraform's main command lines. Let's go a little deeper with the integration of Terraform into a CI/CD process.
- 嗜鉻細胞瘤、副神經(jīng)節(jié)瘤及相關(guān)綜合征
- 健康快車的故事
- 心理障礙的疏導(dǎo)自助
- 現(xiàn)代口腔正畸技術(shù)與臨床思維(現(xiàn)代實用口腔醫(yī)學(xué)著譯叢書)
- 皮膚美容激光治療原理與技術(shù)
- 眼科護理與操作指南
- Python Machine Learning Cookbook(Second Edition)
- 走進孤獨的世界:為家長專業(yè)解讀自閉癥
- 乳腺癌患者自我管理手冊
- 吞咽障礙康復(fù)指南
- 普胸外科手術(shù)精解
- 非婦科脫落細胞學(xué)
- 脊髓損傷者生活自助手冊
- 運動損傷的預(yù)防、治療與恢復(fù)
- 中西醫(yī)結(jié)合腎臟病學(xué)研究新進展