1. Docs
  2. Infrastructure as Code
  3. Concepts
  4. Resources
  5. Resource options
  6. replacementTrigger

Resource option: replacementTrigger

    The replacementTrigger resource option forces a replacement operation on a resource whenever a specified trigger value changes. This is useful when you need to replace resources on a schedule or in response to external events that aren’t captured by the resource’s properties.

    For example, you might want to rotate cryptographic keys monthly by using a YYYY-MM string as the trigger, or synchronize infrastructure updates with application releases by using a version number. Unlike replaceOnChanges, which triggers replacements based on resource property changes, replacementTrigger allows you to control replacement timing based on arbitrary values.

    const today = new Date()
    
    const keyManager = new KeyManagerResource("key-manager", {}, {
      replacementTrigger: today.getMonth() + '-' + today.getFullYear()
    });
    
    import datetime
    
    today = datetime.now()
    trigger = f"{today.month}-{today.year}"
    
    key_manager = KeyManagerResource("key-manager", {},
        opts=pulumi.ResourceOptions(replacement_trigger=trigger))
    
    today := time.Now()
    trigger := fmt.Sprintf("%d-%d", int(today.Month()), today.Year())
    
    keyManager, err := NewKeyManagerResource(ctx, "key-manager", &KeyManagerResourceArgs{},
        pulumi.ReplacementTrigger(pulumi.Any(trigger)))
    
    var today = LocalDate.now();
    var trigger = String.format("%d-%d", today.getMonthValue(), today.getYear());
    
    var keyManager = new KeyManagerResource("key-manager",
        KeyManagerResourceArgs.Empty,
        CustomResourceOptions.builder()
            .replacementTrigger(Output.of(trigger))
            .build());
    
    var today = DateTime.Now;
    var trigger = $"{today.Month}-{today.Year}";
    
    var keyManager = new KeyManagerResource("key-manager", new KeyManagerResourceArgs(),
        new CustomResourceOptions
        {
            ReplacementTrigger = Output.Create(trigger)
        });
    

    configuration: rotationPeriod: type: string default: “01-2026”

    resources: keyManager: type: example:components:KeyManager options: replacementTrigger: ${rotationPeriod}

    During each deploy, the value is checked against the previous value of the trigger, and if they don’t match, the resource will be marked for replacement. Note that, if either the previous value or the current value is null, a replacement operation will not be forced. This means that adding or removing a replacement trigger from a resource will not trigger a replacement - only changing a pre-existing trigger value.
      Neo just got smarter about infrastructure policy automation