如何使用 terraform 创建 aws sagemaker 项目?

awscoder

这是文档中显示的地形:

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

[2] https://docs.amazonaws.cn/en_us/AWSCloudFormation/latest/UserGuide/aws-resource-sagemaker-project.html#aws-resource-sagemaker-project--examples--SageMaker_Project_Example

[3] https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/servicecatalog_product#import

[4] https://www.terraform.io/cli/commands/import

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用Terraform和AWS API Gateway创建API代理

如何使用AWS CLI调用SageMaker Endpoint(

如何使用Lambda和API网关部署由AWS Sagemaker创建的乳腺癌预测终端节点?

使用Terraform创建aws_flow_log时访问错误

如何实现与AWS SageMaker结合使用的PyTorch数据集?

如何使用Terraform创建默认的AWS VPC?

如何使用Terraform创建具有访问权和密钥的AWS IAM服务账户

如何使用Terraform创建AWS Cognito用户

Terraform-如何创建一个AWS MediaConvert JobTemplate?

Terraform:从快照创建AWS Lightsail实例

如何在AWS中已经存在的Terraform资源中使用(手动创建)?

使用Terraform创建AWS服务角色

使用AWS Sagemaker Boto创建多模型端点

如何使用Terraform创建无假设角色策略的AWS IAM角色?

在子AWS账户中创建Terraform资源

为什么使用Boto3使用AWS Sagemaker创建终端需要这么长时间?

使用AWS CDK创建用于构建Docker映像的CodeBuild项目

创建使用Terraform创建新的AWS ecs taskdefinition版本时如何保留

使用 terraform 在非默认 VPC 中创建 AWS RDS 实例

无法使用 AWS-Lambda 调用在 sagemaker 中创建的 XG-Boost 端点

如何通过 Terraform 在 AWS 中创建堆栈?

使用 terraform 在 AWS 中创建安全组时如何为源选择安全组 ID

为什么 AWS SageMaker 创建 S3 存储桶

如何使用 AWS SageMaker Notebook 实例部署预训练模型?

使用 terraform 创建 aws 资源时无法解决依赖冲突

使用 Terraform 创建/销毁 AWS 账户?

如何使用 terraform 在 AWS 中为自定义 AMI 创建创建临时实例?

使用 Terraform 通过 aws_eks_cluster 创建 EKS 集群后如何公开 kubeconfig 文件?

通过 Terraform 创建 sagemaker 笔记本实例