Amazon web services 如何在terraform中将JS文件作为模块进行源代码生成?

Amazon web services 如何在terraform中将JS文件作为模块进行源代码生成?,amazon-web-services,terraform,terraform-provider-aws,Amazon Web Services,Terraform,Terraform Provider Aws,我正在努力做到以下几点: module “git_file” { source = "git::https://githubXX.com/abc.js" } data "archive_file" “init” { type = "zip" git_file = "${module.git_file.source}" } 我无法完成上述工作。无论使用https://还是ssh:// 如何将JS文件作为terraform中的模块来源?模块块用于将terraform模块及其参与

我正在努力做到以下几点:

module “git_file” {
  source = "git::https://githubXX.com/abc.js"
}

data "archive_file" “init” {
type        = "zip"
git_file = "${module.git_file.source}"
}
我无法完成上述工作。无论使用https://还是ssh://


如何将JS文件作为terraform中的模块来源?

模块块用于将terraform模块及其参与的资源加载到特定模块路径下的模块中。它不能按你想要的方式使用

调用模块意味着将该模块的内容包含到 为其输入变量指定特定值的配置。模块 使用模块块从其他模块内调用:

module "servers" {
  source = "./app-cluster"

  servers = 5
}
资料来源:

它有点像其他语言中的import、require或include。它不能用于下载用于Terraform模块的文件

您可以使用来执行您描述的操作:

data "http" "git_file" {
  url = "https://githubXX.com/abc.js"
}

data "archive_file" “init” {
  type        = "zip"
  git_file = data.http.git_file.body
}
这也不可能像您预期的那样起作用。您肯定需要一个到GitHub的原始源代码链接

你应该考虑一个替代的解决方案,包括在同一个存储库中使用abcjs,或者使用一个脚本下载它。

resource "null_resource" "" {
  provisioner "local-exec" {
    command = "git clone https://github.com/..."
  }
}

然后,您将在本地使用这些文件,就像在自己的shell上克隆git一样。我不推荐这个。它很脆弱,可能会与其他工具发生奇怪的交互。

-我将如何使用null_资源来使用它?您需要更好地独立寻找这些解决方案。你要找的答案很容易找到。足智多谋是这一职业的基本要求。我已经更新了解决方案,以根据请求提供null_资源示例。