Skip to content

Latest commit

 

History

History
101 lines (71 loc) · 6.15 KB

File metadata and controls

101 lines (71 loc) · 6.15 KB
page_title stackoverflow Provider
subcategory
description

stackoverflow Provider

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.

Example Usage

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
  ]
}

Schema

Required

  • access_token (String) The Stack Overflow API access token. The STACK_OVERFLOW_ACCESS_TOKEN environment 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 format https://api.stackoverflowteams.com/v3/teams/{team}/ and for Stack Overflow Enterprise this is in one of the following formats https://{name}.stackenterprise.co/api/v3/, https://{name}.stackenterprise.co/api/v3/teams/{team}/, https://{your-custom-domain}/api/v3/, or https://{your-custom-domain}/api/v3/teams/{team}/. The STACK_OVERFLOW_API_URL environment variable can be used instead.

Authentication and Configuration

The Stack Overflow Terraform provider uses the Stack Overflow API v3 for interaction which works with the Teams Business and Enterprise tiers only.

Business

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

Enterprise

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.

Migrating from versions < 1.x

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 the base_url field and include the team name if applicable in the value.

The migration steps should be as follows:

  1. Remove the stackoverflow_filter resource from code
  2. Remove the stackoverflow_filter resource from state by running the terraform state remove command (ex.: terraform state rm stackoverflow_filter.filter)
  3. Remove all usage of the filter field from resources
  4. Remove usage of the default_tags field 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)
  5. Remove usage of the team_name field from the provider. Users should set the base_url field or set the STACK_OVERFLOW_API_URL environment variable instead. For example, if the previous configuration only set the team_name field to the value myteam, the base_url field should now be set to https://api.stackoverflowteams.com/v3/teams/myteam/
  6. Update all stackoveflow_article article_type fields to one of the following: [knowledgeArticle, announcement, policy, howToGuide]