tf

package
v0.0.0-...-2a9aca8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "tf",
	Short: "Execute terraform commands using go-terradagger",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()

		ux := &struct {
			Msg   tui.MessageWriter
			Title tui.TitleWriter
		}{
			Msg:   tui.NewMessageWriter(),
			Title: tui.NewTitleWriter(),
		}

		ux.Title.ShowTitle("TerraDagger CLI")

		td := terradagger.New(ctx, &terradagger.Options{
			Workspace: viper.GetString("workspace"),
		})

		if err := td.StartEngine(); err != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: "Unable to start the Dagger engine",
				Error:   err,
			})
		}

		defer td.Engine.GetEngine().Close()

		tfOptions :=
			terraformcore.WithOptions(td, &terraformcore.TfOptions{
				ModulePath:                   viper.GetString("module"),
				EnableSSHPrivateGit:          true,
				TerraformVersion:             viper.GetString("terraform-version"),
				EnvVarsToInjectByKeyFromHost: []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"},
			})

		_, tfInitErr := terraform.InitE(td, tfOptions, terraform.InitOptions{})
		if tfInitErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tfInitErr.Error(),
				Error:   tfInitErr,
			})
		}

		_, tfPlanErr := terraform.PlanE(td, tfOptions, terraform.PlanOptions{
			Vars: []terraformcore.TFInputVariable{
				{
					Name:  "is_enabled",
					Value: "true",
				}},
			TerraformVarFiles: viper.GetStringSlice("var-files"),
		})
		if tfPlanErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tfPlanErr.Error(),
				Error:   tfPlanErr,
			})
		}

		_, tfApplyErr := terraform.ApplyE(td, tfOptions, terraform.ApplyOptions{
			AutoApprove: true,
			Vars: []terraformcore.TFInputVariable{
				{
					Name:  "is_enabled",
					Value: "true",
				}},
			TerraformVarFiles: viper.GetStringSlice("var-files"),
		})
		if tfApplyErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tfApplyErr.Error(),
				Error:   tfApplyErr,
			})
		}

		_, tfDestroyErr := terraform.DestroyE(td, tfOptions, terraform.DestroyOptions{
			AutoApprove: true,
			Vars: []terraformcore.TFInputVariable{
				{
					Name:  "is_enabled",
					Value: "true",
				}},
			TerraformVarFiles: viper.GetStringSlice("var-files"),
		})
		if tfDestroyErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tfDestroyErr.Error(),
				Error:   tfDestroyErr,
			})
		}
	},
}
View Source
var TgCMD = &cobra.Command{
	Use:   "tg",
	Short: "Execute terraform commands using go-terradagger",
	Run: func(cmd *cobra.Command, args []string) {
		ctx := context.Background()

		ux := &struct {
			Msg   tui.MessageWriter
			Title tui.TitleWriter
		}{
			Msg:   tui.NewMessageWriter(),
			Title: tui.NewTitleWriter(),
		}

		ux.Title.ShowTitle("TerraDagger CLI")

		td := terradagger.New(ctx, &terradagger.Options{
			Workspace: viper.GetString("workspace"),
		})

		if err := td.StartEngine(); err != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: "Unable to start the Dagger engine",
				Error:   err,
			})
		}

		defer td.Engine.GetEngine().Close()

		tgOptions :=
			terraformcore.WithOptions(td, &terraformcore.TfOptions{
				ModulePath:                   viper.GetString("module"),
				EnableSSHPrivateGit:          true,
				TerraformVersion:             viper.GetString("terraform-version"),
				EnvVarsToInjectByKeyFromHost: []string{"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN"},
			})

		_, tgInitErr := terragrunt.InitE(td, tgOptions, terragrunt.InitOptions{}, nil)
		if tgInitErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tgInitErr.Error(),
				Error:   tgInitErr,
			})
		}

		_, tgPlanErr := terragrunt.PlanE(td, tgOptions, terragrunt.PlanOptions{}, nil)

		if tgPlanErr != nil {
			ux.Msg.ShowError(tui.MessageOptions{
				Message: tgInitErr.Error(),
				Error:   tgPlanErr,
			})
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳