cli: refactor terraform output parsing (#2158)

This commit is contained in:
3u13r 2023-08-03 16:17:23 +02:00 committed by GitHub
parent dccb1dfde9
commit 720c48ea45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -216,15 +216,18 @@ func (c *Client) ShowCluster(ctx context.Context, provider cloudprovider.Provide
Secret: secret, Secret: secret,
UID: uid, UID: uid,
} }
// TODO add provider
switch provider { switch provider {
case cloudprovider.GCP: case cloudprovider.GCP:
gcpProjectOutput, ok := tfState.Values.Outputs["project"] gcpProjectOutput, ok := tfState.Values.Outputs["project"]
if ok { if !ok {
return ApplyOutput{}, errors.New("no project output found")
}
gcpProject, ok := gcpProjectOutput.Value.(string) gcpProject, ok := gcpProjectOutput.Value.(string)
if !ok { if !ok {
return ApplyOutput{}, errors.New("invalid type in project output: not a string") return ApplyOutput{}, errors.New("invalid type in project output: not a string")
} }
cidrNodesOutput, ok := tfState.Values.Outputs["ip_cidr_nodes"] cidrNodesOutput, ok := tfState.Values.Outputs["ip_cidr_nodes"]
if !ok { if !ok {
return ApplyOutput{}, errors.New("no ip_cidr_nodes output found") return ApplyOutput{}, errors.New("no ip_cidr_nodes output found")
@ -233,6 +236,7 @@ func (c *Client) ShowCluster(ctx context.Context, provider cloudprovider.Provide
if !ok { if !ok {
return ApplyOutput{}, errors.New("invalid type in ip_cidr_nodes output: not a string") return ApplyOutput{}, errors.New("invalid type in ip_cidr_nodes output: not a string")
} }
cidrPodsOutput, ok := tfState.Values.Outputs["ip_cidr_pods"] cidrPodsOutput, ok := tfState.Values.Outputs["ip_cidr_pods"]
if !ok { if !ok {
return ApplyOutput{}, errors.New("no ip_cidr_pods output found") return ApplyOutput{}, errors.New("no ip_cidr_pods output found")
@ -241,20 +245,20 @@ func (c *Client) ShowCluster(ctx context.Context, provider cloudprovider.Provide
if !ok { if !ok {
return ApplyOutput{}, errors.New("invalid type in ip_cidr_pods output: not a string") return ApplyOutput{}, errors.New("invalid type in ip_cidr_pods output: not a string")
} }
res.GCP = &GCPApplyOutput{ res.GCP = &GCPApplyOutput{
ProjectID: gcpProject, ProjectID: gcpProject,
IPCidrNode: cidrNodes, IPCidrNode: cidrNodes,
IPCidrPod: cidrPods, IPCidrPod: cidrPods,
} }
}
case cloudprovider.Azure: case cloudprovider.Azure:
var attestationURL string attestationURLOutput, ok := tfState.Values.Outputs["attestationURL"]
if ok { if !ok {
if attestationURLOutput, ok := tfState.Values.Outputs["attestationURL"]; ok { return ApplyOutput{}, errors.New("no attestationURL output found")
if attestationURLString, ok := attestationURLOutput.Value.(string); ok {
attestationURL = attestationURLString
}
} }
attestationURL, ok := attestationURLOutput.Value.(string)
if !ok {
return ApplyOutput{}, errors.New("invalid type in attestationURL output: not a string")
} }
azureUAMIOutput, ok := tfState.Values.Outputs["user_assigned_identity_client_id"] azureUAMIOutput, ok := tfState.Values.Outputs["user_assigned_identity_client_id"]