From 3639f800de2138fc2779631082c8258a014a8640 Mon Sep 17 00:00:00 2001 From: Ramin Date: Fri, 3 Nov 2023 20:24:59 +0200 Subject: [PATCH 1/6] azure backend --- go.mod | 9 +- pkg/backend/azurerm/azurerm.go | 186 +++++++++++++++++++++++++++++++++ pkg/backend/azurerm/factory.go | 5 +- pkg/backend/azurerm/main.go | 89 ---------------- 4 files changed, 198 insertions(+), 91 deletions(-) create mode 100644 pkg/backend/azurerm/azurerm.go delete mode 100644 pkg/backend/azurerm/main.go diff --git a/go.mod b/go.mod index c58c1921..37e01581 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.20 require ( cloud.google.com/go/storage v1.33.0 + github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.2.0 + github.com/Azure/azure-storage-blob-go v0.15.0 github.com/Masterminds/semver v1.5.0 github.com/Masterminds/sprig v2.22.0+incompatible github.com/apex/log v1.9.0 @@ -34,6 +36,11 @@ require ( k8s.io/client-go v0.28.3 ) +require ( + github.com/Azure/azure-pipeline-go v0.2.3 // indirect + github.com/mattn/go-ieproxy v0.0.1 // indirect +) + require ( cloud.google.com/go v0.110.8 // indirect cloud.google.com/go/compute v1.23.0 // indirect @@ -42,7 +49,7 @@ require ( cloud.google.com/go/kms v1.15.2 // indirect filippo.io/age v1.1.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 // indirect github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.0.0 // indirect diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go new file mode 100644 index 00000000..7ce1651c --- /dev/null +++ b/pkg/backend/azurerm/azurerm.go @@ -0,0 +1,186 @@ +package azurerm + +import ( + "bytes" + "context" + "fmt" + + "github.com/Azure/azure-sdk-for-go/sdk/azidentity" + "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" + "github.com/hashicorp/hcl/v2/hclwrite" + "github.com/shalb/cluster.dev/pkg/hcltools" + "github.com/shalb/cluster.dev/pkg/project" + "github.com/shalb/cluster.dev/pkg/utils" + "github.com/zclconf/go-cty/cty" +) + +// Backend - describe azure backend for interface package.backend. +type Backend struct { + name string + state map[string]interface{} + ProjectPtr *project.Project `yaml:"-"` + ContainerName string `yaml:"container_name,omitempty"` + StorageAccountName string `yaml:"storage_account_name,omitempty"` + ResourceGroupName string `yaml:"resource_group_name,omitempty"` + client *azblob.Client +} + +func (b *Backend) State() map[string]interface{} { + return b.state +} + +// Name return name. +func (b *Backend) Name() string { + return b.name +} + +// Provider return name. +func (b *Backend) Provider() string { + return "azurerm" +} + +// GetBackendBytes generate terraform backend config. +func (b *Backend) GetBackendBytes(stackName, unitName string) ([]byte, error) { + f, err := b.GetBackendHCL(stackName, unitName) + if err != nil { + return nil, err + } + return f.Bytes(), nil +} + +// GetBackendHCL generate terraform backend config. +func (b *Backend) GetBackendHCL(stackName, unitName string) (*hclwrite.File, error) { + b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) + + f := hclwrite.NewEmptyFile() + rootBody := f.Body() + terraformBlock := rootBody.AppendNewBlock("terraform", []string{}) + backendBlock := terraformBlock.Body().AppendNewBlock("backend", []string{"azurerm"}) + backendBody := backendBlock.Body() + for key, value := range b.state { + backendBody.SetAttributeValue(key, cty.StringVal(value.(string))) + } + return f, nil +} + +// GetRemoteStateHCL generate terraform remote state for this backend. +func (b *Backend) GetRemoteStateHCL(stackName, unitName string) ([]byte, error) { + b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) + + f := hclwrite.NewEmptyFile() + + rootBody := f.Body() + dataBlock := rootBody.AppendNewBlock("data", []string{"terraform_remote_state", fmt.Sprintf("%s-%s", stackName, unitName)}) + dataBody := dataBlock.Body() + dataBody.SetAttributeValue("backend", cty.StringVal("azurerm")) + config, err := hcltools.InterfaceToCty(b.state) + if err != nil { + return nil, err + } + dataBody.SetAttributeValue("config", config) + return f.Bytes(), nil +} + +func (b *Backend) createAzureBlobClient() error { + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + return err + } + + client, err := azblob.NewClient("https://"+b.StorageAccountName+".blob.core.windows.net/", cred, nil) + if err != nil { + return err + } + + b.client = client + return nil +} + +func (b *Backend) LockState() error { + if b.client == nil { + if err := b.createAzureBlobClient(); err != nil { + return err + } + } + lockKey := fmt.Sprintf("cdev.%s.lock", b.ProjectPtr.Name()) + ctx := context.Background() + + // Check if the blob exists. + _, err := b.client.DownloadStream(ctx, b.ContainerName, lockKey, nil) + if err == nil { + return fmt.Errorf("Lock state blob found, the state is locked") + } + + sessionID := utils.RandString(10) + + // Upload a blob to Azure Blob Storage. + buf := []byte(sessionID) + _, err = b.client.UploadBuffer(ctx, b.ContainerName, lockKey, buf, &azblob.UploadBufferOptions{}) + if err != nil { + return fmt.Errorf("Can't save lock state blob: %v", err) + } + + return nil +} + +func (b *Backend) UnlockState() error { + if b.client == nil { + if err := b.createAzureBlobClient(); err != nil { + return err + } + } + + lockKey := fmt.Sprintf("cdev.%s.lock", b.ProjectPtr.Name()) + ctx := context.Background() + _, err := b.client.DeleteBlob(ctx, b.ContainerName, lockKey, nil) + if err != nil { + return fmt.Errorf("Can't unlock state: %v", err) + } + + return nil +} + +func (b *Backend) WriteState(stateData string) error { + if b.client == nil { + if err := b.createAzureBlobClient(); err != nil { + return err + } + } + + stateKey := fmt.Sprintf("cdev.%s.state", b.ProjectPtr.Name()) + ctx := context.Background() + buf := []byte(stateData) + _, err := b.client.UploadBuffer(ctx, b.ContainerName, stateKey, buf, &azblob.UploadBufferOptions{}) + if err != nil { + return fmt.Errorf("Can't save state blob: %v", err) + } + + return nil +} + +func (b *Backend) ReadState() (string, error) { + fmt.Printf("Does not exist in container '%s'\n", b.ContainerName) + if b.client == nil { + if err := b.createAzureBlobClient(); err != nil { + return "", err + } + } + + stateKey := fmt.Sprintf("cdev.%s.state", b.ProjectPtr.Name()) + ctx := context.Background() + + // Download the blob + get, err := b.client.DownloadStream(ctx, b.ContainerName, stateKey, nil) + if err != nil { + fmt.Errorf("Can't read state blob: %v", err) + return "", err + } + + stateData := bytes.Buffer{} + retryReader := get.NewRetryReader(ctx, &azblob.RetryReaderOptions{}) + _, err = stateData.ReadFrom(retryReader) + + err = retryReader.Close() + + return stateData.String(), nil +} diff --git a/pkg/backend/azurerm/factory.go b/pkg/backend/azurerm/factory.go index 304f27ea..6942525d 100644 --- a/pkg/backend/azurerm/factory.go +++ b/pkg/backend/azurerm/factory.go @@ -16,10 +16,13 @@ func (f *Factory) New(config []byte, name string, p *project.Project) (project.B name: name, ProjectPtr: p, } - err := yaml.Unmarshal(config, &bk.state) + state := map[string]interface{}{} + err := yaml.Unmarshal(config, &bk) if err != nil { return nil, utils.ResolveYamlError(config, err) } + + bk.state = state return &bk, nil } diff --git a/pkg/backend/azurerm/main.go b/pkg/backend/azurerm/main.go deleted file mode 100644 index aa76e947..00000000 --- a/pkg/backend/azurerm/main.go +++ /dev/null @@ -1,89 +0,0 @@ -package azurerm - -import ( - "fmt" - - "github.com/shalb/cluster.dev/pkg/hcltools" - "github.com/shalb/cluster.dev/pkg/project" - "github.com/zclconf/go-cty/cty" - - "github.com/hashicorp/hcl/v2/hclwrite" -) - -// Backend - describe s3 backend for interface package.backend. -type Backend struct { - name string - state map[string]interface{} - ProjectPtr *project.Project -} - -func (b *Backend) State() map[string]interface{} { - return b.state -} - -// Name return name. -func (b *Backend) Name() string { - return b.name -} - -// Provider return name. -func (b *Backend) Provider() string { - return "azurerm" -} - -// GetBackendBytes generate terraform backend config. -func (b *Backend) GetBackendBytes(stackName, unitName string) ([]byte, error) { - f, err := b.GetBackendHCL(stackName, unitName) - if err != nil { - return nil, err - } - return f.Bytes(), nil -} - -// GetBackendHCL generate terraform backend config. -func (b *Backend) GetBackendHCL(stackName, unitName string) (*hclwrite.File, error) { - b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) - - f := hclwrite.NewEmptyFile() - rootBody := f.Body() - terraformBlock := rootBody.AppendNewBlock("terraform", []string{}) - backendBlock := terraformBlock.Body().AppendNewBlock("backend", []string{"azurerm"}) - backendBody := backendBlock.Body() - for key, value := range b.state { - backendBody.SetAttributeValue(key, cty.StringVal(value.(string))) - } - return f, nil -} - -// GetRemoteStateHCL generate terraform remote state for this backend. -func (b *Backend) GetRemoteStateHCL(stackName, unitName string) ([]byte, error) { - b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) - - f := hclwrite.NewEmptyFile() - - rootBody := f.Body() - dataBlock := rootBody.AppendNewBlock("data", []string{"terraform_remote_state", fmt.Sprintf("%s-%s", stackName, unitName)}) - dataBody := dataBlock.Body() - dataBody.SetAttributeValue("backend", cty.StringVal("azurerm")) - config, err := hcltools.InterfaceToCty(b.state) - if err != nil { - return nil, err - } - dataBody.SetAttributeValue("config", config) - return f.Bytes(), nil -} -func (b *Backend) LockState() error { - return fmt.Errorf("cdev state azurerm not supported") -} - -func (b *Backend) UnlockState() error { - return fmt.Errorf("cdev state azurerm not supported") -} - -func (b *Backend) WriteState(stateData string) error { - return fmt.Errorf("cdev state azurerm not supported") -} - -func (b *Backend) ReadState() (string, error) { - return "", fmt.Errorf("cdev state azurerm not supported") -} From f54018ca7fbef8646e3bcac0ee8a74b0bc6d1dc4 Mon Sep 17 00:00:00 2001 From: Ramin Date: Sun, 5 Nov 2023 11:04:01 +0200 Subject: [PATCH 2/6] azure backend --- go.mod | 2 +- pkg/backend/azurerm/azurerm.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 37e01581..76514e90 100644 --- a/go.mod +++ b/go.mod @@ -38,6 +38,7 @@ require ( require ( github.com/Azure/azure-pipeline-go v0.2.3 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect github.com/mattn/go-ieproxy v0.0.1 // indirect ) @@ -48,7 +49,6 @@ require ( cloud.google.com/go/iam v1.1.2 // indirect cloud.google.com/go/kms v1.15.2 // indirect filippo.io/age v1.1.1 // indirect - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.8.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.4.0 github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.0.1 // indirect diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go index 7ce1651c..8573964a 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/pkg/backend/azurerm/azurerm.go @@ -4,6 +4,7 @@ import ( "bytes" "context" "fmt" + "strings" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" @@ -169,6 +170,17 @@ func (b *Backend) ReadState() (string, error) { stateKey := fmt.Sprintf("cdev.%s.state", b.ProjectPtr.Name()) ctx := context.Background() + // Check if the object exists. + _, err := b.client.DownloadStream(ctx, b.ContainerName, stateKey, nil) + if err != nil { + // Check if the error message contains "BlobNotFound" to identify the error. + if strings.Contains(err.Error(), "BlobNotFound") { + fmt.Println("The blob does not exist.") + return "", nil + } + return "", err + } + // Download the blob get, err := b.client.DownloadStream(ctx, b.ContainerName, stateKey, nil) if err != nil { From 9a9fe19e2d9267be363faa79b73c0fc60e53566c Mon Sep 17 00:00:00 2001 From: Ramin Date: Sun, 5 Nov 2023 12:48:39 +0200 Subject: [PATCH 3/6] working azure backend --- pkg/backend/azurerm/azurerm.go | 43 ++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go index 8573964a..1a339410 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/pkg/backend/azurerm/azurerm.go @@ -13,16 +13,17 @@ import ( "github.com/shalb/cluster.dev/pkg/project" "github.com/shalb/cluster.dev/pkg/utils" "github.com/zclconf/go-cty/cty" + "gopkg.in/yaml.v3" ) // Backend - describe azure backend for interface package.backend. type Backend struct { - name string - state map[string]interface{} - ProjectPtr *project.Project `yaml:"-"` - ContainerName string `yaml:"container_name,omitempty"` - StorageAccountName string `yaml:"storage_account_name,omitempty"` - ResourceGroupName string `yaml:"resource_group_name,omitempty"` + name string `yaml:"-"` + state map[string]interface{} `yaml:"-"` + ProjectPtr *project.Project `yaml:"-"` + ContainerName string `yaml:"container_name,omitempty"` + StorageAccountName string `yaml:"storage_account_name,omitempty"` + ResourceGroupName string `yaml:"resource_group_name,omitempty"` client *azblob.Client } @@ -40,6 +41,17 @@ func (b *Backend) Provider() string { return "azurerm" } +func getStateMap(in Backend) (res map[string]interface{}, err error) { + tmpData, err := yaml.Marshal(in) + if err != nil { + return + } + res = map[string]interface{}{} + err = yaml.Unmarshal(tmpData, &res) + err = utils.ResolveYamlError(tmpData, err) + return +} + // GetBackendBytes generate terraform backend config. func (b *Backend) GetBackendBytes(stackName, unitName string) ([]byte, error) { f, err := b.GetBackendHCL(stackName, unitName) @@ -51,14 +63,17 @@ func (b *Backend) GetBackendBytes(stackName, unitName string) ([]byte, error) { // GetBackendHCL generate terraform backend config. func (b *Backend) GetBackendHCL(stackName, unitName string) (*hclwrite.File, error) { - b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) - + bConfigTmpl, err := getStateMap(*b) + if err != nil { + return nil, err + } + bConfigTmpl["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) f := hclwrite.NewEmptyFile() rootBody := f.Body() terraformBlock := rootBody.AppendNewBlock("terraform", []string{}) backendBlock := terraformBlock.Body().AppendNewBlock("backend", []string{"azurerm"}) backendBody := backendBlock.Body() - for key, value := range b.state { + for key, value := range bConfigTmpl { backendBody.SetAttributeValue(key, cty.StringVal(value.(string))) } return f, nil @@ -66,15 +81,18 @@ func (b *Backend) GetBackendHCL(stackName, unitName string) (*hclwrite.File, err // GetRemoteStateHCL generate terraform remote state for this backend. func (b *Backend) GetRemoteStateHCL(stackName, unitName string) ([]byte, error) { - b.state["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) - + bConfigTmpl, err := getStateMap(*b) + if err != nil { + return nil, err + } + bConfigTmpl["key"] = fmt.Sprintf("%s-%s.state", stackName, unitName) f := hclwrite.NewEmptyFile() rootBody := f.Body() dataBlock := rootBody.AppendNewBlock("data", []string{"terraform_remote_state", fmt.Sprintf("%s-%s", stackName, unitName)}) dataBody := dataBlock.Body() dataBody.SetAttributeValue("backend", cty.StringVal("azurerm")) - config, err := hcltools.InterfaceToCty(b.state) + config, err := hcltools.InterfaceToCty(bConfigTmpl) if err != nil { return nil, err } @@ -160,7 +178,6 @@ func (b *Backend) WriteState(stateData string) error { } func (b *Backend) ReadState() (string, error) { - fmt.Printf("Does not exist in container '%s'\n", b.ContainerName) if b.client == nil { if err := b.createAzureBlobClient(); err != nil { return "", err From 629aba6d8b57531117b94df7d90f6d9dc1b268e0 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 7 Nov 2023 15:40:47 +0200 Subject: [PATCH 4/6] azure backend configure --- pkg/backend/azurerm/azurerm.go | 57 ++++++++++++---------------------- pkg/backend/azurerm/factory.go | 2 +- 2 files changed, 20 insertions(+), 39 deletions(-) diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go index 1a339410..dc30674d 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/pkg/backend/azurerm/azurerm.go @@ -27,6 +27,25 @@ type Backend struct { client *azblob.Client } +func (b *Backend) Configure() error { + if b.client != nil { + return nil + } + + cred, err := azidentity.NewDefaultAzureCredential(nil) + if err != nil { + return err + } + + client, err := azblob.NewClient("https://"+b.StorageAccountName+".blob.core.windows.net/", cred, nil) + if err != nil { + return err + } + + b.client = client + return nil +} + func (b *Backend) State() map[string]interface{} { return b.state } @@ -100,27 +119,7 @@ func (b *Backend) GetRemoteStateHCL(stackName, unitName string) ([]byte, error) return f.Bytes(), nil } -func (b *Backend) createAzureBlobClient() error { - cred, err := azidentity.NewDefaultAzureCredential(nil) - if err != nil { - return err - } - - client, err := azblob.NewClient("https://"+b.StorageAccountName+".blob.core.windows.net/", cred, nil) - if err != nil { - return err - } - - b.client = client - return nil -} - func (b *Backend) LockState() error { - if b.client == nil { - if err := b.createAzureBlobClient(); err != nil { - return err - } - } lockKey := fmt.Sprintf("cdev.%s.lock", b.ProjectPtr.Name()) ctx := context.Background() @@ -143,12 +142,6 @@ func (b *Backend) LockState() error { } func (b *Backend) UnlockState() error { - if b.client == nil { - if err := b.createAzureBlobClient(); err != nil { - return err - } - } - lockKey := fmt.Sprintf("cdev.%s.lock", b.ProjectPtr.Name()) ctx := context.Background() _, err := b.client.DeleteBlob(ctx, b.ContainerName, lockKey, nil) @@ -160,12 +153,6 @@ func (b *Backend) UnlockState() error { } func (b *Backend) WriteState(stateData string) error { - if b.client == nil { - if err := b.createAzureBlobClient(); err != nil { - return err - } - } - stateKey := fmt.Sprintf("cdev.%s.state", b.ProjectPtr.Name()) ctx := context.Background() buf := []byte(stateData) @@ -178,12 +165,6 @@ func (b *Backend) WriteState(stateData string) error { } func (b *Backend) ReadState() (string, error) { - if b.client == nil { - if err := b.createAzureBlobClient(); err != nil { - return "", err - } - } - stateKey := fmt.Sprintf("cdev.%s.state", b.ProjectPtr.Name()) ctx := context.Background() diff --git a/pkg/backend/azurerm/factory.go b/pkg/backend/azurerm/factory.go index 6942525d..e2d527af 100644 --- a/pkg/backend/azurerm/factory.go +++ b/pkg/backend/azurerm/factory.go @@ -23,7 +23,7 @@ func (f *Factory) New(config []byte, name string, p *project.Project) (project.B } bk.state = state - return &bk, nil + return &bk, bk.Configure() } func init() { From 1a095236d9cdcc1a5f22e8376d15336efaeeb5c9 Mon Sep 17 00:00:00 2001 From: Ramin Date: Tue, 7 Nov 2023 18:25:32 +0200 Subject: [PATCH 5/6] azure backend configure --- pkg/backend/azurerm/azurerm.go | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go index dc30674d..fd8c763a 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/pkg/backend/azurerm/azurerm.go @@ -18,13 +18,32 @@ import ( // Backend - describe azure backend for interface package.backend. type Backend struct { - name string `yaml:"-"` - state map[string]interface{} `yaml:"-"` - ProjectPtr *project.Project `yaml:"-"` - ContainerName string `yaml:"container_name,omitempty"` - StorageAccountName string `yaml:"storage_account_name,omitempty"` - ResourceGroupName string `yaml:"resource_group_name,omitempty"` - client *azblob.Client + client *azblob.Client + name string `yaml:"-"` + state map[string]interface{} `yaml:"-"` + ProjectPtr *project.Project `yaml:"-"` + ContainerName string `yaml:"container_name,omitempty"` + StorageAccountName string `yaml:"storage_account_name,omitempty"` + ResourceGroupName string `yaml:"resource_group_name,omitempty"` + AccessKey string `yaml:"access_key,omitempty"` + ClientID string `yaml:"client_id,omitempty"` + ClientCertificatePassword string `yaml:"client_certificate_password,omitempty"` + ClientCertificatePath string `yaml:"client_certificate_path,omitempty"` + ClientSecret string `yaml:"client_secret,omitempty"` + CustomResourceManagerEndpoint string `yaml:"endpoint,omitempty"` + MetadataHost string `yaml:"metadata_host,omitempty"` + Environment string `yaml:"environment,omitempty"` + MsiEndpoint string `yaml:"msi_endpoint,omitempty"` + OIDCToken string `yaml:"oidc_token,omitempty"` + OIDCTokenFilePath string `yaml:"oidc_token_file_path,omitempty"` + OIDCRequestURL string `yaml:"oidc_request_url,omitempty"` + OIDCRequestToken string `yaml:"oidc_request_token,omitempty"` + SasToken string `yaml:"sas_token,omitempty"` + SubscriptionID string `yaml:"subscription_id,omitempty"` + TenantID string `yaml:"tenant_id,omitempty"` + UseMsi bool `yaml:"use_msi,omitempty"` + UseOIDC bool `yaml:"use_oidc,omitempty"` + UseAzureADAuthentication bool `yaml:"use_azuread_auth,omitempty"` } func (b *Backend) Configure() error { From 2674e37e349f8aca77407f9a75e64452783ffe6b Mon Sep 17 00:00:00 2001 From: romanprog Date: Thu, 23 Nov 2023 19:31:53 +0100 Subject: [PATCH 6/6] Update azurerm.go, use apex log --- pkg/backend/azurerm/azurerm.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/backend/azurerm/azurerm.go b/pkg/backend/azurerm/azurerm.go index fd8c763a..0ec59c58 100644 --- a/pkg/backend/azurerm/azurerm.go +++ b/pkg/backend/azurerm/azurerm.go @@ -6,6 +6,7 @@ import ( "fmt" "strings" + "github.com/apex/log" "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob" "github.com/hashicorp/hcl/v2/hclwrite" @@ -192,7 +193,7 @@ func (b *Backend) ReadState() (string, error) { if err != nil { // Check if the error message contains "BlobNotFound" to identify the error. if strings.Contains(err.Error(), "BlobNotFound") { - fmt.Println("The blob does not exist.") + log.Debugf("The blob does not exist.") return "", nil } return "", err