awslabs / data-on-eks

DoEKS is a tool to build, deploy and scale Data & ML Platforms on Amazon EKS
https://awslabs.github.io/data-on-eks/
Apache License 2.0
634 stars 213 forks source link

[bug] Spark Operator stack fails to create if spark-operator-doeks-spark-irsa already exists #668

Open alanty opened 1 week ago

alanty commented 1 week ago

Description

When creating a duplicate Spark operator stack the creation fails with an error on the IAM policy for Spark:

│ Error: creating IAM Policy (spark-operator-doeks-spark-irsa): operation error IAM: CreatePolicy, https response error StatusCode: 409, ..., EntityAlreadyExists: A policy called spark-operator-doeks-spark-irsa already exists. Duplicate names are not allowed.
│
│   with aws_iam_policy.spark,
│   on spark-team.tf line 66, in resource "aws_iam_policy" "spark":
│   66: resource "aws_iam_policy" "spark" {
│

Versions

Steps to reproduce the behavior:

create two copies of the Spark operator (v4) stack in the same account (i was using a different region)

Expected behavior

we should use a unique name for that policy to avoid conflicts

alanty commented 1 week ago

i think it's this resource giving me a headache: https://github.com/awslabs/data-on-eks/blob/473189d7e7330fc428cabcf72935ad52f7974a2c/analytics/terraform/spark-k8s-operator/spark-team.tf#L66

We can probably use name_prefix instead of name to ensure uniqueness on the policy, even when someone uses the same name for the stack. https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy#argument-reference