这是文档中显示的地形:
resource "aws_sagemaker_project" "example" {
project_name = "example"
service_catalog_provisioning_details {
product_id = aws_servicecatalog_product.example.id
}
}
我创建了一个 ID 为“prod-xxxxxxxxxxxxx”的服务目录产品。当我将服务目录产品 ID 替换为上述模板时,得到以下内容:
resource "aws_sagemaker_project" "example" {
project_name = "example"
service_catalog_provisioning_details {
product_id = aws_servicecatalog_product.prod-xxxxxxxxxxxxx
}
}
我运行 terraform plan,但出现以下错误:
A managed resource "aws_servicecatalog_product" "prod-xxxxxxxxxxxxx" has not been declared in the root module.
我需要做什么来修复这个错误?
由于文档不够清晰,为了像示例中那样进行这项工作,您首先必须在 Terraform 中创建服务目录产品,例如:
resource "aws_servicecatalog_product" "example" {
name = "example"
owner = [aws_security_group.example.id] # <---- This would need to be created first
type = aws_subnet.main.id # <---- This would need to be created first
provisioning_artifact_parameters {
template_url = "https://s3.amazonaws.com/cf-templates-ozkq9d3hgiq2-us-east-1/temp1.json"
}
tags = {
foo = "bar"
}
}
然后您可以在 SageMaker 项目中引用它,方法与示例中相同:
resource "aws_sagemaker_project" "example" {
project_name = "example"
service_catalog_provisioning_details {
product_id = aws_servicecatalog_product.example.id
}
}
创建的每个资源都有一组属性,其他资源、数据源或输出可以根据需要访问这些属性。为了理解这是如何工作的,我强烈建议阅读有关引用值的文档 [1]。由于您已经创建了 Service Catalog 产品,您唯一需要做的就是为产品 ID 提供字符串值:
resource "aws_sagemaker_project" "example" {
project_name = "example"
service_catalog_provisioning_details {
product_id = "prod-xxxxxxxxxxxxx"
}
}
当我无法理解参数的预期值时(例如,product_id
在这种情况下),我通常会阅读文档并查找 [2] 中的示例。注意:该示例是 CloudFormation,但它可以帮助您了解预期的值类型(例如,字符串、数字、布尔值)。
您还可以将创建的服务目录产品导入 Terraform,以便使用 IaC [3] 对其进行管理。terraform import
在尝试之前,您应该了解尽管的所有含义[4]。
[1] https://www.terraform.io/language/expressions/references
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句