skip to Main Content

I don’t know how to create a dynamic resource module

resource "aws_sagemaker_user_profile" "user_profile" {
  domain_id = aws_sagemaker_domain.sagemaker_domain.id
  user_profile_name = var.user_profile_name
}

for every sagemaker user. The idea would be that this block would be displayed for each username entered in the tfvars file with the user_profile_name variable.

2

Answers


  1. Chosen as BEST ANSWER

    yes it's exactly what I wanted.Thank you very much Marko!!.


  2. If I understood the question, you want to create a Sagemaker user profile for every value defined under the user_profile_name variable. To achieve that, you would first need to define the variable like this:

    variable "user_profile_name" {
      type    = set
      default = ["user1", "user2"] # you can add as many as you like
    }
    

    Since you want to create a profile for each of the values, you can use the for_each meta-argument. The final code would then look like:

    resource "aws_sagemaker_user_profile" "user_profile" {
      for_each          = var.user_profile_name
      domain_id         = aws_sagemaker_domain.sagemaker_domain.id
      user_profile_name = each.key
    }
    

    Since the variable is defined as a set, the each.key and each.value give the same result.

    each.value — The map value corresponding to this instance. (If a set was provided, this is the same as each.key.)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search