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

Adding new resource azuredevops_repository_policy_searchable_branches #1272

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

mdevreugd
Copy link

@mdevreugd mdevreugd commented Jan 7, 2025

All Submissions:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • My code follows the code style of this project.
  • I ran lint checks locally prior to submission.
  • Have you checked to ensure there aren't other open PRs for the same update/change?

What about the current behavior has changed?

This PR adds the resource azuredevops_repository_policy_searchable_branches which have been missing so far.
This will help improve the overall automation capabilities around ADO.

Issue Number: #891

Does this introduce a change to go.mod, go.sum or vendor/?

  • Yes
  • No

Does this introduce a breaking change?

  • Yes
  • No

Any relevant logs, error output, etc?

(If it’s long, please paste to https://ghostbin.com/ and insert the link here.)

Other information

@microsoft-github-policy-service agree

@mdevreugd
Copy link
Author

@microsoft-github-policy-service agree

@xuzhang3 xuzhang3 self-assigned this Jan 8, 2025
Copy link
Collaborator

@xuzhang3 xuzhang3 left a comment

Choose a reason for hiding this comment

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

@mdevreugd took a quick look. A few changes required.
Also I found that the default searchable branches may exists and TF script is only part of them, these configurations needs to be handled carefully.
Another issue is the dev and refs/heads/dev have different meanings but in portal they all show up as dev

refs/heads/dev

"github.com/microsoft/azure-devops-go-api/azuredevops/v7/policy"
)

type searchbranchesPolicySettings struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code can be removed


maps.Copy(resource.Schema, map[string]*schema.Schema{
"searchable_branches": {
Type: schema.TypeList,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be TypeSet instead of TypeList to avoid potential ordering issues

Comment on lines +32 to +50
"enabled": {
Type: schema.TypeBool,
Computed: true,
},
"blocking": {
Type: schema.TypeBool,
Computed: true,
},
// API only accepts a single repository as scope.
"repository_ids": {
Type: schema.TypeList,
Required: true,
MinItems: 1,
MaxItems: 1,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsUUID,
},
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

These properties are handled in the infrastructure and we can remove them

Copy link
Author

Choose a reason for hiding this comment

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

That's true. The reason why I've added these is to override them, however.

The thing with the Searchable Branches policy is that the API still expects these to be passed, but setting the enabled or blocking to true causes an error.

And you can only scope this for 1 repository, plus I did not want to mess too much with the schema. Hence forcing the repository_ids to accept only 1.

})

maps.Copy(resource.Schema, map[string]*schema.Schema{
"searchable_branches": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"searchable_branches": {
"branches": {

return resource
}

func searchableBranchesFlattenFunc(d *schema.ResourceData, policyConfig *policy.PolicyConfiguration, projectID *string) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func searchableBranchesFlattenFunc(d *schema.ResourceData, policyConfig *policy.PolicyConfiguration, projectID *string) error {
func flattenSearchableBranches(d *schema.ResourceData, policyConfig *policy.PolicyConfiguration, projectID *string) error {

return nil
}

func searchableBranchesExpandFunc(d *schema.ResourceData, typeID uuid.UUID) (*policy.PolicyConfiguration, *string, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
func searchableBranchesExpandFunc(d *schema.ResourceData, typeID uuid.UUID) (*policy.PolicyConfiguration, *string, error) {
func expandSearchableBranches(d *schema.ResourceData, typeID uuid.UUID) (*policy.PolicyConfiguration, *string, error) {

Computed: true,
},
// API only accepts a single repository as scope.
"repository_ids": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is legacy technical debt. Instead of using a generic scheme, you can add entire schemes as needed and handle create/update/read/delete yourself. Based on the information you shared, it is recommended to do this

Copy link
Author

@mdevreugd mdevreugd Jan 9, 2025

Choose a reason for hiding this comment

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

Ah, I just read this comment in order. :)

So you're suggesting to not use the generic schema provided by common.

Let me look into it 👍

## Relevant Links

- [Azure DevOps Service REST API 7.0 - Policy Configurations](https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/configurations?view=azure-devops-rest-7.0)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
## Timeouts
The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:
* `create` - (Defaults to 30 minutes) Used when creating the Searchable Branches Repository Policy.
* `read` - (Defaults to 5 minute) Used when retrieving the Searchable Branches Repository Policy.
* `update` - (Defaults to 30 minutes) Used when updating the Searchable Branches Repository Policy.
* `delete` - (Defaults to 30 minutes) Used when deleting the Searchable Branches Repository Policy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants