@@ -669,9 +669,6 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
669669 }
670670 d .SetId (instanceId )
671671
672- //get system disk ID and data disk ID
673- var systemDiskId string
674- var dataDiskIds []string
675672 err = resource .Retry (d .Timeout (schema .TimeoutCreate ), func () * resource.RetryError {
676673 instance , errRet := cvmService .DescribeInstanceById (ctx , instanceId )
677674 if errRet != nil {
@@ -682,17 +679,6 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
682679 return resource .NonRetryableError (fmt .Errorf ("cvm instance %s launch failed, this resource will not be stored to tfstate and will auto removed\n ." , * instance .InstanceId ))
683680 }
684681 if instance != nil && * instance .InstanceState == CVM_STATUS_RUNNING {
685- //get system disk ID
686- if instance .SystemDisk != nil && instance .SystemDisk .DiskId != nil {
687- systemDiskId = * instance .SystemDisk .DiskId
688- }
689- if instance .DataDisks != nil {
690- for _ , dataDisk := range instance .DataDisks {
691- if dataDisk != nil && dataDisk .DiskId != nil {
692- dataDiskIds = append (dataDiskIds , * dataDisk .DiskId )
693- }
694- }
695- }
696682 return nil
697683 }
698684 return resource .RetryableError (fmt .Errorf ("cvm instance status is %s, retry..." , * instance .InstanceState ))
@@ -706,31 +692,20 @@ func resourceTencentCloudInstanceCreate(d *schema.ResourceData, meta interface{}
706692 if tags := helper .GetTags (d , "tags" ); len (tags ) > 0 {
707693 tcClient := meta .(tccommon.ProviderMeta ).GetAPIV3Conn ()
708694 tagService := svctag .NewTagService (tcClient )
709- resourceName := tccommon .BuildTagResourceName ("cvm" , "instance" , tcClient .Region , instanceId )
710- if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
711- // If tags attachment failed, the user will be notified, then plan/apply/update with terraform.
712- return err
713- }
714-
715- //except instance ,system disk and data disk will be tagged
716- //keep logical consistence with the console
717- //tag system disk
718- if systemDiskId != "" {
719- resourceName = tccommon .BuildTagResourceName ("cvm" , "volume" , tcClient .Region , systemDiskId )
720- if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
721- // If tags attachment failed, the user will be notified, then plan/apply/update with terraform.
722- return err
695+ err := resource .Retry (tccommon .WriteRetryTimeout , func () * resource.RetryError {
696+ actualTags , e := tagService .DescribeResourceTags (ctx , "cvm" , "instance" , tcClient .Region , instanceId )
697+ if e != nil {
698+ return resource .RetryableError (e )
723699 }
724- }
725- //tag disk ids
726- for _ , diskId := range dataDiskIds {
727- if diskId != "" {
728- resourceName = tccommon .BuildTagResourceName ("cvm" , "volume" , tcClient .Region , diskId )
729- if err := tagService .ModifyTags (ctx , resourceName , tags , nil ); err != nil {
730- // If tags attachment failed, the user will be notified, then plan/apply/update with terraform.
731- return err
700+ for tagKey , tagValue := range tags {
701+ if v , ok := actualTags [tagKey ]; ! ok || v != tagValue {
702+ return resource .RetryableError (fmt .Errorf ("tag(%s, %s) modification is not completed" , tagKey , tagValue ))
732703 }
733704 }
705+ return nil
706+ })
707+ if err != nil {
708+ return err
734709 }
735710 }
736711
0 commit comments