Skip to content

Commit

Permalink
Merge pull request #106 from bdwyertech/output-map
Browse files Browse the repository at this point in the history
Add support for nested objects in output
  • Loading branch information
ytsarev authored Aug 10, 2023
2 parents 9afc47c + 4d21b7f commit d79a410
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 28 deletions.
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ PLATFORMS ?= linux_amd64 linux_arm64

# Setup Go
NPROCS ?= 1
GOLANGCILINT_VERSION ?= 1.50.0
# GOLANGCILINT_VERSION is inherited from build submodule by default.
# Uncomment below if you need to override the version.
# GOLANGCILINT_VERSION ?= 1.50.0
GO_TEST_PARALLEL := $(shell echo $$(( $(NPROCS) / 2 )))
GO_STATIC_PACKAGES = $(GO_PROJECT)/cmd/provider
GO_LDFLAGS += -X $(GO_PROJECT)/pkg/version.Version=$(VERSION)
Expand All @@ -22,9 +24,10 @@ GO111MODULE = on
# ====================================================================================
# Setup Kubernetes tools

KIND_VERSION = v0.15.0
UP_VERSION = v0.14.0
UP_CHANNEL = stable
# Uncomment below to override the versions from the build module
# KIND_VERSION = v0.15.0
# UP_VERSION = v0.14.0
# UP_CHANNEL = stable
UPTEST_VERSION = v0.5.0
-include build/makelib/k8s_tools.mk

Expand Down
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.

2 changes: 1 addition & 1 deletion build
7 changes: 5 additions & 2 deletions examples/workspace-inline-aws.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ spec:
output "vpc_id" {
value = aws_vpc.main.id
}
output "subnet_id" {
value = aws_subnet.main.id
output "subnet_data" {
value = {
"id" = aws_subnet.main.id
"arn" = aws_subnet.main.arn
}
}
variable "vpcName" {
description = "VPC name"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
golang.org/x/sync v0.1.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
k8s.io/api v0.26.3
k8s.io/apiextensions-apiserver v0.26.1
k8s.io/apimachinery v0.26.3
k8s.io/client-go v0.26.3
sigs.k8s.io/controller-runtime v0.14.6
Expand Down Expand Up @@ -126,7 +127,6 @@ require (
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/component-base v0.26.1 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 // indirect
Expand Down
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
19 changes: 10 additions & 9 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 @@ -852,7 +853,7 @@ func TestObserve(t *testing.T) {
},
wo: v1beta1.WorkspaceObservation{
Checksum: tfChecksum,
Outputs: map[string]string{},
Outputs: map[string]extensionsV1.JSON{},
},
},
},
Expand Down Expand Up @@ -882,7 +883,7 @@ func TestObserve(t *testing.T) {
},
wo: v1beta1.WorkspaceObservation{
Checksum: tfChecksum,
Outputs: map[string]string{},
Outputs: map[string]extensionsV1.JSON{},
},
},
},
Expand Down Expand Up @@ -958,7 +959,7 @@ func TestObserve(t *testing.T) {
},
wo: v1beta1.WorkspaceObservation{
Checksum: tfChecksum,
Outputs: map[string]string{},
Outputs: map[string]extensionsV1.JSON{},
},
},
},
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("null")},
},
},
},
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("null")},
},
},
},
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 d79a410

Please sign in to comment.