@@ -70,27 +70,6 @@ public static Set<Tag> convertToSet(final Map<String, String> tagMap) {
70
70
.collect (Collectors .toSet ());
71
71
}
72
72
73
- /**
74
- * generateTagsForCreate
75
- *
76
- * Generate tags to put into resource creation request.
77
- * This includes user defined tags and system tags as well.
78
- */
79
- public final Map <String , String > generateTagsForCreate (final ResourceModel resourceModel , final ResourceHandlerRequest <ResourceModel > handlerRequest ) {
80
- final Map <String , String > tagMap = new HashMap <>();
81
-
82
- // merge system tags with desired resource tags if your service supports CloudFormation system tags
83
- tagMap .putAll (handlerRequest .getSystemTags ());
84
-
85
- if (handlerRequest .getDesiredResourceTags () != null ) {
86
- tagMap .putAll (handlerRequest .getDesiredResourceTags ());
87
- }
88
-
89
- // TODO: get tags from resource model based on your tag property name
90
- // TODO: tagMap.putAll(convertToMap(resourceModel.getTags()));
91
- return Collections .unmodifiableMap (tagMap );
92
- }
93
-
94
73
/**
95
74
* shouldUpdateTags
96
75
*
@@ -106,32 +85,59 @@ public final boolean shouldUpdateTags(final ResourceModel resourceModel, final R
106
85
* getPreviouslyAttachedTags
107
86
*
108
87
* If stack tags and resource tags are not merged together in Configuration class,
109
- * we will get previous attached user defined tags from both handlerRequest.getPreviousResourceTags (stack tags)
110
- * and handlerRequest.getPreviousResourceState (resource tags).
88
+ * we will get previously attached system (with `aws:cloudformation` prefix) and user defined tags from
89
+ * handlerRequest.getPreviousSystemTags() (system tags),
90
+ * handlerRequest.getPreviousResourceTags() (stack tags),
91
+ * handlerRequest.getPreviousResourceState().getTags() (resource tags).
92
+ *
93
+ * System tags are an optional feature. Merge them to your tags if you have enabled them for your resource.
94
+ * System tags can change on resource update if the resource is imported to the stack.
111
95
*/
112
96
public Map <String , String > getPreviouslyAttachedTags (final ResourceHandlerRequest <ResourceModel > handlerRequest ) {
97
+ final Map <String , String > previousTags = new HashMap <>();
98
+
99
+ // TODO: get previous system tags if your service supports CloudFormation system tags
100
+ // if (handlerRequest.getPreviousSystemTags() != null) {
101
+ // previousTags.putAll(handlerRequest.getPreviousSystemTags());
102
+ // }
103
+
113
104
// get previous stack level tags from handlerRequest
114
- final Map <String , String > previousTags = handlerRequest .getPreviousResourceTags () != null ?
115
- handlerRequest .getPreviousResourceTags () : Collections .emptyMap ();
105
+ if (handlerRequest .getPreviousResourceTags () != null ) {
106
+ previousTags .putAll (handlerRequest .getPreviousResourceTags ());
107
+ }
116
108
117
109
// TODO: get resource level tags from previous resource state based on your tag property name
118
- // TODO: previousTags.putAll(handlerRequest.getPreviousResourceState().getTags());
110
+ // TODO: previousTags.putAll(handlerRequest.getPreviousResourceState().getTags()); // if tags are not null
119
111
return previousTags ;
120
112
}
121
113
122
114
/**
123
115
* getNewDesiredTags
124
116
*
125
117
* If stack tags and resource tags are not merged together in Configuration class,
126
- * we will get new user defined tags from both resource model and previous stack tags.
118
+ * we will get new desired system (with `aws:cloudformation` prefix) and user defined tags from
119
+ * handlerRequest.getSystemTags() (system tags),
120
+ * handlerRequest.getDesiredResourceTags() (stack tags),
121
+ * handlerRequest.getDesiredResourceState().getTags() (resource tags).
122
+ *
123
+ * System tags are an optional feature. Merge them to your tags if you have enabled them for your resource.
124
+ * System tags can change on resource update if the resource is imported to the stack.
127
125
*/
128
- public Map <String , String > getNewDesiredTags (final ResourceModel resourceModel , final ResourceHandlerRequest <ResourceModel > handlerRequest ) {
129
- // get new stack level tags from handlerRequest
130
- final Map <String , String > desiredTags = handlerRequest .getDesiredResourceTags () != null ?
131
- handlerRequest .getDesiredResourceTags () : Collections .emptyMap ();
126
+ public Map <String , String > getNewDesiredTags (final ResourceHandlerRequest <ResourceModel > handlerRequest ) {
127
+ final Map <String , String > desiredTags = new HashMap <>();
128
+
129
+ // TODO: merge system tags with desired resource tags if your service supports CloudFormation system tags
130
+ // if (handlerRequest.getSystemTags() != null) {
131
+ // desiredTags.putAll(handlerRequest.getSystemTags());
132
+ // }
133
+
134
+ // get desired stack level tags from handlerRequest
135
+ if (handlerRequest .getDesiredResourceTags () != null ) {
136
+ desiredTags .putAll (handlerRequest .getDesiredResourceTags ());
137
+ }
132
138
133
139
// TODO: get resource level tags from resource model based on your tag property name
134
- // TODO: desiredTags.putAll(convertToMap(resourceModel. getTags()));
140
+ // TODO: desiredTags.putAll(convertToMap(handlerRequest.getDesiredResourceState(). getTags())); // if tags are not null
135
141
return desiredTags ;
136
142
}
137
143
0 commit comments