Is there a way to add access logs on already existing application load balancer in aws using terraform

huangapple go评论59阅读模式
英文:

Is there a way to add access logs on already existing application load balancer in aws using terraform

问题

我使用k8的Helm图表创建了ALB。现在我想使用Terraform在其上启用访问日志。我尝试使用数据源,但似乎不起作用,而且在计划时出现错误。

错误信息是:
"无法配置'arn'的值:其值将根据应用此配置的结果自动决定。"

不确定出了什么问题。

英文:

I have ALB created using k8's helm charts.Now I want to enable access logs on top of it using terraform. I am trying to use data source but it seems not working and I am getting error while I plan it.

data "aws_lb" "ecs_public_alb" {
  name = "my-load-balancer-name"
}

resource "aws_lb" "example" {
  arn                = data.aws_lb.existing_lb.arn
  load_balancer_type = "application"

  access_logs {
    bucket  = "example-bucket"
    prefix  = "lb-access-logs"
    enabled = true
  }

  tags = {
    Terraform   = "true"
    Environment = "dev"
  }
}

The error I am getting is
Can't configure a value for "arn": its value will be decided automatically based on the result of applying this configuration.

Not sure what is going wrong here

答案1

得分: 2

你必须先导入你的ALB到TF中,然后才能使用TF进行修改。你现在所做的resource "aws_lb" "example"是试图创建一个新的ALB,而不是使用现有的ALB。

英文:

You have to import your alb into TF first, before you can modify it using TF. What you are doing now with resource "aws_lb" "example" is trying to create new alb, rather then using the existing one.

答案2

得分: 0

错误的近因是 arn 是只读属性,无法对其进行写操作。arn 将由 AWS 在资源创建后设置。

真正的问题在于你需要决定是 Helm 还是 Terraform 来管理负载均衡器。不能两者兼得,既用 Helm 创建负载均衡器,又用 Terraform 修改它。如果你尝试更新或协调 Helm chart,它将删除日志配置。

这是我会做的:

  • 删除 Helm 发布并销毁负载均衡器
  • 使用 Terraform 创建一个具有日志配置的新负载均衡器

如果你绝对不能重新创建负载均衡器,那么找到一种方法阻止 Helm 在将来管理它。

来源:我曾尝试让 Kubernetes 和 Terraform 共享资源管理责任,但结果非常糟糕。最好有明确的边界,只有一个系统管理资源。

英文:

The proximal cause of your error is that arn is a read-only attribute and you cannot write to it. The arn will be set by AWS once the resource has been created.

The real issue is that you need to decide what will manage the load balancer, Helm or Terraform. You can't have it both ways, creating the load balancer with Helm and then modifying it with Terraform. If you ever try to update or reconcile the Helm chart, it will remove the logging configuration.

Here's what I would do:

  • Remove the Helm release and destroy the load balancer
  • Create a new load balancer in Terraform with the logging configuration

If you absolutely cannot recreate the load balancer, then find a way to stop Helm from managing it in the future.

Source: I have tried to have Kubernetes and Terraform share management responsibilities of resources, and it was a miserable failure. It's much better to have clear boundaries and only one system managing resources.

huangapple
  • 本文由 发表于 2023年2月24日 10:29:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75552120.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定