| page_title | stackoverflow Provider |
|---|---|
| subcategory | |
| description |
Use the Stack Overflow provider to manage questions, answers, articles, and collections for your Stack Overflow for Teams instance. You must configure the provider with the proper credentials before you can use it.
This example demonstrates the usage of the provider by setting up the provider configuration and several different resource types.
provider "stackoverflow" {
base_url = "https://api.stackoverflowteams.com/v3/teams/{team}/"
access_token = "xxxx"
}
data "stackoverflow_tag" "tag" {
tag_id = 1
}
resource "stackoverflow_article" "article" {
article_type = "announcement"
title = "Terraform Provider for Stack Overflow is available!"
body_markdown = "Look for the Stack Overflow provider in the Terraform registry"
tags = [data.stackoverflow_tag.tag.name]
}
resource "stackoverflow_question" "question" {
title = "Stack Overflow Terraform Provider"
body_markdown = "What is the Terraform Provider for Stack Overflow?"
tags = [data.stackoverflow_tag.tag.name]
}
resource "stackoverflow_answer" "answer" {
question_id = stackoverflow_question.question.id
body_markdown = "It is a Terraform plugin provider to manage resources in Stack Overflow for Teams"
}
resource "stackoverflow_collection" "collection" {
title = "Collection Name"
description = "Example collection"
content_ids = [
stackoverflow_article.article.id,
stackoverflow_question.question.id
]
}access_token(String) The Stack Overflow API access token. TheSTACK_OVERFLOW_ACCESS_TOKENenvironment variable can be used instead.base_url(String) The base URL for the Stack Overflow API (must end with/). For Stack Overflow for Teams this is in the formathttps://api.stackoverflowteams.com/v3/teams/{team}/and for Stack Overflow Enterprise this is in one of the following formatshttps://{name}.stackenterprise.co/api/v3/,https://{name}.stackenterprise.co/api/v3/teams/{team}/,https://{your-custom-domain}/api/v3/, orhttps://{your-custom-domain}/api/v3/teams/{team}/. TheSTACK_OVERFLOW_API_URLenvironment variable can be used instead.
The Stack Overflow Terraform provider uses the Stack Overflow API v3 for interaction which works with the Teams Business and Enterprise tiers only.
Stack Overflow for Teams Business tier users should create a personal access token (PAT) using the following documentation:
https://stackoverflowteams.help/en/articles/7913768-stack-overflow-for-teams-api-v3
Stack Overflow Enterprise users should reference the following documentation for creating API Applications/Service Keys:
https://stackoverflowteams.help/en/articles/8043418-stack-overflow-for-teams-enterprise-api-v3.
API applications can be generated for users or administrators can create "service applications/keys" that are associated with the Community user which may be more appropriate in some cases. When creating an API application, set the Domain to your instance's url (ex: {name}.stackenterprise.co)
Once the API application has been registered, users should reference their site's documentation at https://[your_site]/api/docs/authentication for details on create an access key. Users should follow the instructions for "Desktop Applications" that uses the implicit OAuth 2.0 flow to generate an access_token.
Note: The user that creates the access token will be the user referenced when creating articles, questions, and answers even if the API application is registered to the Community user. You may wish to use another non-user account to differentiate content generated by Terraform.
Versions prior to 1.x are not considered stable and many changes have been made that will require manual interview to ensure that your upgrade is successful. The following is a list of features that have been removed in version 1.x:
stackoverflow_filter- This data/resource is no longer available in versions > 1.x because it is no longer needed. This resource was a direct requirement to using Stack Overflow's API v2.x and had no particular meaning besides configuring API access.default_tags- Provider default tags are no longer supported. This decision was made to simplify the code base, standardize the Terraform model state to make it reflect actual configuration code, and to promote tags as first class resources. Tags are now available as data resources and can be used to ensure the resource dependency graph is more complete.team_name- Provider team name field is no longer supported which simplifies the provider configuration to be able to support both Stack Overflow for Teams Business and Stack Overflow Enterprise tiers. Users should provide thebase_urlfield and include the team name if applicable in the value.
The migration steps should be as follows:
- Remove the
stackoverflow_filterresource from code - Remove the
stackoverflow_filterresource from state by running the terraform state remove command (ex.:terraform state rm stackoverflow_filter.filter) - Remove all usage of the
filterfield from resources - Remove usage of the
default_tagsfield from the provider (users may opt to use a local variable with default tags and then subsequently merge that list with each resource's tag values) - Remove usage of the
team_namefield from the provider. Users should set thebase_urlfield or set theSTACK_OVERFLOW_API_URLenvironment variable instead. For example, if the previous configuration only set theteam_namefield to the valuemyteam, thebase_urlfield should now be set tohttps://api.stackoverflowteams.com/v3/teams/myteam/ - Update all
stackoveflow_articlearticle_typefields to one of the following: [knowledgeArticle,announcement,policy,howToGuide]