resource "aws_route53profiles_profile" "profile" {
  name = "Route53-${aws_route53_zone.main.zone_id}-profile"
}

resource "aws_route53profiles_resource_association" "profile_resource_association" {
  name         = "Route53-${aws_route53_zone.main.zone_id}-profile-resource-association"
  profile_id   = aws_route53profiles_profile.profile.id
  resource_arn = aws_route53_zone.main.arn
}

resource "aws_ram_resource_share" "profile_share" {
  name =  "Route53-${aws_route53_zone.main.zone_id}-profile-share"

  tags = {
    environment   = var.environment
    service_name  = "route53-profile"
    terraformed   = true
  }
}

resource "aws_ram_resource_association" "profile_share_resource_association" {
  resource_arn       = aws_route53profiles_profile.profile.arn
  resource_share_arn = aws_ram_resource_share.profile_share.arn
}

resource "aws_ram_principal_association" "profile_share_principal_association" {
  for_each = toset(var.ram_share_ou_ids)

  principal          = format("arn:aws:organizations::970903126758:ou/o-bqioddgr91/%s", each.value)
  resource_share_arn = aws_ram_resource_share.profile_share.arn
}
