通过terraform为多个用户创建SageMaker实例

时间:2020-06-29 03:04:14

标签: terraform aws-cli terraform-provider-aws amazon-sagemaker

我有以下用于从terraform创建SageMaker实例的模块。 以下是我的sagemaker模块:-

resource "aws_sagemaker_notebook_instance" "sagemaker" {
count                 = length(var.users)
name                  = "${var.notebook_prefix}-${var.users[count.index]}-notebook"
role_arn              = length(var.role_arn) > 0 ? element(var.role_arn, count.index) : ""
instance_type         = var.instance_type
direct_internet_access = "Disabled"
subnet_id             = var.subnet_id
security_groups       = var.security_groups
lifecycle_config_name = "lifecycle-${var.users[count.index]}"
}

下面是我的main.tf文件:-

module "sagemaker-notebook" {
source          = "above module"
notebook_prefix = "prod"
resource_prefix = "abc"
role_arn        =  <arn>
instance_type   = "ml.m5.2xlarge"
users           = values(var.user)
security_groups = [<id>]
subnet_id       = "<subnet_id>"
on_start        = base64encode(data.template_file.init.rendered)
on_create       = base64encode(data.template_file.create.rendered)
}

下面是我的变量。tf

variable "user" {
type = "map"
default = {
"1"   = "abc"
"2"   = "def"
"3"   = "xyz"
"4"   = "pqr"
}
}

我面临的问题如下:- 每当我从上述变量中​​删除/添加任何用户时,它都会要求我销毁所有资源并重新创建所有资源,因为它试图在它们所在的位置相互替换,例如,如果我从列表中删除“ pqr”,则它将替换其中的每一个。 我们可以忽略这种行为吗?

0 个答案:

没有答案