Skip to content

Commit

Permalink
introduce restored computed value determining if Feed was created o…
Browse files Browse the repository at this point in the history
…r restored
  • Loading branch information
Mateusz Wreczycki committed Apr 11, 2024
1 parent 430229f commit 7834075
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
17 changes: 14 additions & 3 deletions azuredevops/internal/acceptancetests/resource_feed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,31 @@ func TestAccAzureDevOps_Resource_Feed_Soft_Delete(t *testing.T) {
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"
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: FeedResource,
Config: SecondFeedResource,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfNode, "name"),
resource.TestCheckNoResourceAttr(tfNode, "project"),
resource.TestCheckResourceAttrSet(SecondTfNode, "name"),
resource.TestCheckNoResourceAttr(SecondTfNode, "project"),
resource.TestCheckResourceAttr(SecondTfNode, "restored", "true"),
),
},
},
Expand Down
14 changes: 12 additions & 2 deletions azuredevops/internal/service/feed/resource_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func ResourceFeed() *schema.Resource {
Optional: true,
Default: true,
},
"restored": {
Type: schema.TypeBool,
Computed: true,
},
},
}
}
Expand All @@ -49,6 +53,8 @@ func resourceFeedCreate(d *schema.ResourceData, m interface{}) error {
if err != nil {
return fmt.Errorf(" restoring feed. Name: %s, Error: %+v", name, err)
}

return resourceFeedRead(d, m)
}

err := createFeed(d, m)
Expand Down Expand Up @@ -80,6 +86,7 @@ func resourceFeedRead(d *schema.ResourceData, m interface{}) error {
}

if getFeed != nil {
d.SetId(getFeed.Id.String())
d.Set("name", getFeed.Name)
if getFeed.Project != nil {
d.Set("project_id", getFeed.Project.Id.String())
Expand Down Expand Up @@ -160,7 +167,7 @@ func createFeed(d *schema.ResourceData, m interface{}) error {
Name: &name,
}

createdFeed, err := clients.FeedClient.CreateFeed(clients.Ctx, feed.CreateFeedArgs{
_, err := clients.FeedClient.CreateFeed(clients.Ctx, feed.CreateFeedArgs{
Feed: &createFeed,
Project: &projectId,
})
Expand All @@ -169,7 +176,8 @@ func createFeed(d *schema.ResourceData, m interface{}) error {
return err
}

d.SetId((*createdFeed).Id.String())
d.Set("restored", false)

return nil
}

Expand Down Expand Up @@ -197,5 +205,7 @@ func restoreFeed(d *schema.ResourceData, m interface{}) error {
return err
}

d.Set("restored", true)

return nil
}
1 change: 1 addition & 0 deletions website/docs/d/feed.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ The following attributes are exported:
- `name` - The name of the Feed.
- `feed_id` - The ID of the Feed.
- `project_id` - The ID of the Project.
- `restored` - Determines if Feed was restored after Soft Delete

## Relevant Links

Expand Down

0 comments on commit 7834075

Please sign in to comment.