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

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.

主站蜘蛛池模板: 龙海市| 嘉善县| 隆回县| 岱山县| 平陆县| 东乌珠穆沁旗| 腾冲县| 海南省| 布拖县| 泌阳县| 福海县| 石门县| 饶阳县| 通江县| 水富县| 肇州县| 垫江县| 金溪县| 临洮县| 武冈市| 托克逊县| 湖南省| 柘城县| 房山区| 平阴县| 天峻县| 友谊县| 景德镇市| 雷山县| 奎屯市| 张北县| 邵东县| 咸丰县| 乐至县| 潮安县| 商南县| 合阳县| 永泰县| 苏州市| 安吉县| 萍乡市|