第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

運(yùn)行“地球形態(tài)計(jì)劃”時(shí)如何顯示警告/錯(cuò)誤?

運(yùn)行“地球形態(tài)計(jì)劃”時(shí)如何顯示警告/錯(cuò)誤?

Go
元芳怎么了 2022-09-19 17:15:32
我正在構(gòu)建一個(gè)Terraform插件/提供程序(鏈接),它將幫助用戶(hù)在云平臺(tái)上管理他們的云資源,例如云實(shí)例,Kubernetes集群等。目前,云平臺(tái)不支持 Kubernetes 節(jié)點(diǎn)在創(chuàng)建后的大小更改。如果用戶(hù)想要更改節(jié)點(diǎn)大小,則需要使用新節(jié)點(diǎn)大小創(chuàng)建新的節(jié)點(diǎn)池。所以我在我的插件代碼中添加了這個(gè)塊,特別是在Kubernetes集群更新方法中(鏈接):if d.HasChange("target_nodes_size") {    errMsg := []string{        "[ERR] Unable to update 'target_nodes_size' after creation.",        "Please create a new node pool with the new node size.",    }    return fmt.Errorf(strings.Join(errMsg, " "))}問(wèn)題是,錯(cuò)誤僅在我運(yùn)行命令時(shí)出現(xiàn)。我想要的是,我希望它在用戶(hù)運(yùn)行命令時(shí)顯示,以便他們盡早知道,如果不創(chuàng)建新的節(jié)點(diǎn)池,就不可能更改節(jié)點(diǎn)大小。terraform applyterraform plan如何使該字段不可變并在輸出的早期顯示錯(cuò)誤?target_nodes_sizeterraform plan
查看完整描述

1 回答

?
Helenr

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超4個(gè)贊

這里正確的做法是告訴Terraform,對(duì)資源的更改不能就地完成,而是需要重新創(chuàng)建資源(通常先銷(xiāo)毀,然后創(chuàng)建,但你可以用lifecycle.create_before_destroy來(lái)逆轉(zhuǎn))。

創(chuàng)建提供程序時(shí),可以使用架構(gòu)屬性上的 ForceNew 參數(shù)執(zhí)行此操作。

例如,從 AWS 的 API 端來(lái)看,資源被認(rèn)為是不可變的,因此架構(gòu)中的每個(gè)非計(jì)算屬性都標(biāo)記為 ForceNew: trueaws_launch_configuration

func resourceAwsLaunchConfiguration() *schema.Resource {

    return &schema.Resource{

        Create: resourceAwsLaunchConfigurationCreate,

        Read:   resourceAwsLaunchConfigurationRead,

        Delete: resourceAwsLaunchConfigurationDelete,

        Importer: &schema.ResourceImporter{

            State: schema.ImportStatePassthrough,

        },


        Schema: map[string]*schema.Schema{

            "arn": {

                Type:     schema.TypeString,

                Computed: true,

            },


            "name": {

                Type:          schema.TypeString,

                Optional:      true,

                Computed:      true,

                ForceNew:      true,

                ConflictsWith: []string{"name_prefix"},

                ValidateFunc:  validation.StringLenBetween(1, 255),

            },

// ...

如果您隨后嘗試修改任何字段,則Terraform的計(jì)劃將顯示它需要替換資源,并且在應(yīng)用時(shí),只要用戶(hù)接受該計(jì)劃,它就會(huì)自動(dòng)執(zhí)行此操作。ForceNew: true

對(duì)于更復(fù)雜的示例,該資源允許就地進(jìn)行版本更改,但僅適用于特定的版本升級(jí)路徑(因此您無(wú)法直接從轉(zhuǎn)到,而必須轉(zhuǎn)到。這是通過(guò)在架構(gòu)上使用 CustomizeDiff 屬性來(lái)完成的,該屬性允許您在計(jì)劃時(shí)使用邏輯來(lái)提供與靜態(tài)配置通常不同的結(jié)果。aws_elasticsearch_domain5.47.85.4 -> 5.6 -> 6.8 -> 7.8

“aws_elasticsearch_domain elasticsearch_version”屬性自定義Diff 如下所示:

func resourceAwsElasticSearchDomain() *schema.Resource {

    return &schema.Resource{

        Create: resourceAwsElasticSearchDomainCreate,

        Read:   resourceAwsElasticSearchDomainRead,

        Update: resourceAwsElasticSearchDomainUpdate,

        Delete: resourceAwsElasticSearchDomainDelete,

        Importer: &schema.ResourceImporter{

            State: resourceAwsElasticSearchDomainImport,

        },


        Timeouts: &schema.ResourceTimeout{

            Update: schema.DefaultTimeout(60 * time.Minute),

        },


        CustomizeDiff: customdiff.Sequence(

            customdiff.ForceNewIf("elasticsearch_version", func(_ context.Context, d *schema.ResourceDiff, meta interface{}) bool {

                newVersion := d.Get("elasticsearch_version").(string)

                domainName := d.Get("domain_name").(string)


                conn := meta.(*AWSClient).esconn

                resp, err := conn.GetCompatibleElasticsearchVersions(&elasticsearch.GetCompatibleElasticsearchVersionsInput{

                    DomainName: aws.String(domainName),

                })

                if err != nil {

                    log.Printf("[ERROR] Failed to get compatible ElasticSearch versions %s", domainName)

                    return false

                }

                if len(resp.CompatibleElasticsearchVersions) != 1 {

                    return true

                }

                for _, targetVersion := range resp.CompatibleElasticsearchVersions[0].TargetVersions {

                    if aws.StringValue(targetVersion) == newVersion {

                        return false

                    }

                }

                return true

            }),

            SetTagsDiff,

        ),

嘗試在已接受的升級(jí)路徑上升級(jí) 的 (例如 )將顯示它是計(jì)劃中的就地升級(jí),并在應(yīng)用時(shí)應(yīng)用。另一方面,如果您嘗試通過(guò)不允許的路徑進(jìn)行升級(jí)(例如直接),那么Terraform的計(jì)劃將顯示它需要銷(xiāo)毀現(xiàn)有的彈性搜索域并創(chuàng)建一個(gè)新域。aws_elasticsearch_domainelasticsearch_version7.4 -> 7.85.4 -> 7.8


查看完整回答
反對(duì) 回復(fù) 2022-09-19
  • 1 回答
  • 0 關(guān)注
  • 116 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)