This repository has been archived by the owner on Dec 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ui): show resources and outputs on workspace page (#542)
Fixes #308
- Loading branch information
Showing
46 changed files
with
344 additions
and
89 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
74 changes: 74 additions & 0 deletions
74
internal/http/html/static/templates/content/state_get.tmpl
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,74 @@ | ||
<div class="" x-data="{ activeTab: 'resources' }"> | ||
<div class="flex"> | ||
<label | ||
class="p-2 border cursor-pointer" for="resources-tab" | ||
@click="activeTab = 'resources'" | ||
:class="{ 'bg-gray-200 text-black border-black': activeTab == 'resources' }" | ||
id="resources-label" | ||
>Resources ({{ len .Resources }})</label> | ||
<label | ||
class="p-2 border cursor-pointer" for="outputs-tab" | ||
@click="activeTab = 'outputs'" | ||
:class="{ 'bg-gray-200 text-black border-black': activeTab == 'outputs' }" | ||
id="outputs-label" | ||
>Outputs ({{ len .Outputs }})</label> | ||
</div> | ||
<table | ||
x-show="activeTab == 'resources'" | ||
class="table-fixed w-full text-left break-words border-collapse" | ||
id="resources-table" | ||
> | ||
{{ with .Resources }} | ||
<thead class="bg-gray-200 border-t border-b border-slate-900"> | ||
<tr> | ||
<th>Name</th> | ||
<th>Provider</th> | ||
<th>Type</th> | ||
<th>Module</th> | ||
</tr> | ||
</thead> | ||
{{ end }} | ||
<tbody> | ||
{{ range .Resources }} | ||
<tr class="even:bg-gray-100"> | ||
<td>{{ .Name }}</td> | ||
<td>{{ .Provider }}</td> | ||
<td>{{ .Type }}</td> | ||
<td>{{ .ModuleName }}</td> | ||
</tr> | ||
{{ else }} | ||
<tr> | ||
<td>No resources currently exist.</td> | ||
</tr> | ||
{{ end }} | ||
</tbody> | ||
</table> | ||
<table | ||
x-show="activeTab == 'outputs'" | ||
class="table-fixed w-full text-left break-words border-collapse" | ||
id="outputs-table" | ||
> | ||
{{ with .Outputs }} | ||
<thead class="bg-gray-200 border-t border-b border-slate-900"> | ||
<tr> | ||
<th>Name</th> | ||
<th>Type</th> | ||
<th>Value</th> | ||
</tr> | ||
</thead> | ||
{{ end }} | ||
<tbody> | ||
{{ range $k, $v := .Outputs }} | ||
<tr> | ||
<td>{{ $k }}</td> | ||
<td>{{ $v.Type }}</td> | ||
<td><span class="bg-gray-200">{{ $v.StringValue }}</span></td> | ||
</tr> | ||
{{ else }} | ||
<tr> | ||
<td>No outputs currently exist.</td> | ||
</tr> | ||
{{ end }} | ||
</tbody> | ||
</table> | ||
</div> |
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
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
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,47 @@ | ||
package integration | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/chromedp/chromedp" | ||
"github.com/leg100/otf/internal" | ||
"github.com/leg100/otf/internal/run" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestIntegration_StateUI demonstrates the displaying of terraform state via | ||
// the UI | ||
func TestIntegration_StateUI(t *testing.T) { | ||
integrationTest(t) | ||
|
||
daemon, org, ctx := setup(t, nil) | ||
|
||
// create run and wait for it to complete | ||
ws := daemon.createWorkspace(t, ctx, org) | ||
cv := daemon.createAndUploadConfigurationVersion(t, ctx, ws, nil) | ||
_ = daemon.createRun(t, ctx, ws, cv) | ||
applied: | ||
for event := range daemon.sub { | ||
if r, ok := event.Payload.(*run.Run); ok { | ||
switch r.Status { | ||
case internal.RunApplied: | ||
break applied | ||
case internal.RunPlanned: | ||
err := daemon.Apply(ctx, r.ID) | ||
require.NoError(t, err) | ||
case internal.RunErrored: | ||
t.Fatal("run unexpectedly finished with an error") | ||
} | ||
} | ||
} | ||
|
||
browser.Run(t, ctx, chromedp.Tasks{ | ||
chromedp.Navigate(workspaceURL(daemon.Hostname(), org.Name, ws.Name)), | ||
matchRegex(t, `//label[@id='resources-label']`, `Resources \(1\)`), | ||
matchRegex(t, `//label[@id='outputs-label']`, `Outputs \(0\)`), | ||
matchText(t, `//table[@id='resources-table']/tbody/tr/td[1]`, `test`), | ||
matchText(t, `//table[@id='resources-table']/tbody/tr/td[2]`, `hashicorp/null`), | ||
matchText(t, `//table[@id='resources-table']/tbody/tr/td[3]`, `null_resource`), | ||
matchText(t, `//table[@id='resources-table']/tbody/tr/td[4]`, `root`), | ||
}) | ||
} |
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
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 |
---|---|---|
@@ -1,17 +1,80 @@ | ||
package state | ||
|
||
import "encoding/json" | ||
|
||
// File is the terraform state file contents | ||
type File struct { | ||
Version int | ||
Serial int64 | ||
Lineage string | ||
Outputs map[string]FileOutput | ||
import ( | ||
"encoding/json" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var providerPathRegex = regexp.MustCompile(`provider\[".*?/([^"]+)"\]`) | ||
|
||
type ( | ||
// File is the terraform state file contents | ||
File struct { | ||
Version int | ||
Serial int64 | ||
Lineage string | ||
Outputs map[string]FileOutput | ||
Resources []Resource | ||
} | ||
|
||
// FileOutput is an output in the terraform state file | ||
FileOutput struct { | ||
Value json.RawMessage | ||
Sensitive bool | ||
} | ||
|
||
Resource struct { | ||
Name string | ||
ProviderURI string `json:"provider"` | ||
Type string | ||
Module string | ||
} | ||
) | ||
|
||
// Provider extracts the provider from the provider URI | ||
func (r Resource) Provider() string { | ||
matches := providerPathRegex.FindStringSubmatch(r.ProviderURI) | ||
if matches == nil || len(matches) < 2 { | ||
return r.ProviderURI | ||
} | ||
return matches[1] | ||
} | ||
|
||
func (r Resource) ModuleName() string { | ||
if r.Module == "" { | ||
return "root" | ||
} | ||
return strings.TrimPrefix(r.Module, "module.") | ||
} | ||
|
||
// Type determines the HCL type of the output value | ||
func (r FileOutput) Type() (string, error) { | ||
var dst any | ||
if err := json.Unmarshal(r.Value, &dst); err != nil { | ||
return "", err | ||
} | ||
|
||
var typ string | ||
switch dst.(type) { | ||
case bool: | ||
typ = "bool" | ||
case float64: | ||
typ = "number" | ||
case string: | ||
typ = "string" | ||
case []any: | ||
typ = "tuple" | ||
case map[string]any: | ||
typ = "object" | ||
case nil: | ||
typ = "null" | ||
default: | ||
typ = "unknown" | ||
} | ||
return typ, nil | ||
} | ||
|
||
// FileOutput is an output in the terraform state file | ||
type FileOutput struct { | ||
Value json.RawMessage | ||
Sensitive bool | ||
func (r FileOutput) StringValue() string { | ||
return string(r.Value) | ||
} |
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
Oops, something went wrong.