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,
UID: uid,
}
// TODO add provider
switch provider {
case cloudprovider.GCP:
gcpProjectOutput, ok := tfState.Values.Outputs["project"]
if ok {
if !ok {
return ApplyOutput{}, errors.New("no project output found")
}
gcpProject, ok := gcpProjectOutput.Value.(string)
if !ok {
return ApplyOutput{}, errors.New("invalid type in project output: not a string")
}
cidrNodesOutput, ok := tfState.Values.Outputs["ip_cidr_nodes"]
if !ok {
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 {
return ApplyOutput{}, errors.New("invalid type in ip_cidr_nodes output: not a string")
}
cidrPodsOutput, ok := tfState.Values.Outputs["ip_cidr_pods"]
if !ok {
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 {
return ApplyOutput{}, errors.New("invalid type in ip_cidr_pods output: not a string")
}
res.GCP = &GCPApplyOutput{
ProjectID: gcpProject,
IPCidrNode: cidrNodes,
IPCidrPod: cidrPods,
}
}
case cloudprovider.Azure:
var attestationURL string
if ok {
if attestationURLOutput, ok := tfState.Values.Outputs["attestationURL"]; ok {
if attestationURLString, ok := attestationURLOutput.Value.(string); ok {
attestationURL = attestationURLString
}
attestationURLOutput, ok := tfState.Values.Outputs["attestationURL"]
if !ok {
return ApplyOutput{}, errors.New("no attestationURL output found")
}
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"]