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

GitOps Resources Don't Work..... #260

Closed
steve-gray opened this issue Oct 23, 2022 · 4 comments
Closed

GitOps Resources Don't Work..... #260

steve-gray opened this issue Oct 23, 2022 · 4 comments

Comments

@steve-gray
Copy link

steve-gray commented Oct 23, 2022

I'm unable to get any of the harness_gitops_ prefixed resources to work. It appears either the underlying Go SDK API's don't permit the use of PAT/SAT keys and require a bearer token, or that the keys aren't being passed around internally.

I've tried a few options here in different directions, but ultimately we just want to have a terraform script create some Harness resources and trigger them. It seems this is potentially a trick too much though for the current state of play?

@steve-gray
Copy link
Author

steve-gray commented Oct 23, 2022

Yeah, I've confirmed this with the Go SDK locally. If I manually force in the x-api-key header with my PAT value from the Harness UI, I get a working request - but I'm also able to use the context WithValue auth - which seems to be what this module is doing - at least for some requests/resources.

That said, it still doesn't work in TF with:

provider "harness" {
  endpoint          = "https://app.harness.io/gateway"
  account_id        = "<my-account>"
    platform_api_key  = "pat.<snip>"
}

However, I'm able to hit these resources with:

// Set these to reflect your account details.
const (
	accountId = "<my-account>"
	endpoint  = "https://app.harness.io/gateway"
	apiKey    = "pat.<snip>"
	orgId     = "<my-org>"
	project   = "<my project>"
)

func main() {
	ctx := context.Background()

	ctx = context.WithValue(ctx, nextgen.ContextAPIKey, nextgen.APIKey{
		Key: apiKey,
	})
	client := nextgen.NewAPIClient(&nextgen.Configuration{
		AccountId:    accountId,
		ApiKey:       apiKey,
		BasePath:     endpoint,
		DebugLogging: true,
		HTTPClient:   retryablehttp.NewClient(),
	})

	res, _, errEnv := client.EnvironmentsApi.GetEnvironmentList(ctx, accountId, &nextgen.EnvironmentsApiGetEnvironmentListOpts{
		OrgIdentifier:     optional.NewString(orgId),
		ProjectIdentifier: optional.NewString(project),
	})
	fmt.Println(errEnv)
	fmt.Println(res.Data.Content[0].Environment.Identifier)

	res2, _, err := client.ClustersApi.GetClusterList(ctx, accountId, "integration", &nextgen.ClustersApiGetClusterListOpts{
		OrgIdentifier:     optional.NewString(orgId),
		ProjectIdentifier: optional.NewString(project),
	})
	fmt.Println(err)
	fmt.Println(res2)
}

I'm able to get agents, list clusters etc - I just can't use this terraform module to do it.

I'm working through a fork of the package locally to figure why this isn't' working though. Initially I thought maybe the platform_api_key wasn't being passed correctly to the Go SDK for GitOps operations. However something else seems to be going wrong internally.

@manavjot-harness
Copy link
Contributor

Hi @steve-gray , this has been fixed. Now GitOps resources support the pat token.

@steve-gray
Copy link
Author

I can confirm this is working, and was able to deploy a Gitops agent.

@manavjot-harness - is there a resource to configure the association between an agent and environment anywhere?

@manavjot-harness
Copy link
Contributor

@steve-gray No we don't have a resource for the association for agent and environment. But you can configure environments to use certain clusters from an agent.

Can you please elaborate on the use case?

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

No branches or pull requests

2 participants