Skip to content

Commit

Permalink
Add support for nested objects in output
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Dwyer <brian.dwyer@broadridge.com>
  • Loading branch information
bdwyertech committed May 10, 2023
1 parent b73df0b commit 4c76309
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ spec:
source: Inline
module: |
// All outputs are written to the connection secret. Non-sensitive outputs
// are stored as string values in the status.atProvider.outputs object.
// are stored in the status.atProvider.outputs object.
output "url" {
value = google_storage_bucket.example.self_link
}
Expand Down
5 changes: 3 additions & 2 deletions apis/v1beta1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1beta1

import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
)
Expand Down Expand Up @@ -134,8 +135,8 @@ type WorkspaceParameters struct {

// WorkspaceObservation are the observable fields of a Workspace.
type WorkspaceObservation struct {
Checksum string `json:"checksum,omitempty"`
Outputs map[string]string `json:"outputs,omitempty"`
Checksum string `json:"checksum,omitempty"`
Outputs map[string]extensionsV1.JSON `json:"outputs,omitempty"`
}

// A WorkspaceSpec defines the desired state of a Workspace.
Expand Down
5 changes: 3 additions & 2 deletions apis/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions internal/controller/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/afero"
corev1 "k8s.io/api/core/v1"
extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/apimachinery/pkg/types"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -474,14 +475,12 @@ func op2cd(o []terraform.Output) managed.ConnectionDetails {
// workspace_type.Workspace.
func generateWorkspaceObservation(op []terraform.Output) v1beta1.WorkspaceObservation {
wo := v1beta1.WorkspaceObservation{
Outputs: make(map[string]string, len(op)),
Outputs: make(map[string]extensionsV1.JSON, len(op)),
}
for _, o := range op {
if !o.Sensitive {
if o.Type == terraform.OutputTypeString {
wo.Outputs[o.Name] = o.StringValue()
} else if j, err := o.JSONValue(); err == nil {
wo.Outputs[o.Name] = string(j)
if j, err := o.JSONValue(); err == nil {
wo.Outputs[o.Name] = extensionsV1.JSON{Raw: j}
}
}
}
Expand Down
13 changes: 7 additions & 6 deletions internal/controller/workspace/workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/afero"
corev1 "k8s.io/api/core/v1"
extensionsV1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
runtime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -999,8 +1000,8 @@ func TestObserve(t *testing.T) {
},
wo: v1beta1.WorkspaceObservation{
Checksum: tfChecksum,
Outputs: map[string]string{
"string": "",
Outputs: map[string]extensionsV1.JSON{
"string": {Raw: []byte("")},
},
},
},
Expand Down Expand Up @@ -1042,8 +1043,8 @@ func TestObserve(t *testing.T) {
},
wo: v1beta1.WorkspaceObservation{
Checksum: tfChecksum,
Outputs: map[string]string{
"string": "",
Outputs: map[string]extensionsV1.JSON{
"string": {Raw: []byte("")},
},
},
},
Expand Down Expand Up @@ -1265,8 +1266,8 @@ func TestCreate(t *testing.T) {
},
},
wo: v1beta1.WorkspaceObservation{
Outputs: map[string]string{
"object": "null",
Outputs: map[string]extensionsV1.JSON{
"object": {Raw: []byte("null")},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion package/crds/tf.upbound.io_workspaces.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ spec:
type: string
outputs:
additionalProperties:
type: string
x-kubernetes-preserve-unknown-fields: true
type: object
type: object
conditions:
Expand Down

0 comments on commit 4c76309

Please sign in to comment.