Skip to content

Commit 67c6616

Browse files
feat: update so client to use api v3; add support for stack overflow enterprise; add tag and collection support (#11)
BREAKING CHANGE: stackoverflow_filter has been removed; provider configurations for default tags and team have been removed
1 parent 9e5ecf0 commit 67c6616

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+962
-1274
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
name: Run GoReleaser
4444
uses: goreleaser/goreleaser-action@f82d6c1c344bcacabba2c841718984797f664a6b # v4.2.0
4545
with:
46-
version: latest
46+
version: v1.18.2
4747
args: release --rm-dist
4848
env:
4949
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}

README.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,25 @@ To use a released version of the Terraform provider in your environment, run `te
1212

1313
```terraform
1414
provider "stackoverflow" {
15-
team_name = "my-team-name"
15+
base_url = "https://api.stackoverflowteams.com/v3/teams/{team}/"
1616
access_token = "xxxx"
17-
default_tags = ["terraform"]
18-
}
19-
20-
resource "stackoverflow_filter" "filter" {
2117
}
2218
2319
resource "stackoverflow_article" "article" {
2420
article_type = "announcement"
2521
title = "Terraform Provider for Stack Overflow is available!"
2622
body_markdown = "Look for the Stack Overflow provider in the Terraform registry"
2723
tags = ["example"]
28-
filter = stackoverflow_filter.filter.id
2924
}
3025
3126
resource "stackoverflow_question" "question" {
3227
title = "Stack Overflow Terraform Provider"
3328
body_markdown = "What is the Terraform Provider for Stack Overflow?"
3429
tags = ["example"]
35-
filter = stackoverflow_filter.filter.id
3630
}
3731
3832
resource "stackoverflow_answer" "answer" {
3933
question_id = stackoverflow_question.question.id
4034
body_markdown = "It is a Terraform plugin provider to manage resources in Stack Overflow for Teams"
41-
filter = stackoverflow_filter.filter.id
4235
}
4336
```

docs/data-sources/answer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ The `answer` data source allows for referencing an existing answer in Stack Over
1515
```
1616
data "stackoverflow_answer" "answer" {
1717
answer_id = 1
18-
filter = "XXXX"
1918
}
2019
```
2120

@@ -25,10 +24,11 @@ data "stackoverflow_answer" "answer" {
2524
### Required
2625

2726
- `answer_id` (Number) The identifier for the answer
28-
- `filter` (String) The API filter to use
27+
- `question_id` (Number) The identifier for the question
2928

3029
### Read-Only
3130

31+
- `body_markdown` (String) The answer content in Markdown format
3232
- `id` (String) The ID of this resource.
3333

3434

docs/data-sources/article.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ The `article` data source allows for referencing an existing article in Stack Ov
1313
```
1414
data "stackoverflow_article" "article" {
1515
article_id = 1
16-
filter = "XXXX"
1716
}
1817
```
1918

@@ -23,10 +22,13 @@ data "stackoverflow_article" "article" {
2322
### Required
2423

2524
- `article_id` (Number) The identifier for the article
26-
- `filter` (String) The API filter to use
2725

2826
### Read-Only
2927

28+
- `article_type` (String) The type of article. Must be one of `knowledge-article`, `announcement`, `how-to-guide`, `policy`
29+
- `body_markdown` (String) The article content in Markdown format
3030
- `id` (String) The ID of this resource.
31+
- `tags` (List of String) The set of tags to be associated with the article
32+
- `title` (String) The title of the article
3133

3234

docs/data-sources/collection.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackoverflow_collection Data Source - terraform-provider-stackoverflow"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# stackoverflow_collection (Data Source)
10+
11+
The `collection` data source allows for referencing an existing collection in Stack Overflow.
12+
13+
```
14+
data "stackoverflow_collection" "collection" {
15+
collection_id = 1
16+
}
17+
```
18+
19+
<!-- schema generated by tfplugindocs -->
20+
## Schema
21+
22+
### Required
23+
24+
- `collection_id` (Number) The identifier for the collection
25+
26+
### Read-Only
27+
28+
- `description` (String) The collection description
29+
- `title` (String) The collection name
30+
31+

docs/data-sources/filter.md

Lines changed: 0 additions & 37 deletions
This file was deleted.

docs/data-sources/question.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ The `question` data source allows for referencing an existing question in Stack
1414

1515
```
1616
data "stackoverflow_question" "question" {
17-
filter = "XXXX"
1817
question_id = 1
1918
}
2019
```
@@ -24,11 +23,13 @@ data "stackoverflow_question" "question" {
2423

2524
### Required
2625

27-
- `filter` (String) The API filter to use
2826
- `question_id` (Number) The identifier for the question
2927

3028
### Read-Only
3129

30+
- `body_markdown` (String) The question content in Markdown format
3231
- `id` (String) The ID of this resource.
32+
- `tags` (List of String) The set of tags to be associated with the article
33+
- `title` (String) The title of the article
3334

3435

docs/data-sources/tag.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
# generated by https://github.com/hashicorp/terraform-plugin-docs
3+
page_title: "stackoverflow_tag Data Source - terraform-provider-stackoverflow"
4+
subcategory: ""
5+
description: |-
6+
7+
---
8+
9+
# stackoverflow_tag (Data Source)
10+
11+
The `tag` data source allows for referencing an existing tag in Stack Overflow.
12+
13+
## Example
14+
15+
```
16+
data "stackoverflow_tag" "tag" {
17+
tag_id = 1
18+
}
19+
```
20+
21+
<!-- schema generated by tfplugindocs -->
22+
## Schema
23+
24+
### Required
25+
26+
- `tag_id` (Number) The identifier for the tag
27+
28+
### Read-Only
29+
30+
- `description` (String) The tag description
31+
- `id` (String) The ID of this resource.
32+
- `name` (String) The tag name
33+
34+

docs/index.md

Lines changed: 62 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,95 @@ description: |-
66
77
---
88

9-
# Stack Overflow Provider
9+
# stackoverflow Provider
1010

11-
Use the Stack Overflow provider to manage questions, answers, and articles for your Stack Overflow for Teams. You must configure the provider with the proper credentials before you can use it.
11+
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.
1212

1313
## Example Usage
1414

15-
This example demonstrates the usage of the provider by setting up the provider configuration and several different resource types. Note the usage of the filter resource which is required when managing all other resource types.
15+
This example demonstrates the usage of the provider by setting up the provider configuration and several different resource types.
1616

1717
```terraform
1818
provider "stackoverflow" {
19-
team_name = "my-team-name"
19+
base_url = "https://api.stackoverflowteams.com/v3/teams/{team}/"
2020
access_token = "xxxx"
21-
default_tags = ["terraform"]
2221
}
2322
24-
resource "stackoverflow_filter" "filter" {
23+
data "stackoverflow_tag" "tag" {
24+
tag_id = 1
2525
}
2626
2727
resource "stackoverflow_article" "article" {
2828
article_type = "announcement"
2929
title = "Terraform Provider for Stack Overflow is available!"
3030
body_markdown = "Look for the Stack Overflow provider in the Terraform registry"
31-
tags = ["example"]
32-
filter = stackoverflow_filter.filter.id
31+
tags = [data.stackoverflow_tag.tag.name]
3332
}
3433
3534
resource "stackoverflow_question" "question" {
3635
title = "Stack Overflow Terraform Provider"
3736
body_markdown = "What is the Terraform Provider for Stack Overflow?"
38-
tags = ["example"]
39-
filter = stackoverflow_filter.filter.id
37+
tags = [data.stackoverflow_tag.tag.name]
4038
}
4139
4240
resource "stackoverflow_answer" "answer" {
4341
question_id = stackoverflow_question.question.id
4442
body_markdown = "It is a Terraform plugin provider to manage resources in Stack Overflow for Teams"
45-
filter = stackoverflow_filter.filter.id
43+
}
44+
45+
resource "stackoverflow_collection" "collection" {
46+
title = "Collection Name"
47+
description = "Example collection"
48+
content_ids = [
49+
stackoverflow_article.article.id,
50+
stackoverflow_question.question.id
51+
]
4652
}
4753
```
4854

4955
<!-- schema generated by tfplugindocs -->
50-
## Argument Reference
51-
52-
| Name | Required | Type | Environment Variable | Default | Description |
53-
| ---- | -------- | ---- | -------------------- | ------- | ----------- |
54-
| `access_token` | Required | `string` | `STACK_OVERFLOW_ACCESS_TOKEN` | | The Stack Overflow API access token |
55-
| `team_name` | Required | `string` | `STACK_OVERFLOW_TEAM` | | The Stack Overflow team name |
56-
| `base_url` | Optional | `string` | `STACK_OVERFLOW_API_URL` | `https://api.stackoverflowteams.com/2.3/` | The base URL for the Stack Overflow API |
57-
| `default_tags` | Optional | `string[]` | | | A list of tags to automatically associate with any resources that support tags |
56+
## Schema
57+
58+
### Required
59+
60+
- `access_token` (String) The Stack Overflow API access token. The `STACK_OVERFLOW_ACCESS_TOKEN` environment variable can be used instead.
61+
- `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.
62+
63+
## Authentication and Configuration
64+
65+
The Stack Overflow Terraform provider uses the Stack Overflow API v3 for interaction which works with the Teams Business and Enterprise tiers only.
66+
67+
### Business
68+
69+
Stack Overflow for Teams Business tier users should create a personal access token (PAT) using the following documentation:
70+
71+
[https://stackoverflowteams.help/en/articles/7913768-stack-overflow-for-teams-api-v3](https://stackoverflowteams.help/en/articles/7913768-stack-overflow-for-teams-api-v3)
72+
73+
### Enterprise
74+
75+
Stack Overflow Enterprise users should reference the following documentation for creating API Applications/Service Keys:
76+
77+
[https://stackoverflowteams.help/en/articles/8043418-stack-overflow-for-teams-enterprise-api-v3](https://stackoverflowteams.help/en/articles/8043418-stack-overflow-for-teams-enterprise-api-v3).
78+
79+
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`)
80+
81+
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`.
82+
83+
> 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.
84+
85+
## Migrating from versions < 1.x
86+
87+
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.
88+
The following is a list of features that have been removed in version 1.x:
89+
90+
* `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.
91+
* `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.
92+
* `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.
93+
94+
The migration steps should be as follows:
95+
96+
1. Remove the `stackoverflow_filter` resource from code
97+
1. Remove the `stackoverflow_filter` resource from state by running the terraform state remove command (ex.: `terraform state rm stackoverflow_filter.filter`)
98+
1. Remove all usage of the `filter` field from resources
99+
1. 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)
100+
1. 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/`

docs/resources/answer.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,19 @@ Manages an answer and associates it to the related question.
1313
## Example
1414

1515
```
16+
data "stackoverflow_tag" "tag" {
17+
tag_id = 1
18+
}
19+
1620
resource "stackoverflow_question" "question" {
1721
title = "Stack Overflow Terraform Provider"
1822
body_markdown = "What is the Terraform Provider for Stack Overflow?"
19-
tags = ["example"]
20-
filter = "XXXX"
23+
tags = [data.stackoverflow_tag.tag.name]
2124
}
2225
2326
resource "stackoverflow_answer" "answer" {
2427
question_id = stackoverflow_question.question.id
2528
body_markdown = "It is a Terraform plugin provider to manage resources in Stack Overflow for Teams"
26-
filter = "XXXX"
2729
}
2830
```
2931

@@ -33,7 +35,6 @@ resource "stackoverflow_answer" "answer" {
3335
### Required
3436

3537
- `body_markdown` (String) The answer content in Markdown format
36-
- `filter` (String) The API filter to use
3738
- `question_id` (Number) The question identifier that this answer applies to
3839

3940
### Read-Only

0 commit comments

Comments
 (0)