@@ -18,7 +18,6 @@ package config
18
18
19
19
import (
20
20
"context"
21
- "fmt"
22
21
"html/template"
23
22
"os"
24
23
"strings"
@@ -32,7 +31,7 @@ func CheckTfStateType(conf *Config, bucketNameClusters string, bucketNameSharedV
32
31
if conf .TerraformState == "cloud" {
33
32
if conf .VpcConfig .VpcType == "shared" {
34
33
if bucketNameSharedVPC == "" {
35
- bucketNameSharedVPC : = "tf-state-sharedvpc-" + strings .ToLower (randstr .String (6 ))
34
+ bucketNameSharedVPC = "tf-state-sharedvpc-" + strings .ToLower (randstr .String (6 ))
36
35
err := createTfStorage (conf .VpcConfig .VpcProjectID , bucketNameSharedVPC )
37
36
if err != nil {
38
37
return err
@@ -44,17 +43,18 @@ func CheckTfStateType(conf *Config, bucketNameClusters string, bucketNameSharedV
44
43
}
45
44
}
46
45
if bucketNameClusters == "" {
47
- log .Infof ("Clusters Bucket Name: %s" , bucketNameClusters )
48
- bucketNameClusters := "tf-state-clusters-" + strings .ToLower (randstr .String (6 ))
46
+ bucketNameClusters = "tf-state-clusters-" + strings .ToLower (randstr .String (6 ))
49
47
err := createTfStorage (conf .ClustersProjectID , bucketNameClusters )
50
48
if err != nil {
51
49
return err
52
50
}
51
+ log .Infof ("✅ Created a bucket for the Clusters TF State: %s" , bucketNameClusters )
53
52
}
54
53
err := createTfBackend (bucketNameClusters , "cluster_build/backend.tf" )
55
54
if err != nil {
56
55
return err
57
56
}
57
+ log .Infof ("✅ Created Cluster TF State backend file in bucket: %s" , bucketNameClusters )
58
58
return nil
59
59
}
60
60
return nil
@@ -67,17 +67,12 @@ func createTfStorage(projectId string, bucketName string) error {
67
67
if err != nil {
68
68
return err
69
69
}
70
- attrs , err := c .Bucket (bucketName ).Attrs (ctx )
71
- if err == storage .ErrBucketNotExist {
72
- log .Infof ("Creating storage bucket: %s " , bucketName )
73
- err = c .Bucket (bucketName ).Create (ctx , projectId , nil )
74
- if err != nil {
75
- log .Fatalf ("error creating storage bucket: %s" , err )
76
- return err
77
- }
78
- } else {
79
- fmt .Printf ("The bucket exists and has attributes: %#v\n " , attrs )
70
+ err = c .Bucket (bucketName ).Create (ctx , projectId , nil )
71
+ if err != nil {
72
+ log .Fatalf ("error creating storage bucket: %s" , err )
73
+ return err
80
74
}
75
+ log .Infof ("✅ Created storage bucket: %s " , bucketName )
81
76
return err
82
77
}
83
78
0 commit comments