Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-cross committed Feb 7, 2022
1 parent b5c7793 commit d73b871
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
26 changes: 16 additions & 10 deletions cmd/meroxa/root/environments/create.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/*
Copyright © 2021 Meroxa Inc
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -18,6 +15,7 @@ package environments

import (
"context"
"encoding/json"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -129,25 +127,33 @@ func (c *Create) Execute(ctx context.Context) error {
c.logger.Infof(ctx, "Provisioning environment...")

environment, err := c.client.CreateEnvironment(ctx, e)
fmt.Printf("err: %+v\n", err)
fmt.Printf("env: %+v\n", environment)

if err != nil {
c.logger.JSON(ctx, environment.Status.State)
if environment.Status.State == meroxa.EnvironmentStatePreflightError {
c.logger.JSON(ctx, environment.Status.PreflightDetails)
}
return err
}

c.logger.Infof(ctx, "Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)

if environment.Status.State == meroxa.EnvironmentStatePreflightSuccess {
if environment.Status.State == meroxa.EnvironmentStatePreflightError {
details, _ := prettyString(environment.Status.PreflightDetails)
c.logger.Errorf(ctx, "Environment %q could not be provisioned because it failed the preflight checks\n%s\n", environment.Name, details)
} else if environment.Status.State == meroxa.EnvironmentStatePreflightSuccess {
environment.Status.PreflightDetails = nil
c.logger.Infof(ctx, "Preflight checks have passed. Environment %q is being provisioned. Run `meroxa env describe %s` for status", environment.Name, environment.Name)
}

c.logger.JSON(ctx, environment)
return nil
}

func prettyString(a interface{}) (string, error) {
j, err := json.MarshalIndent(a, "", " ")
if err != nil {
return "", err
}
return string(j), nil
}

func (c *Create) NotConfirmed() string {
return "\nTo view all options for creating a Meroxa Environment,\n " +
"please run \"meroxa help env create\". \n"
Expand Down
2 changes: 1 addition & 1 deletion utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ func EnvironmentTable(environment *meroxa.Environment) string {
{Text: strings.Join(environment.Status.PreflightDetails.PreflightPermissions.S3, " ; ")},
},
{
{Align: simpletable.AlignRight, Text: "AWS Service Quotas Permissions Status:"},
{Align: simpletable.AlignRight, Text: "AWS ServiceQuotas Permissions Status:"},
{Text: strings.Join(environment.Status.PreflightDetails.PreflightPermissions.ServiceQuotas, " ; ")},
},
{
Expand Down
6 changes: 3 additions & 3 deletions utils/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ func GenerateEnvironmentFailed(environmentName string) meroxa.Environment {
Name: environmentName,
Region: meroxa.EnvironmentRegionUsEast1,
Provider: meroxa.EnvironmentProviderAws,
Status: meroxa.EnvironmentViewStatus{
Status: *meroxa.EnvironmentViewStatus{
State: meroxa.EnvironmentStatePreflightError,
Details: "",
PreflightDetails: meroxa.PreflightDetails{
PreflightDetails: *meroxa.PreflightDetails{
PreflightPermissions: meroxa.PreflightPermissions{
S3: []string{"missing read permission for S3", "missing write permissions for S3"},
EC2: []string{"missing read permission for S3", "missing write permissions for S3"},
},
PreflightLimits: meroxa.PreflightLimits{
PreflightLimits: *meroxa.PreflightLimits{
EIP: "",
},
},
Expand Down

0 comments on commit d73b871

Please sign in to comment.