Terraform init 问题:命令行参数太多
Terraform init problem: too many command line arguments
我正在尝试做的事情:我已经设置了一个自托管的 gitlab 实例,并且我正在使用 GitLab CI 自动化 terraform 过程,为此我必须设置一个 terraform后端。我按照官方文档中的步骤操作,但不幸的是 运行 在管道中 运行 时出错。这段代码在我的 .gitlab-ci.yml 文件中找到,所以它 运行s 在我的 GitLab 运行ner 上,它使用基于 python:3 的 docker 图像.9-破坏者 (Debian)
这里是有问题的代码,当然我编辑掉了IP地址:
- terraform init \
-backend-config="address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/" \
-backend-config="lock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock" \
-backend-config="unlock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock" \
-backend-config="username=root" \
-backend-config="password=$ACCESSTOKEN" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
不幸的是,执行上述命令时出现此错误:
Too many command line arguments. Did you mean to use -chdir?
以防万一有人遇到类似问题并碰巧发现这个 post,将我的脚本更改为这种格式解决了这个问题:
- export TF_ADDRESS=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/
- export TF_HTTP_ADDRESS=${TF_ADDRESS}
- export TF_HTTP_LOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_LOCK_METHOD=POST
- export TF_HTTP_UNLOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_UNLOCK_METHOD=DELETE
- export TF_HTTP_USERNAME=root
- export TF_HTTP_PASSWORD=$ACCESSTOKEN
- export TF_HTTP_RETRY_WAIT_MIN=5
- terraform init -reconfigure
Block Scalar also works
- >-
terraform init
-backend-config="address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}"
-backend-config="lock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
-backend-config="unlock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
-backend-config="username=${USERNAME}"
-backend-config="password=${TF_BOT_GLPAT}"
-backend-config="lock_method=POST"
-backend-config="unlock_method=DELETE"
-backend-config="retry_wait_min=5"
-backend-config="skip_cert_verification=true"
我正在尝试做的事情:我已经设置了一个自托管的 gitlab 实例,并且我正在使用 GitLab CI 自动化 terraform 过程,为此我必须设置一个 terraform后端。我按照官方文档中的步骤操作,但不幸的是 运行 在管道中 运行 时出错。这段代码在我的 .gitlab-ci.yml 文件中找到,所以它 运行s 在我的 GitLab 运行ner 上,它使用基于 python:3 的 docker 图像.9-破坏者 (Debian)
这里是有问题的代码,当然我编辑掉了IP地址:
- terraform init \
-backend-config="address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/" \
-backend-config="lock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock" \
-backend-config="unlock_address=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/lock" \
-backend-config="username=root" \
-backend-config="password=$ACCESSTOKEN" \
-backend-config="lock_method=POST" \
-backend-config="unlock_method=DELETE" \
-backend-config="retry_wait_min=5"
不幸的是,执行上述命令时出现此错误:
Too many command line arguments. Did you mean to use -chdir?
以防万一有人遇到类似问题并碰巧发现这个 post,将我的脚本更改为这种格式解决了这个问题:
- export TF_ADDRESS=http://ipaddress//api/v4/projects/3/terraform/state/terraform-state/
- export TF_HTTP_ADDRESS=${TF_ADDRESS}
- export TF_HTTP_LOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_LOCK_METHOD=POST
- export TF_HTTP_UNLOCK_ADDRESS=${TF_ADDRESS}/lock
- export TF_HTTP_UNLOCK_METHOD=DELETE
- export TF_HTTP_USERNAME=root
- export TF_HTTP_PASSWORD=$ACCESSTOKEN
- export TF_HTTP_RETRY_WAIT_MIN=5
- terraform init -reconfigure
Block Scalar also works
- >-
terraform init
-backend-config="address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}"
-backend-config="lock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
-backend-config="unlock_address=${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/terraform/state/${TF_STATE_NAME}/lock"
-backend-config="username=${USERNAME}"
-backend-config="password=${TF_BOT_GLPAT}"
-backend-config="lock_method=POST"
-backend-config="unlock_method=DELETE"
-backend-config="retry_wait_min=5"
-backend-config="skip_cert_verification=true"