software.amazon.awssdk.services.cloudformation.model.StackResourceDrift Maven / Gradle / Ivy
Show all versions of cloudformation Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.cloudformation.model;
import java.io.Serializable;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Contains the drift information for a resource that has been checked for drift. This includes actual and expected
* property values for resources in which CloudFormation has detected drift. Only resource properties explicitly defined
* in the stack template are checked for drift. For more information, see Detecting
* Unregulated Configuration Changes to Stacks and Resources.
*
*
* Resources that don't currently support drift detection can't be checked. For a list of resources that support drift
* detection, see Resources that Support Drift Detection.
*
*
* Use DetectStackResourceDrift to detect drift on individual resources, or DetectStackDrift to detect
* drift on all resources in a given stack that support drift detection.
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class StackResourceDrift implements SdkPojo, Serializable,
ToCopyableBuilder {
private static final SdkField STACK_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("StackId").getter(getter(StackResourceDrift::stackId)).setter(setter(Builder::stackId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StackId").build()).build();
private static final SdkField LOGICAL_RESOURCE_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("LogicalResourceId").getter(getter(StackResourceDrift::logicalResourceId))
.setter(setter(Builder::logicalResourceId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LogicalResourceId").build()).build();
private static final SdkField PHYSICAL_RESOURCE_ID_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("PhysicalResourceId").getter(getter(StackResourceDrift::physicalResourceId))
.setter(setter(Builder::physicalResourceId))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PhysicalResourceId").build())
.build();
private static final SdkField> PHYSICAL_RESOURCE_ID_CONTEXT_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("PhysicalResourceIdContext")
.getter(getter(StackResourceDrift::physicalResourceIdContext))
.setter(setter(Builder::physicalResourceIdContext))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PhysicalResourceIdContext").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(PhysicalResourceIdContextKeyValuePair::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField RESOURCE_TYPE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ResourceType").getter(getter(StackResourceDrift::resourceType)).setter(setter(Builder::resourceType))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ResourceType").build()).build();
private static final SdkField EXPECTED_PROPERTIES_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ExpectedProperties").getter(getter(StackResourceDrift::expectedProperties))
.setter(setter(Builder::expectedProperties))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExpectedProperties").build())
.build();
private static final SdkField ACTUAL_PROPERTIES_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("ActualProperties").getter(getter(StackResourceDrift::actualProperties))
.setter(setter(Builder::actualProperties))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ActualProperties").build()).build();
private static final SdkField> PROPERTY_DIFFERENCES_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("PropertyDifferences")
.getter(getter(StackResourceDrift::propertyDifferences))
.setter(setter(Builder::propertyDifferences))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PropertyDifferences").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(PropertyDifference::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField STACK_RESOURCE_DRIFT_STATUS_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("StackResourceDriftStatus").getter(getter(StackResourceDrift::stackResourceDriftStatusAsString))
.setter(setter(Builder::stackResourceDriftStatus))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StackResourceDriftStatus").build())
.build();
private static final SdkField TIMESTAMP_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("Timestamp").getter(getter(StackResourceDrift::timestamp)).setter(setter(Builder::timestamp))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Timestamp").build()).build();
private static final SdkField MODULE_INFO_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.memberName("ModuleInfo").getter(getter(StackResourceDrift::moduleInfo)).setter(setter(Builder::moduleInfo))
.constructor(ModuleInfo::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ModuleInfo").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(STACK_ID_FIELD,
LOGICAL_RESOURCE_ID_FIELD, PHYSICAL_RESOURCE_ID_FIELD, PHYSICAL_RESOURCE_ID_CONTEXT_FIELD, RESOURCE_TYPE_FIELD,
EXPECTED_PROPERTIES_FIELD, ACTUAL_PROPERTIES_FIELD, PROPERTY_DIFFERENCES_FIELD, STACK_RESOURCE_DRIFT_STATUS_FIELD,
TIMESTAMP_FIELD, MODULE_INFO_FIELD));
private static final long serialVersionUID = 1L;
private final String stackId;
private final String logicalResourceId;
private final String physicalResourceId;
private final List physicalResourceIdContext;
private final String resourceType;
private final String expectedProperties;
private final String actualProperties;
private final List propertyDifferences;
private final String stackResourceDriftStatus;
private final Instant timestamp;
private final ModuleInfo moduleInfo;
private StackResourceDrift(BuilderImpl builder) {
this.stackId = builder.stackId;
this.logicalResourceId = builder.logicalResourceId;
this.physicalResourceId = builder.physicalResourceId;
this.physicalResourceIdContext = builder.physicalResourceIdContext;
this.resourceType = builder.resourceType;
this.expectedProperties = builder.expectedProperties;
this.actualProperties = builder.actualProperties;
this.propertyDifferences = builder.propertyDifferences;
this.stackResourceDriftStatus = builder.stackResourceDriftStatus;
this.timestamp = builder.timestamp;
this.moduleInfo = builder.moduleInfo;
}
/**
*
* The ID of the stack.
*
*
* @return The ID of the stack.
*/
public final String stackId() {
return stackId;
}
/**
*
* The logical name of the resource specified in the template.
*
*
* @return The logical name of the resource specified in the template.
*/
public final String logicalResourceId() {
return logicalResourceId;
}
/**
*
* The name or unique identifier that corresponds to a physical instance ID of a resource supported by
* CloudFormation.
*
*
* @return The name or unique identifier that corresponds to a physical instance ID of a resource supported by
* CloudFormation.
*/
public final String physicalResourceId() {
return physicalResourceId;
}
/**
* For responses, this returns true if the service returned a value for the PhysicalResourceIdContext property. This
* DOES NOT check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the
* property). This is useful because the SDK will never return a null collection or map, but you may need to
* differentiate between the service returning nothing (or null) and the service returning an empty collection or
* map. For requests, this returns true if a value for the property was specified in the request builder, and false
* if a value was not specified.
*/
public final boolean hasPhysicalResourceIdContext() {
return physicalResourceIdContext != null && !(physicalResourceIdContext instanceof SdkAutoConstructList);
}
/**
*
* Context information that enables CloudFormation to uniquely identify a resource. CloudFormation uses context
* key-value pairs in cases where a resource's logical and physical IDs aren't enough to uniquely identify that
* resource. Each context key-value pair specifies a unique resource that contains the targeted resource.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasPhysicalResourceIdContext} method.
*
*
* @return Context information that enables CloudFormation to uniquely identify a resource. CloudFormation uses
* context key-value pairs in cases where a resource's logical and physical IDs aren't enough to uniquely
* identify that resource. Each context key-value pair specifies a unique resource that contains the
* targeted resource.
*/
public final List physicalResourceIdContext() {
return physicalResourceIdContext;
}
/**
*
* The type of the resource.
*
*
* @return The type of the resource.
*/
public final String resourceType() {
return resourceType;
}
/**
*
* A JSON structure containing the expected property values of the stack resource, as defined in the stack template
* and any values specified as template parameters.
*
*
* For resources whose StackResourceDriftStatus
is DELETED
, this structure will not be
* present.
*
*
* @return A JSON structure containing the expected property values of the stack resource, as defined in the stack
* template and any values specified as template parameters.
*
* For resources whose StackResourceDriftStatus
is DELETED
, this structure will
* not be present.
*/
public final String expectedProperties() {
return expectedProperties;
}
/**
*
* A JSON structure containing the actual property values of the stack resource.
*
*
* For resources whose StackResourceDriftStatus
is DELETED
, this structure will not be
* present.
*
*
* @return A JSON structure containing the actual property values of the stack resource.
*
* For resources whose StackResourceDriftStatus
is DELETED
, this structure will
* not be present.
*/
public final String actualProperties() {
return actualProperties;
}
/**
* For responses, this returns true if the service returned a value for the PropertyDifferences property. This DOES
* NOT check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasPropertyDifferences() {
return propertyDifferences != null && !(propertyDifferences instanceof SdkAutoConstructList);
}
/**
*
* A collection of the resource properties whose actual values differ from their expected values. These will be
* present only for resources whose StackResourceDriftStatus
is MODIFIED
.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasPropertyDifferences} method.
*
*
* @return A collection of the resource properties whose actual values differ from their expected values. These will
* be present only for resources whose StackResourceDriftStatus
is MODIFIED
.
*/
public final List propertyDifferences() {
return propertyDifferences;
}
/**
*
* Status of the resource's actual configuration compared to its expected configuration.
*
*
* -
*
* DELETED
: The resource differs from its expected template configuration because the resource has been
* deleted.
*
*
* -
*
* MODIFIED
: One or more resource properties differ from their expected values (as defined in the stack
* template and any values specified as template parameters).
*
*
* -
*
* IN_SYNC
: The resource's actual configuration matches its expected template configuration.
*
*
* -
*
* NOT_CHECKED
: CloudFormation does not currently return this value.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #stackResourceDriftStatus} will return {@link StackResourceDriftStatus#UNKNOWN_TO_SDK_VERSION}. The raw
* value returned by the service is available from {@link #stackResourceDriftStatusAsString}.
*
*
* @return Status of the resource's actual configuration compared to its expected configuration.
*
* -
*
* DELETED
: The resource differs from its expected template configuration because the resource
* has been deleted.
*
*
* -
*
* MODIFIED
: One or more resource properties differ from their expected values (as defined in
* the stack template and any values specified as template parameters).
*
*
* -
*
* IN_SYNC
: The resource's actual configuration matches its expected template configuration.
*
*
* -
*
* NOT_CHECKED
: CloudFormation does not currently return this value.
*
*
* @see StackResourceDriftStatus
*/
public final StackResourceDriftStatus stackResourceDriftStatus() {
return StackResourceDriftStatus.fromValue(stackResourceDriftStatus);
}
/**
*
* Status of the resource's actual configuration compared to its expected configuration.
*
*
* -
*
* DELETED
: The resource differs from its expected template configuration because the resource has been
* deleted.
*
*
* -
*
* MODIFIED
: One or more resource properties differ from their expected values (as defined in the stack
* template and any values specified as template parameters).
*
*
* -
*
* IN_SYNC
: The resource's actual configuration matches its expected template configuration.
*
*
* -
*
* NOT_CHECKED
: CloudFormation does not currently return this value.
*
*
*
*
* If the service returns an enum value that is not available in the current SDK version,
* {@link #stackResourceDriftStatus} will return {@link StackResourceDriftStatus#UNKNOWN_TO_SDK_VERSION}. The raw
* value returned by the service is available from {@link #stackResourceDriftStatusAsString}.
*
*
* @return Status of the resource's actual configuration compared to its expected configuration.
*
* -
*
* DELETED
: The resource differs from its expected template configuration because the resource
* has been deleted.
*
*
* -
*
* MODIFIED
: One or more resource properties differ from their expected values (as defined in
* the stack template and any values specified as template parameters).
*
*
* -
*
* IN_SYNC
: The resource's actual configuration matches its expected template configuration.
*
*
* -
*
* NOT_CHECKED
: CloudFormation does not currently return this value.
*
*
* @see StackResourceDriftStatus
*/
public final String stackResourceDriftStatusAsString() {
return stackResourceDriftStatus;
}
/**
*
* Time at which CloudFormation performed drift detection on the stack resource.
*
*
* @return Time at which CloudFormation performed drift detection on the stack resource.
*/
public final Instant timestamp() {
return timestamp;
}
/**
*
* Contains information about the module from which the resource was created, if the resource was created from a
* module included in the stack template.
*
*
* @return Contains information about the module from which the resource was created, if the resource was created
* from a module included in the stack template.
*/
public final ModuleInfo moduleInfo() {
return moduleInfo;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(stackId());
hashCode = 31 * hashCode + Objects.hashCode(logicalResourceId());
hashCode = 31 * hashCode + Objects.hashCode(physicalResourceId());
hashCode = 31 * hashCode + Objects.hashCode(hasPhysicalResourceIdContext() ? physicalResourceIdContext() : null);
hashCode = 31 * hashCode + Objects.hashCode(resourceType());
hashCode = 31 * hashCode + Objects.hashCode(expectedProperties());
hashCode = 31 * hashCode + Objects.hashCode(actualProperties());
hashCode = 31 * hashCode + Objects.hashCode(hasPropertyDifferences() ? propertyDifferences() : null);
hashCode = 31 * hashCode + Objects.hashCode(stackResourceDriftStatusAsString());
hashCode = 31 * hashCode + Objects.hashCode(timestamp());
hashCode = 31 * hashCode + Objects.hashCode(moduleInfo());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof StackResourceDrift)) {
return false;
}
StackResourceDrift other = (StackResourceDrift) obj;
return Objects.equals(stackId(), other.stackId()) && Objects.equals(logicalResourceId(), other.logicalResourceId())
&& Objects.equals(physicalResourceId(), other.physicalResourceId())
&& hasPhysicalResourceIdContext() == other.hasPhysicalResourceIdContext()
&& Objects.equals(physicalResourceIdContext(), other.physicalResourceIdContext())
&& Objects.equals(resourceType(), other.resourceType())
&& Objects.equals(expectedProperties(), other.expectedProperties())
&& Objects.equals(actualProperties(), other.actualProperties())
&& hasPropertyDifferences() == other.hasPropertyDifferences()
&& Objects.equals(propertyDifferences(), other.propertyDifferences())
&& Objects.equals(stackResourceDriftStatusAsString(), other.stackResourceDriftStatusAsString())
&& Objects.equals(timestamp(), other.timestamp()) && Objects.equals(moduleInfo(), other.moduleInfo());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("StackResourceDrift").add("StackId", stackId()).add("LogicalResourceId", logicalResourceId())
.add("PhysicalResourceId", physicalResourceId())
.add("PhysicalResourceIdContext", hasPhysicalResourceIdContext() ? physicalResourceIdContext() : null)
.add("ResourceType", resourceType()).add("ExpectedProperties", expectedProperties())
.add("ActualProperties", actualProperties())
.add("PropertyDifferences", hasPropertyDifferences() ? propertyDifferences() : null)
.add("StackResourceDriftStatus", stackResourceDriftStatusAsString()).add("Timestamp", timestamp())
.add("ModuleInfo", moduleInfo()).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "StackId":
return Optional.ofNullable(clazz.cast(stackId()));
case "LogicalResourceId":
return Optional.ofNullable(clazz.cast(logicalResourceId()));
case "PhysicalResourceId":
return Optional.ofNullable(clazz.cast(physicalResourceId()));
case "PhysicalResourceIdContext":
return Optional.ofNullable(clazz.cast(physicalResourceIdContext()));
case "ResourceType":
return Optional.ofNullable(clazz.cast(resourceType()));
case "ExpectedProperties":
return Optional.ofNullable(clazz.cast(expectedProperties()));
case "ActualProperties":
return Optional.ofNullable(clazz.cast(actualProperties()));
case "PropertyDifferences":
return Optional.ofNullable(clazz.cast(propertyDifferences()));
case "StackResourceDriftStatus":
return Optional.ofNullable(clazz.cast(stackResourceDriftStatusAsString()));
case "Timestamp":
return Optional.ofNullable(clazz.cast(timestamp()));
case "ModuleInfo":
return Optional.ofNullable(clazz.cast(moduleInfo()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function