mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-04 23:35:11 -04:00
cli: write infrastructure to new state file (#2321)
Co-authored-by: 3u13r <lc@edgeless.systems>
This commit is contained in:
parent
8f5a2867b4
commit
322c4aad10
26 changed files with 263 additions and 109 deletions
|
@ -24,6 +24,7 @@ import (
|
|||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/cli/internal/state"
|
||||
"github.com/edgelesssys/constellation/v2/internal/cloud/cloudprovider"
|
||||
"github.com/edgelesssys/constellation/v2/internal/constants"
|
||||
"github.com/edgelesssys/constellation/v2/internal/file"
|
||||
|
@ -170,6 +171,44 @@ func (c *Client) ShowIAM(ctx context.Context, provider cloudprovider.Provider) (
|
|||
}
|
||||
}
|
||||
|
||||
// ShowInfrastructure reads the state of Constellation cluster resources from Terraform.
|
||||
func (c *Client) ShowInfrastructure(ctx context.Context, provider cloudprovider.Provider) (state.Infrastructure, error) {
|
||||
tfOutput, err := c.ShowCluster(ctx, provider)
|
||||
if err != nil {
|
||||
return state.Infrastructure{}, err
|
||||
}
|
||||
return ConvertToInfrastructure(tfOutput), nil
|
||||
}
|
||||
|
||||
// ConvertToInfrastructure converts the Terraform output of a cluster creation or apply operation to a state.Infrastructure.
|
||||
func ConvertToInfrastructure(applyOutput ApplyOutput) state.Infrastructure {
|
||||
var infra state.Infrastructure
|
||||
infra.UID = applyOutput.UID
|
||||
infra.ClusterEndpoint = applyOutput.IP
|
||||
infra.InitSecret = applyOutput.Secret
|
||||
infra.APIServerCertSANs = applyOutput.APIServerCertSANs
|
||||
|
||||
if applyOutput.Azure != nil {
|
||||
infra.Azure = &state.Azure{
|
||||
ResourceGroup: applyOutput.Azure.ResourceGroup,
|
||||
SubscriptionID: applyOutput.Azure.SubscriptionID,
|
||||
UserAssignedIdentity: applyOutput.Azure.UserAssignedIdentity,
|
||||
NetworkSecurityGroupName: applyOutput.Azure.NetworkSecurityGroupName,
|
||||
LoadBalancerName: applyOutput.Azure.LoadBalancerName,
|
||||
AttestationURL: applyOutput.Azure.AttestationURL,
|
||||
}
|
||||
}
|
||||
|
||||
if applyOutput.GCP != nil {
|
||||
infra.GCP = &state.GCP{
|
||||
ProjectID: applyOutput.GCP.ProjectID,
|
||||
IPCidrNode: applyOutput.GCP.IPCidrNode,
|
||||
IPCidrPod: applyOutput.GCP.IPCidrPod,
|
||||
}
|
||||
}
|
||||
return infra
|
||||
}
|
||||
|
||||
// ShowCluster reads the state of Constellation cluster resources from Terraform.
|
||||
func (c *Client) ShowCluster(ctx context.Context, provider cloudprovider.Provider) (ApplyOutput, error) {
|
||||
tfState, err := c.tf.Show(ctx)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue