Class StackInstances


  • public class StackInstances
    extends com.pulumi.resources.CustomResource
    Manages CloudFormation stack instances for the specified accounts, within the specified regions. A stack instance refers to a stack in a specific account and region. Additional information about stacks can be found in the [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacks.html). > **NOTE:** This resource will manage all stack instances for the specified `stackSetName`. If you create stack instances outside of Terraform or import existing infrastructure, ensure that your configuration includes all accounts and regions where stack instances exist for the stack set. Failing to include all accounts and regions will cause Terraform to continuously report differences between your configuration and the actual infrastructure. > **NOTE:** All target accounts must have an IAM Role created that matches the name of the execution role configured in the stack (the `executionRoleName` argument in the `aws.cloudformation.StackSet` resource) in a trust relationship with the administrative account or administration IAM Role. The execution role must have appropriate permissions to manage resources defined in the template along with those required for stacks to operate. See the [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs.html) for more details. > **NOTE:** To retain the Stack during Terraform resource destroy, ensure `retainStacks = true` has been successfully applied into the Terraform state first. This must be completed _before_ an apply that would destroy the resource. ## Example Usage ### Basic Usage
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.cloudformation.StackInstances;
     import com.pulumi.aws.cloudformation.StackInstancesArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             var example = new StackInstances("example", StackInstancesArgs.builder()
                 .accounts(            
                     "123456789012",
                     "234567890123")
                 .regions(            
                     "us-east-1",
                     "us-west-2")
                 .stackSetName(exampleAwsCloudformationStackSet.name())
                 .build());
     
         }
     }
     
     
    ### Example IAM Setup in Target Account
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.iam.IamFunctions;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementArgs;
     import com.pulumi.aws.iam.inputs.GetPolicyDocumentStatementPrincipalArgs;
     import com.pulumi.aws.iam.Role;
     import com.pulumi.aws.iam.RoleArgs;
     import com.pulumi.aws.iam.RolePolicy;
     import com.pulumi.aws.iam.RolePolicyArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             final var aWSCloudFormationStackSetExecutionRoleAssumeRolePolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                 .statements(GetPolicyDocumentStatementArgs.builder()
                     .principals(GetPolicyDocumentStatementPrincipalArgs.builder()
                         .identifiers(aWSCloudFormationStackSetAdministrationRole.arn())
                         .type("AWS")
                         .build())
                     .actions("sts:AssumeRole")
                     .effect("Allow")
                     .build())
                 .build());
     
             var aWSCloudFormationStackSetExecutionRole = new Role("aWSCloudFormationStackSetExecutionRole", RoleArgs.builder()
                 .assumeRolePolicy(aWSCloudFormationStackSetExecutionRoleAssumeRolePolicy.json())
                 .name("AWSCloudFormationStackSetExecutionRole")
                 .build());
     
             // Documentation: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/stacksets-prereqs.html
             // Additional IAM permissions necessary depend on the resources defined in the StackSet template
             final var aWSCloudFormationStackSetExecutionRoleMinimumExecutionPolicy = IamFunctions.getPolicyDocument(GetPolicyDocumentArgs.builder()
                 .statements(GetPolicyDocumentStatementArgs.builder()
                     .actions(                
                         "cloudformation:*",
                         "s3:*",
                         "sns:*")
                     .effect("Allow")
                     .resources("*")
                     .build())
                 .build());
     
             var aWSCloudFormationStackSetExecutionRoleMinimumExecutionPolicyRolePolicy = new RolePolicy("aWSCloudFormationStackSetExecutionRoleMinimumExecutionPolicyRolePolicy", RolePolicyArgs.builder()
                 .name("MinimumExecutionPolicy")
                 .policy(aWSCloudFormationStackSetExecutionRoleMinimumExecutionPolicy.json())
                 .role(aWSCloudFormationStackSetExecutionRole.name())
                 .build());
     
         }
     }
     
     
    ### Example Deployment across Organizations account
     
     package generated_program;
     
     import com.pulumi.Context;
     import com.pulumi.Pulumi;
     import com.pulumi.core.Output;
     import com.pulumi.aws.cloudformation.StackInstances;
     import com.pulumi.aws.cloudformation.StackInstancesArgs;
     import com.pulumi.aws.cloudformation.inputs.StackInstancesDeploymentTargetsArgs;
     import java.util.ArrayList;
     import java.util.Arrays;
     import java.util.Map;
     import java.io.File;
     import java.nio.file.Files;
     import java.nio.file.Paths;
     
     public class App {
         public static void main(String[] args) {
             Pulumi.run(App::stack);
         }
     
         public static void stack(Context ctx) {
             var example = new StackInstances("example", StackInstancesArgs.builder()
                 .deploymentTargets(StackInstancesDeploymentTargetsArgs.builder()
                     .organizationalUnitIds(exampleAwsOrganizationsOrganization.roots()[0].id())
                     .build())
                 .regions(            
                     "us-west-2",
                     "us-east-1")
                 .stackSetName(exampleAwsCloudformationStackSet.name())
                 .build());
     
         }
     }
     
     
    ## Import Import CloudFormation stack instances that target OUs, using the stack set name, `callAs`, and "OU" separated by commas (`,`). For example: Using `pulumi import`, import CloudFormation stack instances using the stack set name and `callAs` separated by commas (`,`). If you are importing a stack instance targeting OUs, see the example below. For example: ```sh $ pulumi import aws:cloudformation/stackInstances:StackInstances example example,SELF ``` Using `pulumi import`, Import CloudFormation stack instances that target OUs, using the stack set name, `callAs`, and "OU" separated by commas (`,`). For example: ```sh $ pulumi import aws:cloudformation/stackInstances:StackInstances example example,SELF,OU ```
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pulumi.resources.CustomResource

        com.pulumi.resources.CustomResource.CustomResourceInternal
      • Nested classes/interfaces inherited from class com.pulumi.resources.Resource

        com.pulumi.resources.Resource.LazyField<T extends java.lang.Object>, com.pulumi.resources.Resource.LazyFields, com.pulumi.resources.Resource.ResourceInternal
    • Field Summary

      • Fields inherited from class com.pulumi.resources.Resource

        childResources, remote
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      com.pulumi.core.Output<java.util.List<java.lang.String>> accounts()  
      com.pulumi.core.Output<java.util.Optional<java.lang.String>> callAs()  
      com.pulumi.core.Output<java.util.Optional<StackInstancesDeploymentTargets>> deploymentTargets()  
      static StackInstances get​(java.lang.String name, com.pulumi.core.Output<java.lang.String> id, StackInstancesState state, com.pulumi.resources.CustomResourceOptions options)
      Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
      com.pulumi.core.Output<java.util.Optional<StackInstancesOperationPreferences>> operationPreferences()  
      com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>>> parameterOverrides()  
      com.pulumi.core.Output<java.lang.String> region()  
      com.pulumi.core.Output<java.util.List<java.lang.String>> regions()  
      com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> retainStacks()  
      com.pulumi.core.Output<java.util.List<StackInstancesStackInstanceSummary>> stackInstanceSummaries()  
      com.pulumi.core.Output<java.lang.String> stackSetId()  
      com.pulumi.core.Output<java.lang.String> stackSetName()  
      • Methods inherited from class com.pulumi.resources.CustomResource

        getId, id, idFuture
      • Methods inherited from class com.pulumi.resources.Resource

        getChildResources, getResourceName, getResourceType, getUrn, pulumiChildResources, pulumiResourceName, pulumiResourceType, urn
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • StackInstances

        public StackInstances​(java.lang.String name)
        Parameters:
        name - The _unique_ name of the resulting resource.
      • StackInstances

        public StackInstances​(java.lang.String name,
                              StackInstancesArgs args)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
      • StackInstances

        public StackInstances​(java.lang.String name,
                              StackInstancesArgs args,
                              @Nullable
                              com.pulumi.resources.CustomResourceOptions options)
        Parameters:
        name - The _unique_ name of the resulting resource.
        args - The arguments to use to populate this resource's properties.
        options - A bag of options that control this resource's behavior.
    • Method Detail

      • accounts

        public com.pulumi.core.Output<java.util.List<java.lang.String>> accounts()
        Returns:
        Accounts where you want to create stack instances in the specified `regions`. You can specify either `accounts` or `deploymentTargets`, but not both.
      • callAs

        public com.pulumi.core.Output<java.util.Optional<java.lang.String>> callAs()
        Returns:
        Whether you are acting as an account administrator in the organization's management account or as a delegated administrator in a member account. Valid values: `SELF` (default), `DELEGATED_ADMIN`.
      • deploymentTargets

        public com.pulumi.core.Output<java.util.Optional<StackInstancesDeploymentTargets>> deploymentTargets()
        Returns:
        AWS Organizations accounts for which to create stack instances in the `regions`. stack sets doesn't deploy stack instances to the organization management account, even if the organization management account is in your organization or in an OU in your organization. Drift detection is not possible for most of this argument. See deploymentTargets below.
      • operationPreferences

        public com.pulumi.core.Output<java.util.Optional<StackInstancesOperationPreferences>> operationPreferences()
        Returns:
        Preferences for how AWS CloudFormation performs a stack set operation. See operationPreferences below.
      • parameterOverrides

        public com.pulumi.core.Output<java.util.Optional<java.util.Map<java.lang.String,​java.lang.String>>> parameterOverrides()
        Returns:
        Key-value map of input parameters to override from the stack set for these instances. This argument's drift detection is limited to the first account and region since each instance can have unique parameters.
      • region

        public com.pulumi.core.Output<java.lang.String> region()
        Returns:
        Region where this resource will be [managed](https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints). Defaults to the Region set in the provider configuration.
      • regions

        public com.pulumi.core.Output<java.util.List<java.lang.String>> regions()
        Returns:
        Regions where you want to create stack instances in the specified `accounts`.
      • retainStacks

        public com.pulumi.core.Output<java.util.Optional<java.lang.Boolean>> retainStacks()
        Returns:
        Whether to remove the stack instances from the stack set, but not delete the stacks. You can't reassociate a retained stack or add an existing, saved stack to a new stack set. To retain the stack, ensure `retainStacks = true` has been successfully applied _before_ an apply that would destroy the resource. Defaults to `false`.
      • stackInstanceSummaries

        public com.pulumi.core.Output<java.util.List<StackInstancesStackInstanceSummary>> stackInstanceSummaries()
        Returns:
        List of stack instances created from an organizational unit deployment target. This may not always be set depending on whether CloudFormation returns summaries for your configuration. See `stackInstanceSummaries`.
      • stackSetId

        public com.pulumi.core.Output<java.lang.String> stackSetId()
        Returns:
        Name or unique ID of the stack set that the stack instance is associated with.
      • stackSetName

        public com.pulumi.core.Output<java.lang.String> stackSetName()
        Returns:
        Name of the stack set. The following arguments are optional:
      • get

        public static StackInstances get​(java.lang.String name,
                                         com.pulumi.core.Output<java.lang.String> id,
                                         @Nullable
                                         StackInstancesState state,
                                         @Nullable
                                         com.pulumi.resources.CustomResourceOptions options)
        Get an existing Host resource's state with the given name, ID, and optional extra properties used to qualify the lookup.
        Parameters:
        name - The _unique_ name of the resulting resource.
        id - The _unique_ provider ID of the resource to lookup.
        state -
        options - Optional settings to control the behavior of the CustomResource.