Использование поставщика Terraform local-exec для запуска скрипта powershell для создания ILB ASE в Azure (ILB ASE еще не поддерживается напрямую поставщиком Terraform Azure, поэтому мы делаем это вручную в Powershell). Мы не хотим создавать ASE с внутренним балансировщиком нагрузки, пока local-exec работает в режиме плана, так как эта операция занимает 2 часа. Есть ли способ для local-exec определить, работает ли скрипт terraform в режиме планирования или применения?
Средство подготовки local-exec
не будет работать в режиме плана, так что это не проблема.
Provisioner не запускается на этапе планирования.
~\projects\test ⚡ ◷ 3:31:16 PM
▶ cat .\main.tf
resource "null_resource" "localtest" {
provisioner "local-exec" {
command = "New-Item -Name test"
interpreter = ["pwsh", "-Command"]
}
}
~\projects\test ⚡ ◷ 3:31:19 PM
▶ terraform init
Initializing the backend...
Initializing provider plugins...
- Checking for available provider plugins...
- Downloading plugin for provider "null" (hashicorp/null) 2.1.2...
The following providers do not have any version constraints in configuration,
so the latest version was installed.
To prevent automatic upgrades to new major versions that may contain breaking
changes, it is recommended to add version = "..." constraints to the
corresponding provider blocks in configuration, with the constraint strings
suggested below.
* provider.null: version = "~> 2.1"
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.
~\projects\test ⚡ ◷ 3:31:26 PM
▶ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
------------------------------------------------------------------------
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Terraform will perform the following actions:
# null_resource.localtest will be created
+ resource "null_resource" "localtest" {
+ id = (known after apply)
}
Plan: 1 to add, 0 to change, 0 to destroy.
------------------------------------------------------------------------
Note: You didn't specify an "-out" parameter to save this plan, so Terraform
can't guarantee that exactly these actions will be performed if
"terraform apply" is subsequently run.
~\projects\test ⚡ ◷ 3:31:32 PM
▶ dir test
Get-ChildItem: Cannot find path 'C:\Users\pearcec\projects\test\test' because it does not exist.
~\projects\test ⚡ ⨯ ◷ 3:32:01 PM
▶ terraform apply -auto-approve
null_resource.localtest: Creating...
null_resource.localtest: Provisioning with 'local-exec'...
null_resource.localtest (local-exec): Executing: ["pwsh" "-Command" "New-Item -Name test"]
null_resource.localtest (local-exec): Directory: C:\Users\pearcec\projects\test
null_resource.localtest (local-exec): Mode LastWriteTime Length Name
null_resource.localtest (local-exec): ---- ------------- ------ ----
null_resource.localtest (local-exec): -a--- 7/22/2020 3:32 PM 0 test
null_resource.localtest: Creation complete after 0s [id=5060708809844859353]
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
~\projects\test ⚡ ◷ 3:32:22 PM
▶ dir test
-a--- 7/22/2020 3:32 PM 0 test
~\projects\test ⚡ ◷ 3:32:25 PM
▶
Я не очень понимаю ваш вопрос. Он находится в режиме планирования при запуске
terraform plan
и в режиме применения при запускеterraform apply
. Есть ли здесь какие-либо проблемы?