-
Notifications
You must be signed in to change notification settings - Fork 280
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
New Resource azuredevops_service_principal_entitlement
#1028
base: main
Are you sure you want to change the base?
New Resource azuredevops_service_principal_entitlement
#1028
Conversation
Remove unused list of keys
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nyanph can you add the AccTest for the new resources?
## Argument Reference | ||
|
||
- `origin_id` - (Required) The object ID of the enterprise application. | ||
- `origin` - (Optional) The type of source provider for the origin identifier. Defaults to `aad`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any other possible values besides the default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure. The docs say AAD, AD, MSA, but I'm not sure if that list is exhaustive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can add AD
, AAD
, MSA
to the doc
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
|
||
func flattenServicePrincipalEntitlement(d *schema.ResourceData, servicePrincipalEntitlement *memberentitlementmanagement.ServicePrincipalEntitlement) { | ||
d.SetId(servicePrincipalEntitlement.Id.String()) | ||
d.Set("descriptor", *servicePrincipalEntitlement.ServicePrincipal.Descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check the servicePrincipalEntitlement.ServicePrincipal.Descriptor
and servicePrincipalEntitlement.ServicePrincipal
first before get the values to prevent potential nil exception
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand the request. The check is done in l126, before the function is called. I can repeat the same check within the function and throw an error if that is the correct way to do it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service may not return the property due to permission. Therefore, you need to check this property before calling it with a pointer.
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
azuredevops_service_principal_entitlement
Co-authored-by: xuzhang3 <[email protected]>
Co-authored-by: xuzhang3 <[email protected]>
Co-authored-by: xuzhang3 <[email protected]>
Co-authored-by: xuzhang3 <[email protected]>
…rce_service_principal_entitlement.go Co-authored-by: xuzhang3 <[email protected]>
…rce_service_principal_entitlement.go Co-authored-by: xuzhang3 <[email protected]>
…rce_service_principal_entitlement.go Co-authored-by: xuzhang3 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some AccTest to cover the usage scenarios?
Refs:
https://developer.hashicorp.com/terraform/plugin/sdkv2/testing/acceptance-tests
https://github.com/microsoft/terraform-provider-azuredevops/blob/main/azuredevops/internal/acceptancetests/resource_group_entitlement_test.go
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
|
||
func flattenServicePrincipalEntitlement(d *schema.ResourceData, servicePrincipalEntitlement *memberentitlementmanagement.ServicePrincipalEntitlement) { | ||
d.SetId(servicePrincipalEntitlement.Id.String()) | ||
d.Set("descriptor", *servicePrincipalEntitlement.ServicePrincipal.Descriptor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Service may not return the property due to permission. Therefore, you need to check this property before calling it with a pointer.
...evops/internal/service/memberentitlementmanagement/resource_service_principal_entitlement.go
Outdated
Show resolved
Hide resolved
I am not that good with Go to be honest, so I'm afraid I can't do that properly. |
Co-authored-by: xuzhang3 <[email protected]>
Any update on this? |
This is a very valuable pull request |
@smokedlinq @nyanhp Service principal Entitlement is a little bit special. SPN requires to be real resource and user/PAT should have permission to access Azure resource. We can using an existed SPN to test AccTest Example: func TestAccServicePrincipalEntitlement_basic(t *testing.T) {
if os.Getenv("ARM_SPN_OBJECT_ID") == "" {
t.Skip("ARM_SPN_OBJECT_ID needs to be set for testing")
}
tfNode := "azuredevops_service_principal_entitlement.test"
originId := os.Getenv("ARM_SPN_OBJECT_ID") // enterprise app object ID
resource.ParallelTest(t, resource.TestCase{
Providers: testutils.GetProviders(),
CheckDestroy: checkServicePrincipalEntitlementDestroyed,
Steps: []resource.TestStep{
{
Config: hclServiceServicePrincipalEntitlementBasic(originId),
Check: resource.ComposeTestCheckFunc(
checkServicePrincipalEntitlementExists(originId),
resource.TestCheckResourceAttrSet(tfNode, "descriptor"),
),
},
},
})
}
func checkServicePrincipalEntitlementExists(expectedDisplayName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
resource, ok := s.RootModule().Resources["azuredevops_service_principal_entitlement.test"]
if !ok {
return fmt.Errorf(" Did not find a servicePrincipalEntitlement in the TF state")
}
clients := testutils.GetProvider().Meta().(*client.AggregatedClient)
id, err := uuid.Parse(resource.Primary.ID)
if err != nil {
return fmt.Errorf(" { Parsing servicePrincipalEntitlement ID, got %s: %v", resource.Primary.ID, err)
}
servicePrincipalEntitlement, err := clients.MemberEntitleManagementClient.GetServicePrincipalEntitlement(clients.Ctx, memberentitlementmanagement.GetServicePrincipalEntitlementArgs{
ServicePrincipalId: &id,
})
if err != nil {
return fmt.Errorf("servicePrincipalEntitlement with ID=%s cannot be found!. Error=%v", id, err)
}
if !strings.EqualFold(strings.ToLower(*servicePrincipalEntitlement.ServicePrincipal.OriginId), strings.ToLower(expectedDisplayName)) {
return fmt.Errorf("sssssssss ")
}
return nil
}
}
func checkServicePrincipalEntitlementDestroyed(s *terraform.State) error {
clients := testutils.GetProvider().Meta().(*client.AggregatedClient)
for _, resource := range s.RootModule().Resources {
if resource.Type != "azuredevops_service_principal_entitlement" {
continue
}
id, err := uuid.Parse(resource.Primary.ID)
if err != nil {
return fmt.Errorf(" Parsing servicePrincipalEntitlement ID, got %s: %v", resource.Primary.ID, err)
}
servicePrincipalEntitlement, err := clients.MemberEntitleManagementClient.GetServicePrincipalEntitlement(clients.Ctx, memberentitlementmanagement.GetServicePrincipalEntitlementArgs{
ServicePrincipalId: &id,
})
if err != nil {
if utils.ResponseWasNotFound(err) {
return nil
}
return fmt.Errorf(" Get servicePrincipalEntitlement : %+v", err)
}
if servicePrincipalEntitlement != nil && servicePrincipalEntitlement.ServicePrincipal != nil {
return fmt.Errorf(" Service Principal Entitlement with ID: %s should not exist", id.String())
}
}
return nil
}
func hclServiceServicePrincipalEntitlementBasic(originID string) string {
return fmt.Sprintf(`
resource "azuredevops_service_principal_entitlement" "test" {
origin_id = "%s"
}
`, originID)
} |
Any updates? |
Any update on this? This is a very valuable pull request. |
I am also waiting for this. |
Same here guys! |
@nyanhp can I fork your branch since you do not time to update this PR ? |
Sure, the fork is public. I have plenty of time, but I am not going to become professional enough with Go, a language I rarely use, just to write integration tests for a one-time PR |
All Submissions:
What about the current behavior has changed?
Added new resource azuredevops_service_principal_entitlement to handle service principal entitlements. The API threw errors when attempting to use a principal name to add the principal, so I only implemented the use of origin and origin_id.
Issue Number: #1025 #797 #889
Does this introduce a change to
go.mod
,go.sum
orvendor/
?Does this introduce a breaking change?
Any relevant logs, error output, etc?
Other information