Skip to content

Commit

Permalink
Added state_name so it allows to set the name of the state file.
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomationD committed Sep 9, 2022
1 parent 4c6133c commit 8a8f669
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
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

0 comments on commit 8a8f669

Please sign in to comment.