궁금한게 많은 개발자 노트

[ IaC ] Terraform AWS current caller identity 본문

DevOps

[ IaC ] Terraform AWS current caller identity

궁금한게 많은 개발자 2023. 10. 30. 20:23

aws_caller_identity

terraform version 0.7.1부터 지원하는, 자신의 계정(account_id)또는 다른 계정의 account id, user id, arn을 참조하고자 할 때 사용되는 data resource입니다.

특정 aws resource에서 account_id를 포함하는 경우에도 하드코딩 하지 않고 손 쉽게 대체할수 있습니다.

data "aws_caller_identity" "current" {}

output "account_id" {
  value = "${data.aws_caller_identity.current.account_id}"
}

output "caller_arn" {
  value = "${data.aws_caller_identity.current.arn}"
}

output "caller_user" {
  value = "${data.aws_caller_identity.current.user_id}"
}

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity

 

Terraform Registry

 

registry.terraform.io

 

또한 terraform에서 aws account관련 설정할 때 자주 사용되는 data resource인 aws_iam_group에 대해 알아보려 합니다.

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

특정 그룹의 정보에 대해 알 수 있으며, policy나 role을 group단위로 적용할 때 참조하기 위해 주로 사용됩니다.

arn, group_id, path, users에 대한 참조가 가능하며 users는 arn, path, user_id, user_name의 정보를 가지고 있습니다.

 

This data source exports the following attributes in addition to the arguments above:

  • arn - Group ARN.
  • group_id - Stable and unique string identifying the group.
  • path - Path to the group.
  • users - List of objects containing group member information. See below.

users

  • arn - User ARN.
  • path - Path to the IAM user.
  • user_id - Stable and unique string identifying the IAM user.
  • user_name - Name of the IAM user.

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_group

 

Terraform Registry

 

registry.terraform.io

 

Comments