繁体   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