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

Implement the archived attribute on Project data source and resource #148

Merged
merged 4 commits into from
Jun 11, 2019

Conversation

dihedron
Copy link
Contributor

@dihedron dihedron commented Jun 6, 2019

Hallo, I'm proposing in this PR a few changes to enable the management of the archived attribute on both the gitlab_project resource and data source.
In doing so I had to implement partial state update in the project's update method, since the existing project properties update logic and the new archiving/unarchiving operation require different API calls, which may fail independently.
In the process I also noticed that the existing code to handle the shared_with_groups attribute in the gitlab_project resource method does not seem to handle errors which are swallowed altogether. Since this attribute, just like the archived attribute, requires its own different API call, I expected it to use partial state updates in order to avoid an inconsistent state in case of failure.
I updated the acceptance tests and the documentation for both resource and datasource.
Hope this helps!

@roidelapluie
Copy link
Collaborator

Hello,

SetPartial is great and could be used in create too ?

@dihedron
Copy link
Contributor Author

dihedron commented Jun 9, 2019

I'll check about that!

@dihedron
Copy link
Contributor Author

SetPartial is great and could be used in create too?

OK, as far as I understand, the resource is only committed to Terraform state once you set its ID in the schema.ResourceData, which happens quite (maybe too?) late in the resourceGitlabProjectCreate function.

Partial state management shoud still fit in but I feel it is more effective if we move this line:

d.SetId(fmt.Sprintf("%d", project.ID))

above the shared_with_groups update code, like this:

	// from this point onwards no matter how we return, resource creation 
	// is committed to state since we set its ID
	d.SetId(fmt.Sprintf("%d", project.ID))

	if v, ok := d.GetOk("shared_with_groups"); ok {
		for _, option := range expandSharedWithGroupsOptions(v) {
			if _, err := client.Projects.ShareProjectWithGroup(project.ID, option); err != nil {
				return err
			}
		}
		d.SetPartial("shared_with_groups")
	}

This is a change to code I didn't write and I'd like your advice on this before I submit it. Let me know.
Cheers!

@roidelapluie
Copy link
Collaborator

Fine for me!

@ghost ghost added size/L and removed size/M labels Jun 11, 2019
@dihedron
Copy link
Contributor Author

OK, it's in the PR.
While testing that shared_with_groups was unaffected by my changes, I noticed the docs reported the groups_access_level as optional whereas it's Required: true in the schema. I fixed the docs, it's in the same PR.
Cheers.

@roidelapluie roidelapluie merged commit a564280 into gitlabhq:master Jun 11, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Nov 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

Successfully merging this pull request may close these issues.

2 participants