我正在使用 GitLab CI 来运行 OpenTofu 管道。根目录中的
.gitlab-ci.yml
包含这个(它完美运行):
include:
- component: gitlab.com/components/opentofu/[email protected]
inputs:
version: 0.17.0
opentofu_version: 1.6.1
root_dir: provisioning/eks-test-1
state_name: eks-test-1
variables:
TF_STATE_NAME: eks-test-1
stages: [validate, build, deploy]
现在我想使用 OpenTofu 和 GitLab CI 管理多个环境。我找到了这篇 GitLab 文章,它解释了使用 Terraform 和 GitLab CI 的过程。
所以我像这样更新了我的配置:
主要.gitlab-ci.yml
include:
- provisioning/eks-test-1/.gitlab-ci.yml
注意:我稍后会包含多个。
新文件配置/eks-test-1/.gitlab-ci.yml
include:
- component: gitlab.com/components/opentofu/[email protected]
inputs:
version: 0.17.0
opentofu_version: 1.6.1
state_name: eks-test-1
variables:
TF_STATE_NAME: eks-test-1
stages: [validate, build, deploy]
fmt
和validate
步骤有效,但我在plan step
期间遇到此错误:
OpenTofu initialized in an empty directory!
The directory has no OpenTofu configuration files. You may begin working
with OpenTofu immediately by creating OpenTofu configuration files.
╷
│ Error: No configuration files
│
│ Plan requires configuration to be present. Planning without a configuration
│ would mark everything for destruction, which is normally not what is
│ desired. If you would like to destroy everything, run plan with the
│ -destroy option. Otherwise, create a OpenTofu configuration file (.tf file)
│ and try again.
╵
有人知道如何让它发挥作用吗?
正如@helder-sepulveda所指出的,问题是嵌套的
.gitlab-ci.yml
不是在他的目录中执行(意思是provisioning/eks-test-1
)而是在根目录中执行。
为了解决这个问题,我在
root_dir
中添加了 provisioning/eks-test-1/.gitlab-ci.yml
:
include:
- component: gitlab.com/components/opentofu/[email protected]
inputs:
version: 0.17.0
opentofu_version: 1.6.1
root_dir: provisioning/eks-test-1
state_name: eks-test-1
variables:
TF_STATE_NAME: eks-test-1
stages: [validate, build, deploy]