官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 米脂县| 盐津县| 辽阳市| 顺昌县| 铁力市| 宁城县| 瓮安县| 惠州市| 湖南省| 新野县| 天长市| 临猗县| 兴仁县| 江陵县| 肇源县| 喀什市| 南京市| 屯门区| 北海市| 临猗县| 山东省| 盖州市| 肥城市| 贡觉县| 五寨县| 凉城县| 丰台区| 临汾市| 漾濞| 新巴尔虎左旗| 铜梁县| 永胜县| 汉源县| 墨玉县| 临潭县| 徐水县| 昌黎县| 乌苏市| 安阳市| 奉节县| 漯河市|