簡體   English   中英

創建存儲帳戶后無法立即創建天藍色的容器

[英]Fails to create azure container right after storage account was created

我正在嘗試從terraform創建存儲帳戶,並使用其某些訪問密鑰來創建blob容器。 我的terraform配置是從bash文件給出的,因此,這里最重要的步驟之一如下:

customer_prefix=4pd
customer_environment=dev

RESOURCE_GROUP_NAME=$customer_prefix
az group create --name $RESOURCE_GROUP_NAME --location westeurope

# Creating Storage account
STORAGE_ACCOUNT_NAME=4pdterraformstates
az storage account create --resource-group $RESOURCE_GROUP_NAME --name $STORAGE_ACCOUNT_NAME  --sku Standard_LRS --encryption-services blob

# We are getting the storage account key to access to it when we need to store the terraform .tf production state file
ACCOUNT_KEY=$(az storage account keys list --resource-group $RESOURCE_GROUP_NAME --account-name $STORAGE_ACCOUNT_NAME --query [0].value -o tsv)


# Creating a blob container
CONTAINER_NAME=4pd-tfstate
az storage container create --name $CONTAINER_NAME --account-name $STORAGE_ACCOUNT_NAME --account-key $ACCOUNT_KEY

source ../terraform_apply_template.sh

我正在從.bash文件發送那些az cli命令,因此,我正在向其中發送其他TF_VAR_azurerm ...變量

最終,當我執行bash的第一個bash文件時,對創建計划的terraform_apply_template.sh調用將被應用。 如下:

#!/bin/bash
#Terminates script execution after first failed (returned non-zero exit code) command and treat unset variables as errors.
set -ue

terraform init -backend-config=$statefile -backend-config=$storage_access_key -backend-config=$storage_account_name

#TF:
function tf_plan {
    terraform plan -out=$outfile
}

case "${1-}" in
    apply)
        tf_plan && terraform apply $outfile
        ;;

    apply-saved)
        if [ ! -f $outfile ]; then tf_plan; fi
        terraform apply $outfile
        ;;

    *)
        tf_plan

        echo ""
        echo "Not applying changes. Call one of the following to apply changes:"
        echo " - '$0 apply': prepares and applies new plan"
        echo " - '$0 apply-saved': applies saved plan ($outfile)"
        ;;
esac

但是我的輸出是以下內容,初始化了azurerm后端,創建了名為4pdterraformstates的存儲帳戶,還創建了4pd-tfstate blob容器,

在此處輸入圖片說明

但在實踐中此操作無效,我得到以下輸出:

Initializing the backend...

Successfully configured the backend "azurerm"! Terraform will automatically
use this backend unless the backend configuration changes.

Error: Failed to get existing workspaces: storage: service returned error: StatusCode=404, ErrorCode=ContainerNotFound, ErrorMessage=The specified container does not exist.
RequestId:2db5df4e-f01e-014c-369d-272246000000
Time:2019-06-20T19:21:01.6931098Z, RequestInitiated=Thu, 20 Jun 2019 19:21:01 GMT, RequestId=2db5df4e-f01e-014c-369d-272246000000, API Version=2016-05-31, QueryParameterName=, QueryParameterValue=

尋找類似的行為, 我在azurerm提供程序terraform存儲庫中發現了此問題

並且還根據直接在terraform存儲庫中創建的此問題 ,這看起來像是網絡操作錯誤...但奇怪的是它已修復..

我正在使用terraform v0.12.1版本

⟩ terraform version
Terraform v0.12.2

根據@ Gaurav-Mantri的回答,有必要等到要配置存儲帳戶后,才能繼續執行與存儲帳戶本身相關的其他任務。

創建存儲帳戶是一個異步過程。 當您執行z存儲帳戶創建以創建存儲帳戶時,請求將發送到Azure,並且您會收到一個可接受的響應(如果一切順利)。

創建(設置)存儲帳戶的整個過程需要一些時間(根據我的經驗,最多需要1分鍾),並且在配置該存儲帳戶之前,不允許對該存儲帳戶進行任何操作。

創建存儲帳戶后如何包括等待過程? 似乎僅使用bash sleep命令或將bash shell與read命令暫停一段時間是不夠的。

創建存儲帳戶是一個異步過程。 當您執行az storage account create以創建存儲帳戶時,請求將發送到Azure,並且您會收到一個accepted響應(如果一切順利)。

創建(設置)存儲帳戶的整個過程需要一些時間(根據我的經驗,最多需要1分鍾),並且在配置該存儲帳戶之前,不允許對該存儲帳戶進行任何操作。

這是您收到錯誤的原因,因為您在發送創建請求后立即嘗試執行操作。

不確定如何執行,但需要做的就是等待配置存儲帳戶。 您可以定期(例如每5秒一次)獲取存儲帳戶的屬性,並檢查其配置狀態。 供應狀態成功后,您可以嘗試創建一個容器。 那時您的請求應該會成功。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM