Closed Starefossen closed 4 years ago
Hi,
AFAIK there is no official API for contexts (I could not find anything related to context in https://circleci.com/docs/api/).
There is an ongoing feature request for such API here. Feel free to up vote it !
Thanks @tgermain π I'll give it my vote and try to get in touch with CircleCI! Why is thsi not a feature already?!
No idea, there are a lot of missing api. For instance you can trigger a single job using the api but not a workflow. We talked with them about it and they should release the API to do it soon.
Just to add some more bits, even on their web interface the app is using an unstable graphl api (https://circleci.com/graphql-unstable) to handle contextes. In theory we could use that in the meantime (as long its not againsts their ToS), but the authentication is cookie based so it will be a bit tricky to say the least to authenticate.
The circleci
official cli just added support for managing contexts - https://github.com/CircleCI-Public/circleci-cli/pull/362
could probably use some of that code to implement context management in this provider! yay
Interesting! Thanks for pointing out the official cli. I'm gonna experiment and see if I can replace the client we are using now with the official one!
@mrolla I'd be willing to chip in on this. I've been annoyed by the lack of an API for contexts for a long time and I'm betting enough other users feel similarly and would proceed with an unstable API.
Based on my experimentation, you must be an organization admin to interact with the context API, despite the UI adding support for non-administrative users editing contexts π.
The CircleCI CLI is using the "unstable" GraphQL API, so I suspect you'd want to add a second client and gradually move over, only removing the unofficial client for the REST API when the GraphQL API is complete/stable.
@bendrucker you are right. When I played with the official circleci client I was let down that it only supported the new graphql endpoint so I could not immediately use it to replace the rest one we are using. Introducing the official client for managing contexts I believe makes the most sense. If you got some spare time to work on the feature I'll gladly help reviewing.
Ok, sounds good! It's become a sore spot for me that we've developed strong Terraform coverage at work but CircleCI, which is a critical part of our pipeline, is managed all via copy-paste. We even have a circleci
workspace that creates the credentials Circle needs to deploy, it just can't set the values π. It has an output
with a key value map that we use for copying via terraform output
βits value is ready to go straight into for_each
.
I'll try to work on this a little today and should be able to get something out with complete acceptance tests next week. This would add:
circleci_context
circleci_context_environment_variable
Assuming all works out I'll also reach out to CircleCI (might have a connection) and see if they could share a bit about how they're planning to support their API. Haven't seen much if any response in public but I might be able to get more info via private outreach/as a paying customer π.
Opened https://github.com/mrolla/terraform-provider-circleci/pull/35, completely unexecuted but hey it compiles π
Should have time fairly soon to write some acceptance tests and fix whatever else might come up.
Wanted to get docs in place since there are some different config patterns worth documenting, including data sources for appending variables to a context without "managing" it via a resource:
data "circleci_context" "build" {
name = "build"
}
resource "circleci_context_environment_variable" "build_token" {
variable = "MY_API_TOKEN"
value = var.token
context_id = data.circleci_context.build.id
}
If anyone has time to work on standard Terraform provider styled docs for the provider and environment_variable
config that'd be helpful, otherwise I'll try to tackle it.
@bendrucker thanks for the amazing job!
Does there exists an API from CircleCI that will enable this provider to manage Contexts and environment variables in them as well?