Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for data Source: azurerm_kubernetes_cluster without cluster user #21708

Closed
1 task done
damienpontifex opened this issue May 9, 2023 · 2 comments
Closed
1 task done

Comments

@damienpontifex
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Wanting to use the resource data "azurerm_kubernetes_cluster" to lookup ARM related properties without getting kube credentials.
Today, my service principal has Reader scope on the group with a kubernetes cluster in it, but gets

managedclusters.ManagedClustersClient#GetAccessProfile: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client '' with object id '' does not have authorization to perform action 'Microsoft.ContainerService/managedClusters/accessProfiles/listCredential/action' over scope '/subscriptions//resourceGroups//providers/Microsoft.ContainerService/managedClusters//accessProfiles/clusterUser' or the scope is invalid. If access was recently granted, please refresh your credentials."

If the account doesn't have cluster user permissions, but read permissions to the resource, it should still retrieve ARM properties without kube credentials to perform kubernetes based provider actions

New or Affected Resource(s)/Data Source(s)

azurerm_kubernetes_cluster (data source)

Potential Terraform Configuration

data "azurerm_kubernetes_cluster" "example" {
  name                = "myakscluster"
  resource_group_name = "my-example-resource-group"
  exclude_kube_log    = true  # default false to retain current behaviour
}

References

Location where cluster credentials are retrieved after the ARM lookup

id := managedclusters.NewManagedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string))
resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}
return fmt.Errorf("retrieving %s: %+v", id, err)
}
userCredentialsResp, err := client.ListClusterUserCredentials(ctx, id, managedclusters.ListClusterUserCredentialsOperationOptions{})
// only raise the error if it's not a limited permissions error, since this is the Data Source
if err != nil && !response.WasStatusCode(userCredentialsResp.HttpResponse, http.StatusForbidden) {
return fmt.Errorf("retrieving User Credentials for %s: %+v", id, err)
}

@damienpontifex
Copy link
Contributor Author

damienpontifex commented Jun 7, 2023

Actually, I believe is duplicate/resolved by #21229

Just had to update provider to > 3.51 to get that change

Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants