Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added state_name so it allows to set the name of the state file. #449

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions internal/commands/tfenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,15 @@ func (o *TfenvOptions) Run() error {

func GenerateTerraformFiles(project *config.Project, terraformStateBucketName string) error {
pterm.DefaultSection.Printfln("Starting generate terraform files")

stateKey := fmt.Sprintf("%v/terraform.tfstate", project.Env)

var tf config.Terraform

if project.Terraform != nil {
tf = *project.Terraform["infra"]
}

stateName := tf.StateName
stateKey := fmt.Sprintf("%v/%v.tfstate", project.Env, stateName)

if len(terraformStateBucketName) != 0 {
tf.StateBucketName = terraformStateBucketName
}
Expand Down
1 change: 1 addition & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func InitConfig() {
viper.SetDefault("PREFER_RUNTIME", "native")
viper.SetDefault("CUSTOM_PROMPT", false)
viper.SetDefault("PLAIN_TEXT", false)
viper.SetDefault("terraform.infra.state_name", "terraform")

home, err := os.UserHomeDir()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/config/infra.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Terraform struct {
Version string `mapstructure:",omitempty"`
StateBucketRegion string `mapstructure:"state_bucket_region,omitempty"`
StateBucketName string `mapstructure:"state_bucket_name,omitempty"`
StateName string `mapstructure:"state_name,omitempty"`
RootDomainName string `mapstructure:"root_domain_name,omitempty"`
AwsRegion string `mapstructure:"aws_region,omitempty"`
AwsProfile string `mapstructure:"aws_profile,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions internal/schema/ize-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@
"type": "string",
"description": "(optional) Terraform state bucket name can be specified here. Normally it's generated and defaults to <NAMESPACE>-tf-state"
},
"state_name": {
"type": "string",
"description": "(optional) Terraform state name that will be used in the .tfstate file. Normally it's 'terraform' or state name."
},
"root_domain_name" : {
"type": "string",
"description": "(optional) Root domain name can be set here. This is the main domain that will be passed to the terraform. Generally if your app lives at 'api.dev.nutcorp.net' the root domain is `nutcorp.net`"
Expand Down Expand Up @@ -443,6 +447,10 @@
"type": "string",
"description": "(optional) Terraform state bucket name can be specified here. Normally it's generated and defaults to <NAMESPACE>-tf-state"
},
"state_name": {
"type": "string",
"description": "(optional) Terraform state name that will be used in the .tfstate file. Normally it's 'terraform' or state name."
},
"root_domain_name" : {
"type": "string",
"description": "(optional) Root domain name can be set here. This is the main domain that will be passed to the terraform. Generally if your app lives at 'api.dev.nutcorp.net' the root domain is `nutcorp.net`"
Expand Down