Skip to content
This repository was archived by the owner on Feb 11, 2025. It is now read-only.

[Question] Is it possible to transform Outputs that are JSON string? #133

Open
edanc opened this issue Nov 10, 2022 · 3 comments · May be fixed by #138
Open

[Question] Is it possible to transform Outputs that are JSON string? #133

edanc opened this issue Nov 10, 2022 · 3 comments · May be fixed by #138
Labels
enhancement New feature or request

Comments

@edanc
Copy link

edanc commented Nov 10, 2022

What problem are you facing?

Hi!

I have been attempting to use this provider as a way to get information about a vpc. For example I have a workspace similar to the one in the examples.

        kind: Workspace
        metadata:
          name: observe-only-vpc
        spec:
          providerConfigRef:
            name: aws-east-us-1-staging
          forProvider:
            source: Inline
            module: |
              data "aws_vpc" "vpc" {
                tags = {
                  Name = var.vpcName
                }
              }
              data "aws_subnets" "private_subnets" {
                filter {
                  name   = "vpc-id"
                  values = [data.aws_vpc.vpc.id]
                }
                filter {
                  name   = "tag:Tier"
                  values = ["private"]
                }
              }
              output "vpc_id" {
                description = "Observe Only VPC ID"
                value       = try(data.aws_vpc.vpc.id, "")
              }
     
              output "private_subnets" {
                value = data.aws_subnets.private_subnets.ids
              }

              variable "vpcName" {
                description = "VPC name"
                type        = string
              }
            vars:
              - key: vpcName
      patches:
        - fromFieldPath: spec.parameters.vpcName
          toFieldPath: spec.forProvider.vars[0].value
        - type: ToCompositeFieldPath
          fromFieldPath: status.atProvider.outputs.vpc_id
          toFieldPath: status.share.vpcId
          policy:
            fromFieldPath: Optional
        - type: ToCompositeFieldPath
          fromFieldPath: status.atProvider.outputs.private_subnets
          toFieldPath: status.share.vpc_private_subnets
          policy:
            fromFieldPath: Optional

The problem im facing is that im using the status.share.vpc_private_subnets value in another resource that expects
this to be of type array

error message

Cannot apply composed resource: cannot patch object: Cluster.eks.aws.crossplane.io "crossplane-eks-example" is invalid: spec.forProvider.resourcesVpcConfig.subnetIds: Invalid value: "string": spec.forProvider.resourcesVpcConfig.subnetIds in body must be of type array: "string"

I'm new to Crossplane so i'm not sure if its possible to convert the string '["id-222", "id-111"]' into an array?

@edanc edanc added the enhancement New feature or request label Nov 10, 2022
@bobh66
Copy link
Collaborator

bobh66 commented Nov 11, 2022

Right now there is no way to output a list or object/map, only string/number formats are supported. I've been thinking about updating this code to support output of list and object, I just need to find the time to do it.

@edanc
Copy link
Author

edanc commented Nov 11, 2022

@bobh66 Thanks for the reply. Is there anyway to transform that in compositions?

@edanc
Copy link
Author

edanc commented Nov 16, 2022

@bobh66 I have been working on adding this feature and I believe I have a working example. I will open a pull request after I have passing test.

The approach I took was to use https://pkg.go.dev/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1#JSON as the value of the map for WorkspaceObservation

type WorkspaceObservation struct {
	Outputs map[string]extensionV1.JSON `json:"outputs,omitempty"`
}

@edanc edanc linked a pull request Nov 16, 2022 that will close this issue
2 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants