0
votes

How to add new user in group existing, using Terraform?

I'm using: terraform import aws_iam_group.group [name-group]

My codigo

resource "aws_iam_group" "group"{
  name = "default"
}

resource "aws_iam_group_membership" "member"{
   name = "${var.aws_iam_group_member_name}"

   users = ["${aws_iam_user.user.name}"]

   group = "${aws_iam_group.group.name}"
}

resource "aws_iam_user" "user" {
  name = "${var.aws_iam_username}"
  path          = "/"
  force_destroy = true

}

Run:

terraform plan --target=aws_iam_group.group

terraform apply

1 error(s) occurred:

  • aws_iam_group.group: 1 error(s) occurred:

  • aws_iam_group.group: Error creating IAM Group default: EntityAlreadyExists: Group with name default already exists. status code: 409, request id: 54c27edd-02fb-11e9-b510-a7c53bb3d8e2

1

1 Answers

1
votes

Try referencing the group like this

data "aws_iam_group" "example" {
  group_name = "default"
}

That will pull in the group information and then you can reference the attributes for your user.

https://www.terraform.io/docs/providers/aws/d/iam_group.html