-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package tfe | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
|
||
tfe "github.com/hashicorp/go-tfe" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceTFEWorkspaceReadme() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTFEWorkspaceReadReadme, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"workspace_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"raw_markdown": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTFEWorkspaceReadReadme(d *schema.ResourceData, meta interface{}) error { | ||
tfeClient := meta.(*tfe.Client) | ||
|
||
// Get the workspace | ||
workspaceID := d.Get("workspace_id").(string) | ||
readme, err := tfeClient.Workspaces.Readme(ctx, workspaceID) | ||
if err != nil { | ||
if err == tfe.ErrResourceNotFound { | ||
return fmt.Errorf("Could not find workspace with ID %s", workspaceID) | ||
} | ||
return fmt.Errorf( | ||
"Error retrieving readme %s: %v", workspaceID, err) | ||
} | ||
|
||
rs, err := ioutil.ReadAll(readme) | ||
if err != nil { | ||
return fmt.Errorf("Error reading readme: %s", err) | ||
} | ||
|
||
d.Set("raw_markdown", rs) | ||
|
||
d.SetId(workspaceID) | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package tfe | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestAccTFEWorkspaceReadmeDataSource_basic(t *testing.T) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters