All Products
Search
Document Center

CloudOps Orchestration Service:ACS-ESS-LifeCycleModifyInstanceChargeType

Last Updated:Dec 04, 2024

Template name

ACS-ESS-LifeCycleModifyInstanceChargeType

Execute Now

Template description

Uses a lifecycle hook to change the billing method of instances.

Template type

Automated

Owner

Alibaba Cloud

Input parameters

Parameter

Description

Data type

Required

Default value

Limit

instanceChargeType

The new billing method of the instances.

String

No

PostPaid

periodUnit

The unit of the renewal duration of the instances.

String

No

Month

period

The renewal duration.

Number

No

1

includeDataDisks

Specifies whether to change the billing method of data disks that are attached to the instances.

Boolean

No

False

networkChargeType

The new network billing method of the instances.

String

No

PayByTraffic

lifecycleActionResult

The action to be taken after the lifecycle hook is disabled.

String

No

ABANDON

regionId

The region ID.

String

No

${regionId}

instanceIds

The list of Elastic Compute Service (ECS) instance IDs.

List

No

['${instanceIds}']

lifecycleHookId

The lifecycle hook ID.

String

No

${lifecycleHookId}

rateControl

The rate control settings.

Json

No

{'Mode': 'Concurrency', 'MaxErrors': 0, 'Concurrency': 10}

lifecycleActionToken

The token of a specific scaling activity that is associated with the instances.

String

No

${lifecycleActionToken}

OOSAssumeRole

The RAM role that is assumed by CloudOps Orchestration Service (OOS).

String

No

""

Output parameters

N/A.

Permission policy that is required to execute the template

{
    "Version": "1",
    "Statement": [
        {
            "Action": [
                "ecs:DescribeInstances",
                "ecs:ModifyInstanceChargeType",
                "ecs:ModifyInstanceNetworkSpec"
            ],
            "Resource": "*",
            "Effect": "Allow"
        },
        {
            "Action": [
                "ess:CompleteLifecycleAction"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}

References

ACS-ESS-LifeCycleModifyInstanceChargeType

Template content

FormatVersion: OOS-2019-06-01
Description:
  en: Use lifecycleHook to modify instance charge type in the specified scaling activity
  name-en: ACS-ESS-LifeCycleModifyInstanceChargeType 
  categories:
    - elastic_manage
Parameters:
  instanceChargeType:
    Label:
      en: InstanceChargeType
    Type: String
    AllowedValues:
      - PostPaid
      - PrePaid
    Default: PostPaid
  periodUnit:
    Label:
      en: PeriodUnit
    Type: String
    AllowedValues:
      - Week
      - Month
    Default: Month
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${instanceChargeType}
              - PostPaid
  period:
    Description:
      en: The period of the instance
    Label:
      en: Period
    Type: Number
    Default: 1
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${instanceChargeType}
              - PostPaid
  includeDataDisks:
    Description:
      en: Specifies whether to change the billing method of all data disks attached to the instance from pay-as-you-go to subscription
    Label:
      en: IncludeDataDisks 
    Type: Boolean
    Default: false
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${instanceChargeType}
              - PostPaid
  networkChargeType:
    Label:
      en: NetworkChargeType
    Type: String
    AllowedValues:
      - PayByBandwidth
      - PayByTraffic
    Default: PayByTraffic
  lifecycleActionResult:
    Label:
      en: LifecycleActionResult
    Description:
      en: After the command execution fails, the lifecycle hook waits for the next action after the state ends
    Type: String
    AllowedValues:
      - ABANDON
      - ROLLBACK
      - CONTINUE
    Default: ABANDON
  regionId:
    Label:
      en: RegionId
    Description:
      en: The ID of region
    Type: String
    Default: ${regionId}
  instanceIds:
    Label:
      en: InstanceIds
    Description:
      en: The ID list of the ECS instance
    Type: List
    Default:
      - ${instanceIds}
  lifecycleHookId:
    Label:
      en: LifecycleHookId 
    Description:
      en: The ID of the lifecycle hook
    Type: String
    Default: ${lifecycleHookId}
  rateControl:
    Label:
      en: RateControl
    Type: Json
    AssociationProperty: RateControl
    Default:
      Mode: Concurrency
      MaxErrors: 0
      Concurrency: 10
  lifecycleActionToken:
    Label:
      en: LifecycleActionToken
    Description:
      en: The token that indicates a specific scaling activity associated with an instance
    Type: String
    Default: ${lifecycleActionToken}
  OOSAssumeRole:
    Label:
      en: OOSAssumeRole
    Type: String
    Default: ''
RamRole: '{{ OOSAssumeRole }}'
Tasks:
  - Name: sleepTask
    Action: ACS::Sleep
    Properties:
      Duration: 10s
  - Name: modifyInstanceChargeType
    OnError: CompleteLifecycleActionForAbandon
    OnSuccess: CompleteLifecycleActionForContinue
    Description:
      en: Modify instance charge type
    Action: ACS::ECS::ModifyInstanceChargeType
    Properties:
      regionId: '{{ regionId }}'
      instanceId: '{{ ACS::TaskLoopItem }}'
      instanceChargeType: '{{ instanceChargeType }}'
      networkChargeType: '{{ networkChargeType }}'
      period: '{{ period }}'
      periodUnit: '{{ periodUnit }}'
      includeDataDisks: '{{ includeDataDisks }}'
    Loop:
      Items: '{{ instanceIds }}'
      RateControl: '{{ rateControl }}'
  - Name: CompleteLifecycleActionForContinue
    Action: ACS::ExecuteAPI
    Description:
      en: Modify lifecycle action for continue
    OnSuccess: ACS::END
    Properties:
      Service: ESS
      API: CompleteLifecycleAction
      Parameters:
        RegionId: '{{ regionId }}'
        LifecycleHookId: '{{ lifecycleHookId }}'
        LifecycleActionToken: '{{ lifecycleActionToken }}'
        LifecycleActionResult: CONTINUE
  - Name: CompleteLifecycleActionForAbandon
    Action: ACS::ExecuteAPI
    Description:
      en: Complete lifecycle action for Abandon 
    Properties:
      Service: ESS
      API: CompleteLifecycleAction
      Parameters:
        RegionId: '{{ regionId }}'
        LifecycleHookId: '{{ lifecycleHookId }}'
        LifecycleActionToken: '{{ lifecycleActionToken }}'
        LifecycleActionResult: '{{ lifecycleActionResult }}'