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

Feat: support new vcs_connection resource #999

Merged
merged 3 commits into from
Jan 2, 2025

Conversation

TomerHeber
Copy link
Collaborator

Issue & Steps to Reproduce / Feature Request

resolves #994

Solution

Key Features:

  • CRUD operations for VCS connections
  • Import by ID or name
  • Support for GitHub Enterprise, GitLab Enterprise, and BitBucket Server
  • Validation for URL and VCS types
  • Test coverage for unit, acceptance, and integration was added.

min_lower = 8
}

# resource "env0_vcs_connection" "github" {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can't run this test because I'm unsure if an agent (or what) is configured.
I will require assistance with this specific test. I am open to suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

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

we discussed in slack, TF-provider-integration-tests org has no agents, so don't test it for now (similar to how we don't test other agent operations such as project agent-assignment)

@TomerHeber
Copy link
Collaborator Author

/review

@bot-env0 bot-env0 requested a review from a team December 27, 2024 14:12
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think this was a mistake... " copy..."

Copy link
Contributor

@sagydr sagydr Jan 2, 2025

Choose a reason for hiding this comment

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

Sorry I don't understand, what's the mistake?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the file shouldn't be there... it got into the repo by mistake...


type VcsConnectionUpdatePayload struct {
Name string `json:"name"`
VcsAgentKey string `json:"vcsAgentKey,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

during update I don't think VcsAgentKey can be empty...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so it's a PUT and not a PATCH?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, it's a PUT

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ack!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

discussed internally. This field can be empty (null or undefined).
Therefore, omitempty is needed.

"url": {
Type: schema.TypeString,
Required: true,
Description: "URL of the VCS server",
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be either "VCS URL" (github.com) OR "Repository URL" (github.com/env0/myrepo)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ok I will update the description.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

does it need to contain https:// as prefix?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, either http or https (like I saw you already validate)

Comment on lines +112 to +130
func getVcsConnectionByName(name string, meta interface{}) (*client.VcsConnection, error) {
apiClient := meta.(client.ApiClientInterface)

vcsConnections, err := apiClient.VcsConnections()
if err != nil {
return nil, err
}

var foundConnections []client.VcsConnection

for _, connection := range vcsConnections {
if connection.Name == name {
foundConnections = append(foundConnections, connection)
}
}

if len(foundConnections) == 0 {
return nil, fmt.Errorf("VCS connection with name %v not found", name)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to find Vcs-Connections by name? We don't have this in the BE

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you mean adding a search query? I don't think so. this for loop should suffice.
(or I misunderstood?).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm asking why do we need this entire function? Why do we need getVcsConnectionByName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh! oh!

for import operation by name.
(imports can be by ID or Name).

Comment on lines +57 to +59
func TestNewStringInValidator(t *testing.T) {
allowedValues := []string{"one", "two", "three"}
validator := NewStringInValidator(allowedValues)
Copy link
Contributor

Choose a reason for hiding this comment

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

what are you testing here? related to vcs-connections?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

just added more unit tests...
the VCS is using some of these validators... (but not all of them).

resource "env0_vcs_connection" "bitbucket_server" {
name = "bitbucket-server"
type = "BitBucketServer"
url = "https://bitbucket.example.com"
Copy link
Contributor

Choose a reason for hiding this comment

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

no vcs_agent_key on purpose? It may work with vcs_agent_key missing but better to be consistent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah - needs to be fixed.

Copy link
Collaborator Author

@TomerHeber TomerHeber Jan 2, 2025

Choose a reason for hiding this comment

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

so... follow-up question... do we want this field to be required ? right now it's optional in the API AFAIK.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest to keep it optional, like we describe in the API

func (client *ApiClient) VcsConnectionUpdate(id string, payload VcsConnectionUpdatePayload) (*VcsConnection, error) {
var result VcsConnection

if err := client.http.Put("/vcs/connections/"+id, payload, &result); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

you already use Put

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah - was just asking to be on the safe side...

Copy link
Contributor

@sagydr sagydr left a comment

Choose a reason for hiding this comment

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

Great!

@github-actions github-actions bot added ready to merge PR approved - can be merged once the PR owner is ready and removed pending final review labels Jan 2, 2025
@TomerHeber TomerHeber merged commit ffd28c4 into main Jan 2, 2025
4 of 5 checks passed
@TomerHeber TomerHeber deleted the feat-support-vcs-connection-#994 branch January 2, 2025 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support new "vcs_connection" resource
2 participants