Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions rafay/resource_eks_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,11 @@ func podIdentityAssociationsFields() map[string]*schema.Schema {
Type: schema.TypeBool,
Optional: true,
Description: "enable flag to create service account",
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
// During CREATE the resource is still "new" → allow the diff.
// Afterwards, suppress any attempted change so TF doesn't even
// try to plan it; the Update code will throw a hard error.
return !d.IsNewResource()
},
"role_name": {
Type: schema.TypeString,
Expand Down
23 changes: 23 additions & 0 deletions rafay/resource_eks_pod_identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ func resourceEksPodIdentityUpdate(ctx context.Context, d *schema.ResourceData, m
return diag.FromErr(fmt.Errorf("spec not specified"))
}

if d.HasChange("spec") {
oldRaw, newRaw := d.GetChange("spec")

oldFlag := extractCreateServiceAccount(oldRaw)
newFlag := extractCreateServiceAccount(newRaw)

if oldFlag != newFlag {
return diag.Errorf(
"create_service_account is immutable. ")
}
}

if len(podIdentity) == 0 {
return diag.FromErr(errors.New("could not get pod identity associations"))
}
Expand Down Expand Up @@ -421,6 +433,17 @@ func resourceEksPodIdentityDelete(ctx context.Context, d *schema.ResourceData, m
return diags
}

func extractCreateServiceAccount(raw interface{}) bool {
if l, ok := raw.([]interface{}); ok && len(l) > 0 && l[0] != nil {
if m, ok := l[0].(map[string]interface{}); ok {
if v, ok := m["create_service_account"].(bool); ok {
return v
}
}
}
return false
}

func getIdFromName(clusterName string, projectName string) (string, string, error) {
resp, err := project.GetProjectByName(projectName)
if err != nil {
Expand Down