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

Add support for group_membership_filter in azuread #1458

Merged
merged 1 commit into from
Jan 21, 2025
Merged
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
16 changes: 5 additions & 11 deletions rancher2/00_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
testAccRancher2AdminPass = testAccRancher2DefaultAdminPass
err := testAccCheck()
if err != nil {
log.Fatalf("%v", err)
log.Fatalf("failed check %s", err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdyt of using %w instead o %s?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops, sorry, my mistake

}
}

Expand Down Expand Up @@ -64,14 +64,8 @@ func testAccCheck() error {
secretKey := os.Getenv("RANCHER_SECRET_KEY")
caCerts := os.Getenv("RANCHER_CA_CERTS")
adminPass := os.Getenv("RANCHER_ADMIN_PASS")
insecure := false
if os.Getenv("RANCHER_INSECURE") == "true" {
insecure = true
}
bootstrap := false
if os.Getenv("RANCHER_BOOTSTRAP") == "true" {
bootstrap = true
}
insecure := os.Getenv("RANCHER_INSECURE") == "true"
bootstrap := os.Getenv("RANCHER_BOOTSTRAP") == "true"

if apiURL == "" {
return fmt.Errorf("RANCHER_URL must be set for acceptance tests")
Expand All @@ -96,12 +90,12 @@ func testAccCheck() error {
if len(tokenKey) > 5 {
err := testAccClusterDefaultName(testAccProviderConfig)
if err != nil {
return err
return fmt.Errorf("failed to test the default cluster name: %w", err)
}

testAccRancher2ClusterRKEK8SDefaultVersion, err = testAccProviderConfig.getK8SDefaultVersion()
if err != nil {
return err
return fmt.Errorf("failed get the default k8s version: %w", err)
}
}
}
Expand Down
21 changes: 21 additions & 0 deletions rancher2/resource_rancher2_auth_config_azuread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,19 @@ resource "` + testAccRancher2AuthConfigAzureADType + `" "azuread" {
rancher_url = "https://RANCHER-UPDATED"
tenant_id = "YYYYYYYY"
token_endpoint = "token"
}
`

testAccRancher2AuthConfigAzureADConfigWithUserGroupFilter = `
resource "` + testAccRancher2AuthConfigAzureADType + `" "azuread" {
application_id = "XXXXXX"
application_secret = "YYYYYYYY"
auth_endpoint = "authorize-updated"
graph_endpoint = "graph"
rancher_url = "https://RANCHER-UPDATED"
tenant_id = "ZZZZZZZZ"
token_endpoint = "token"
group_membership_filter = "startswith(displayName, 'test')"
}
`
)
Expand Down Expand Up @@ -76,6 +89,14 @@ func TestAccRancher2AuthConfigAzureAD_basic(t *testing.T) {
resource.TestCheckResourceAttr(testAccRancher2AuthConfigAzureADType+"."+AuthConfigAzureADName, "tenant_id", "XXXXXXXX"),
),
},
{
Config: testAccRancher2AuthConfigAzureADConfigWithUserGroupFilter,
Check: resource.ComposeTestCheckFunc(
testAccCheckRancher2AuthConfigExists(testAccRancher2AuthConfigAzureADType+"."+AuthConfigAzureADName, authConfig),
resource.TestCheckResourceAttr(testAccRancher2AuthConfigAzureADType+"."+AuthConfigAzureADName, "tenant_id", "ZZZZZZZZ"),
resource.TestCheckResourceAttr(testAccRancher2AuthConfigAzureADType+"."+AuthConfigAzureADName, "group_membership_filter", "startswith(displayName, 'test')"),
),
},
},
})
}
Expand Down
4 changes: 4 additions & 0 deletions rancher2/schema_auth_config_azuread.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ func authConfigAzureADFields() map[string]*schema.Schema {
Type: schema.TypeString,
Required: true,
},
"group_membership_filter": {
Type: schema.TypeString,
Optional: true,
},
}

for k, v := range authConfigFields() {
Expand Down
5 changes: 5 additions & 0 deletions rancher2/structure_auth_config_azuread.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func flattenAuthConfigAzureAD(d *schema.ResourceData, in *managementClient.Azure
d.Set("rancher_url", in.RancherURL)
d.Set("tenant_id", in.TenantID)
d.Set("token_endpoint", in.TokenEndpoint)
d.Set("group_membership_filter", in.GroupMembershipFilter)

return nil
}
Expand Down Expand Up @@ -109,5 +110,9 @@ func expandAuthConfigAzureAD(in *schema.ResourceData) (*managementClient.AzureAD
obj.TokenEndpoint = v
}

if v, ok := in.Get("group_membership_filter").(string); ok {
obj.GroupMembershipFilter = v
}

return obj, nil
}
52 changes: 26 additions & 26 deletions rancher2/structure_auth_config_azuread_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,38 @@ var (

func init() {
testAuthConfigAzureADConf = &managementClient.AzureADConfig{
Name: AuthConfigAzureADName,
Type: managementClient.AzureADConfigType,
AccessMode: "access",
AllowedPrincipalIDs: []string{"allowed1", "allowed2"},
Enabled: true,
ApplicationID: "application_id",
AuthEndpoint: "auth_endpoint",
Endpoint: "endpoint",
GraphEndpoint: "graph_endpoint",
RancherURL: "rancher_url",
TenantID: "tenant_id",
TokenEndpoint: "token_endpoint",
Name: AuthConfigAzureADName,
Type: managementClient.AzureADConfigType,
AccessMode: "access",
AllowedPrincipalIDs: []string{"allowed1", "allowed2"},
Enabled: true,
ApplicationID: "application_id",
AuthEndpoint: "auth_endpoint",
Endpoint: "endpoint",
GraphEndpoint: "graph_endpoint",
RancherURL: "rancher_url",
TenantID: "tenant_id",
TokenEndpoint: "token_endpoint",
GroupMembershipFilter: "startswith(displayName,'test')",
}
testAuthConfigAzureADInterface = map[string]interface{}{
"name": AuthConfigAzureADName,
"type": managementClient.AzureADConfigType,
"access_mode": "access",
"allowed_principal_ids": []interface{}{"allowed1", "allowed2"},
"enabled": true,
"application_id": "application_id",
"auth_endpoint": "auth_endpoint",
"endpoint": "endpoint",
"graph_endpoint": "graph_endpoint",
"rancher_url": "rancher_url",
"tenant_id": "tenant_id",
"token_endpoint": "token_endpoint",
"name": AuthConfigAzureADName,
"type": managementClient.AzureADConfigType,
"access_mode": "access",
"allowed_principal_ids": []interface{}{"allowed1", "allowed2"},
"enabled": true,
"application_id": "application_id",
"auth_endpoint": "auth_endpoint",
"endpoint": "endpoint",
"graph_endpoint": "graph_endpoint",
"rancher_url": "rancher_url",
"tenant_id": "tenant_id",
"token_endpoint": "token_endpoint",
"group_membership_filter": "startswith(displayName,'test')",
}
}

func TestFlattenAuthConfigAzureAD(t *testing.T) {

cases := []struct {
Input *managementClient.AzureADConfig
ExpectedOutput map[string]interface{}
Expand Down Expand Up @@ -75,7 +76,6 @@ func TestFlattenAuthConfigAzureAD(t *testing.T) {
}

func TestExpandAuthConfigAzureAD(t *testing.T) {

cases := []struct {
Input map[string]interface{}
ExpectedOutput *managementClient.AzureADConfig
Expand Down
Loading