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

New resource azuredevops_feed azuredevops_feed_permission Data source azuredevops_feed Basic Feed Management #1011

Merged
merged 39 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
529c528
add feed client
Mar 25, 2024
4dfbf61
Feed resource definition
Mar 25, 2024
173e9d5
fix Feed resource definition to buildable state
Mar 25, 2024
f152d53
add data for Feed
Mar 25, 2024
1069541
add tests for feed resource
Mar 25, 2024
b6012f2
add acceptence tests for Feed DataSource
Mar 25, 2024
bdff4b7
fix acc for Feed DataSource
Mar 25, 2024
e65ea8c
cover acc tests for Feed Resource
Mar 25, 2024
cb7a3d9
fix tests
Mar 26, 2024
9908558
change logic of resource delete to perma delete the feed
Mar 26, 2024
abac20b
update structure to be based on project_id, update data to take both …
Mar 26, 2024
0af6837
add documentation for the Feed Resource and DataSource
Mar 26, 2024
8322042
fix import for data_feed.go
Mar 26, 2024
b383d17
Update website/docs/d/feed.html.markdown
SetsudanHana Apr 9, 2024
62661bb
Update website/docs/d/feed.html.markdown
SetsudanHana Apr 9, 2024
f15e316
Update website/docs/r/feed.html.markdown
SetsudanHana Apr 9, 2024
0fa8e40
Update website/docs/r/feed.html.markdown
SetsudanHana Apr 9, 2024
57e87f1
Update website/docs/r/feed.html.markdown
SetsudanHana Apr 9, 2024
2279cc8
Update azuredevops/internal/service/feed/resource_feed.go
SetsudanHana Apr 9, 2024
037814c
ForceNew if projectId changes
Apr 9, 2024
8b6b3e4
update logic got passing down resource data
Apr 9, 2024
56ca63a
replace emptiness check with atLeastOneOf
Apr 9, 2024
d10ca99
replace String validation with dedicated UUID one
Apr 9, 2024
e7a5a2e
remove setting up Id within the update
Apr 9, 2024
e4548a0
apply PR suggestion
Apr 9, 2024
c528b7f
Update azuredevops/internal/service/feed/resource_feed.go
SetsudanHana Apr 9, 2024
b8c1541
Update azuredevops/internal/service/feed/resource_feed.go
SetsudanHana Apr 9, 2024
6903322
Update azuredevops/internal/service/feed/resource_feed.go
SetsudanHana Apr 9, 2024
f9530eb
implement soft delete option for feed
Apr 11, 2024
e12d226
update documentation
Apr 11, 2024
9a2849d
introduce `restored` computed value determining if Feed was created o…
Apr 11, 2024
2069408
add resource definition for feed permission
Apr 12, 2024
394dd5c
register new resource to the provider
Apr 12, 2024
73afa37
add acceptance tests, fix implementation translating new descriptor i…
Apr 12, 2024
01406f7
add documentation for feed_permission assignment
Apr 12, 2024
b748367
add comment regarding limitations of feed recreation
Apr 16, 2024
aafbed2
address PR comments
Apr 18, 2024
e50b723
introduce feature block, move permanent_delete parameter to feature b…
May 7, 2024
8b9f8a7
address PR comments
May 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
573 changes: 573 additions & 0 deletions azdosdkmocks/feed_sdk_mock.go

Large diffs are not rendered by default.

71 changes: 71 additions & 0 deletions azuredevops/internal/acceptancetests/data_feed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//go:build (all || core || data_sources || data_feed) && (!data_sources || !exclude_feed)
// +build all core data_sources data_feed
// +build !data_sources !exclude_feed

package acceptancetests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

func TestAccAzureDevOps_DataSource_Feed_By_Name(t *testing.T) {
name := testutils.GenerateResourceName()

FeedData := fmt.Sprintf(`
resource "azuredevops_feed" "feed" {
name = "%s"
}

data "azuredevops_feed" "feed" {
name = azuredevops_feed.feed.name
}
`, name)

tfNode := "data.azuredevops_feed.feed"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckResourceAttrSet(tfNode, "feed_id"),
),
},
},
})
}

func TestAccAzureDevOps_DataSource_Feed_By_Feed_Id(t *testing.T) {
name := testutils.GenerateResourceName()

FeedData := fmt.Sprintf(`
resource "azuredevops_feed" "feed" {
name = "%s"
}

data "azuredevops_feed" "feed" {
feed_id = azuredevops_feed.feed.id
}
`, name)

tfNode := "data.azuredevops_feed.feed"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckResourceAttrSet(tfNode, "feed_id"),
),
},
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//go:build (all || core || data_sources || data_feed) && (!data_sources || !exclude_feed)
// +build all core data_sources data_feed
// +build !data_sources !exclude_feed

package acceptancetests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

func TestAccAzureDevOps_Resource_FeedPermission(t *testing.T) {
name := testutils.GenerateResourceName()
groupName := testutils.GenerateResourceName()
projectName := testutils.GenerateResourceName()

FeedResource := fmt.Sprintf(`
%s

resource "azuredevops_feed" "feed" {
name = "%s"
project_id = azuredevops_project.project.id
}

resource "azuredevops_feed_permission" "permission" {
feed_id = azuredevops_feed.feed.id
project_id = azuredevops_project.project.id
role = "reader"
identity_descriptor = azuredevops_group.group.descriptor
}
`, testutils.HclGroupResource("group", projectName, groupName), name)

tfNode := "azuredevops_feed_permission.permission"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "feed_id"),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
resource.TestCheckResourceAttrSet(tfNode, "role"),
resource.TestCheckResourceAttrSet(tfNode, "identity_descriptor"),
),
},
},
})
}
124 changes: 124 additions & 0 deletions azuredevops/internal/acceptancetests/resource_feed_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//go:build (all || core || data_sources || data_feed) && (!data_sources || !exclude_feed)
// +build all core data_sources data_feed
// +build !data_sources !exclude_feed

package acceptancetests

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)

func TestAccAzureDevOps_Resource_Feed(t *testing.T) {
name := testutils.GenerateResourceName()

FeedResource := fmt.Sprintf(`
resource "azuredevops_feed" "feed" {
name = "%s"
}
`, name)

tfNode := "azuredevops_feed.feed"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckNoResourceAttr(tfNode, "project"),
),
},
},
})
}

func TestAccAzureDevOps_Resource_Feed_with_Project(t *testing.T) {
name := testutils.GenerateResourceName()
projectName := testutils.GenerateResourceName()

ProjectResource := testutils.HclProjectResource(projectName)
FeedResource := fmt.Sprintf(`
%s

resource "azuredevops_feed" "feed" {
name = "%s"
project_id = azuredevops_project.project.id
}

`, ProjectResource, name)

tfNode := "azuredevops_feed.feed"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckResourceAttrSet(tfNode, "project_id"),
),
},
},
})
}

func TestAccAzureDevOps_Resource_Feed_Soft_Delete(t *testing.T) {
name := testutils.GenerateResourceName()

FeedResource := fmt.Sprintf(`
resource "azuredevops_feed" "feed" {
name = "%s"
features {
permanent_delete = false
}
}
`, name)

tfNode := "azuredevops_feed.feed"
resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: FeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckNoResourceAttr(tfNode, "project"),
resource.TestCheckResourceAttr(tfNode, "restored", "false"),
),
},
},
})

SecondFeedResource := fmt.Sprintf(`
resource "azuredevops_feed" "second_feed" {
name = "%s"
features {
permanent_delete = false
}
}
`, name)

SecondTfNode := "azuredevops_feed.second_feed"

resource.Test(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
ProviderFactories: testutils.GetProviderFactories(),
Steps: []resource.TestStep{
{
Config: SecondFeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(SecondTfNode, "name"),
resource.TestCheckNoResourceAttr(SecondTfNode, "project"),
resource.TestCheckResourceAttr(SecondTfNode, "restored", "true"),
),
},
},
})
}
9 changes: 9 additions & 0 deletions azuredevops/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/core"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/elastic"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/featuremanagement"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/feed"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/git"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/graph"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/identity"
Expand Down Expand Up @@ -58,6 +59,7 @@ type AggregatedClient struct {
TaskAgentClient taskagent.Client
MemberEntitleManagementClient memberentitlementmanagement.Client
FeatureManagementClient featuremanagement.Client
FeedClient feed.Client
SecurityClient security.Client
IdentityClient identity.Client
WorkItemTrackingClient workitemtracking.Client
Expand Down Expand Up @@ -147,6 +149,12 @@ func GetAzdoClient(azdoTokenProvider func() (string, error), organizationURL str

featuremanagementClient := featuremanagement.NewClient(ctx, connection)

feedClient, err := feed.NewClient(ctx, connection)
if err != nil {
log.Printf("getAzdoClient(): feed.NewClient failed.")
return nil, err
}

workitemtrackingClient, err := workitemtracking.NewClient(ctx, connection)
if err != nil {
log.Printf("getAzdoClient(): workitemtracking.NewClient failed.")
Expand Down Expand Up @@ -195,6 +203,7 @@ func GetAzdoClient(azdoTokenProvider func() (string, error), organizationURL str
TaskAgentClient: taskagentClient,
MemberEntitleManagementClient: memberentitlementmanagementClient,
FeatureManagementClient: featuremanagementClient,
FeedClient: feedClient,
SecurityClient: securityClient,
IdentityClient: identityClient,
WorkItemTrackingClient: workitemtrackingClient,
Expand Down
77 changes: 77 additions & 0 deletions azuredevops/internal/service/feed/data_feed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package feed

import (
"fmt"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/microsoft/azure-devops-go-api/azuredevops/v7/feed"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/client"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/utils"
)

func DataFeed() *schema.Resource {
return &schema.Resource{
Read: dataFeedRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
ValidateFunc: validation.StringIsNotWhiteSpace,
Optional: true,
AtLeastOneOf: []string{
"name", "feed_id",
},
},
"feed_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.IsUUID,
ConflictsWith: []string{
"name",
},
},
"project_id": {
Type: schema.TypeString,
ValidateFunc: validation.IsUUID,
Optional: true,
},
},
}
}

func dataFeedRead(d *schema.ResourceData, m interface{}) error {
clients := m.(*client.AggregatedClient)

name := d.Get("name").(string)
id := d.Get("feed_id").(string)
projectId := d.Get("project_id").(string)

identifier := id
if identifier == "" {
identifier = name
}

getFeed, err := clients.FeedClient.GetFeed(clients.Ctx, feed.GetFeedArgs{
FeedId: &identifier,
Project: &projectId,
})

if err != nil {
if utils.ResponseWasNotFound(err) {
d.SetId("")
return nil
}
return fmt.Errorf("Error reading feed during read: %+v", err)
}

if getFeed != nil {
d.SetId((*getFeed.Id).String())
d.Set("name", *getFeed.Name)
d.Set("feed_id", (*getFeed.Id).String())
if getFeed.Project != nil {
d.Set("project_id", (*getFeed.Project.Id).String())
}
}

return nil
}
Loading