无法使用gitlab CI/CD部署AK
我正在尝试使用以下gitlab管道在Azure上部署kubernetes群集,
image:
name: hashicorp/terraform:1.2.3
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
variables:
TF_ROOT: ${CI_PROJECT_DIR}/infrastructure
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}
cache:
key: my-services
paths:
- ${TF_ROOT}/.terraform
before_script:
- cd ${TF_ROOT}
- rm -rf .terraform
- terraform --version
- terraform init
stages:
- terraform_validate
- terraform_plan
- terraform_apply
terraform_validate_dev:
stage: terraform_validate
environment:
name: development
script:
- terraform validate
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
terraform_plan_dev:
stage: terraform_plan
environment:
name: development
script:
- terraform plan
- terraform plan-json
dependencies:
- terraform_validate_dev
artifacts:
name: plan deployment
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
rules:
- if: $CI_COMMIT_BRANCH == "development"
terraform_apply_dev:
stage: terraform_apply
environment:
name: development
script:
- terraform apply
dependencies:
- terraform_plan_dev
rules:
- if: $CI_COMMIT_BRANCH == "development"
when: manual
但是在Terraform_plan
阶段期间,我会收到以下错误:
"Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH."
有什么想法吗?
I'm trying to deploy a Kubernetes cluster on Azure using the following GitLab pipeline
image:
name: hashicorp/terraform:1.2.3
entrypoint:
- '/usr/bin/env'
- 'PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
variables:
TF_ROOT: ${CI_PROJECT_DIR}/infrastructure
TF_ADDRESS: ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${CI_PROJECT_NAME}
cache:
key: my-services
paths:
- ${TF_ROOT}/.terraform
before_script:
- cd ${TF_ROOT}
- rm -rf .terraform
- terraform --version
- terraform init
stages:
- terraform_validate
- terraform_plan
- terraform_apply
terraform_validate_dev:
stage: terraform_validate
environment:
name: development
script:
- terraform validate
rules:
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
terraform_plan_dev:
stage: terraform_plan
environment:
name: development
script:
- terraform plan
- terraform plan-json
dependencies:
- terraform_validate_dev
artifacts:
name: plan deployment
paths:
- ${TF_ROOT}/plan.cache
reports:
terraform: ${TF_ROOT}/plan.json
rules:
- if: $CI_COMMIT_BRANCH == "development"
terraform_apply_dev:
stage: terraform_apply
environment:
name: development
script:
- terraform apply
dependencies:
- terraform_plan_dev
rules:
- if: $CI_COMMIT_BRANCH == "development"
when: manual
but during the terraform_plan
stage, I receive the following error:
"Error: building AzureRM Client: please ensure you have installed Azure CLI version 2.0.79 or newer. Error parsing json result from the Azure CLI: launching Azure CLI: exec: "az": executable file not found in $PATH."
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最后,我能够找到问题。
不幸的是,@sytech提出的解决方案并没有解决问题,而是帮助我发现了真正的问题。
作为一个很好的做法,想要部署或使用Azure服务的自动化工具应始终使用服务主体。因此,我在Azure创建了一个服务主体,并试图将其与我的Terraform代码一起使用。
As the 文档说,要使用服务主体,我们需要创建以下环境变量:
一旦添加了这些环境变量,
Terraform_plan
阶段就可以完成其工作。Finally, I was able to find the problem.
Unfortunately, the solution proposed by @sytech did not solve the problem but helped me discover the real problem.
As a good practice, automated tools that want to deploy or use Azure services should always use service principals. For that reason, I created a service principal in Azure and was trying to use it with my Terraform code.
As the documentation says, to use the service principal we need to create the following environment variables:
Once I added these environment variables the
terraform_plan
stage was able to complete its work.正如错误消息所解释的那样,您必须安装azure cli 。
例如:
As the error message explains, you must install azure CLI.
For example: