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

feature: add project mirror resources to provider #358

Merged
merged 6 commits into from
Sep 7, 2020
Merged

feature: add project mirror resources to provider #358

merged 6 commits into from
Sep 7, 2020

Conversation

lukegriffith
Copy link
Contributor

@lukegriffith lukegriffith commented Jul 14, 2020

Implemented functionality for project mirrors, as per issue https://github.com/terraform-providers/terraform-provider-gitlab/issues/150

This was recently added to the go-gitlab library by myself and released in v0.33.0

xanzy/go-gitlab#879

@lukegriffith lukegriffith changed the title Mirror config feature: add project mirror resources to provider Jul 15, 2020
Copy link
Collaborator

@armsnyder armsnyder left a comment

Choose a reason for hiding this comment

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

General thing I noticed - you can use %d instead of %v for the mirror ID (int) throughout, in format strings.

Also, tests?

gitlab/resource_gitlab_project_mirror.go Outdated Show resolved Hide resolved
gitlab/resource_gitlab_project_mirror.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@armsnyder armsnyder left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Collaborator

@armsnyder armsnyder left a comment

Choose a reason for hiding this comment

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

sorry, just realized again - please add a test :)

@armsnyder
Copy link
Collaborator

Can you add a test for the importer as well? You can copy an _import test from another resource without much change.

@lukegriffith
Copy link
Contributor Author

Will do, late GMT so will do tomorrow. Thanks for reviewing and patience much appreciated.

@lukegriffith
Copy link
Contributor Author

Having issues adding the importer at the moment, and quite make sense of the error either. Still working on this, any input would be great - im not too familiar with the import tests, or the workflow it runs. Trying to pin down where the call to gitlab is being made.

@armsnyder
Copy link
Collaborator

armsnyder commented Aug 3, 2020

The importer test is fine. The problem occurs after the import, during the read. Your read function uses some attributes that are not set in your import function.

Check the docs for ImportStatePassthrough

https://www.terraform.io/docs/extend/resources/import.html#importer-state-function

Where possible, prefer using schema.ImportStatePassthrough as the Importer State function. This function requires the Read function to be able to refresh the entire resource with d.Id() ONLY. Sometimes it is possible to adjust the resource Read function to replace d.Get() use with d.Id() if they exactly match or add a function that parses the resource ID into the necessary attributes.

@jeremad
Copy link
Contributor

jeremad commented Aug 8, 2020

You can now rebase on master, go-gitlab has been updated

@lukegriffith
Copy link
Contributor Author

I've got the acceptance tests working, testing manually resource imports fine also.

@lukegriffith
Copy link
Contributor Author

rebased and caused a lot of mess. Resouce is working as expected. Do you require the commit history to be cleared up any further or is this good?

d.Set("enabled", projectMirror.Enabled)
d.Set("only_protected_branches", projectMirror.OnlyProtectedBranches)
d.Set("keep_divergent_refs", projectMirror.KeepDivergentRefs)
d.SetId(buildTwoPartID(projectID, &mirrorID))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nitpick, but this line is unnecessary since in all cases the ID will have already been set before calling this function.

@@ -0,0 +1,213 @@
package gitlab

// TODO convert to handle project mirror.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I can't tell what this means.

ResourceName: "gitlab_project_mirror.foo",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"enabled", "mirror_id", "project", "url"},
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why was this needed? The import should result in a fully synced state, ideally.

@armsnyder
Copy link
Collaborator

If you could squash this MR that could be good, because GitHub looks confused. Maybe it's just me but it's showing changes in the diff that aren't yours.

@lukegriffith
Copy link
Contributor Author

That occured once I performed git rebase master and it interlaced the more recent commits.
I will tidy this up from master and address the more recent comments.

Re: import test. Testing manually the resource is imported fine using the terraform cli, the import test does not show any fields. I've copied the test from other resources unsure why this is causing problems as the functionality works.

@lukegriffith
Copy link
Contributor Author

Import test success, I wasn't setting all properties

}
}

func testAccCheckGitlabProjectMirrorDestroy(s *terraform.State) error {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just an fyi, a "destroy" test should be testing the behavior of your own resource destroy function, i.e. checking that the mirror gets disabled. There's an open issue about this generally #205 so we can come back and do this later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will not make any changes in this PR for this.

@armsnyder
Copy link
Collaborator

Can you add a new documentation page for this new resource?

@lukegriffith
Copy link
Contributor Author

added docs page.

@armsnyder
Copy link
Collaborator

Looks good, but can you add the new doc page to the index (like so #391)

@lukegriffith
Copy link
Contributor Author

lukegriffith commented Aug 29, 2020

ack I actually searched for an index, didn't realise it was the erb file. should be done.

Copy link
Collaborator

@armsnyder armsnyder left a comment

Choose a reason for hiding this comment

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

Thanks!

@lukegriffith
Copy link
Contributor Author

@armsnyder is there anything I can do to speed this up getting merged? I have some work in the next week that i'd be keen to use this resource for... unsure on the release cadence or the process?

@armsnyder
Copy link
Collaborator

I don't have merging powers, but @nicholasklick may be able to give an update.

@lukegriffith
Copy link
Contributor Author

Hi @nicholasklick any timeframe on this getting merged?

@nicholasklick nicholasklick merged commit f60dc34 into gitlabhq:master Sep 7, 2020
@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.

4 participants