Skip to content

Commit 08cd306

Browse files
committed
Add cloudformation service method
1 parent 046c5e7 commit 08cd306

File tree

3 files changed

+396
-21
lines changed

3 files changed

+396
-21
lines changed

app/domain/model/cloudformation.go

+174
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import "time"
55
const (
66
// CloudFormationRetryMaxAttempts is the maximum number of retries for CloudFormation.
77
CloudFormationRetryMaxAttempts int = 2
8+
// CloudFormationWaitNanoSecTime is the time to wait for CloudFormation.
9+
// It is 1 hour.
10+
CloudFormationWaitNanoSecTime = time.Duration(6000000000000000)
811
)
912

1013
// StackStatus is the status of a CloudFormation stack.
@@ -84,3 +87,174 @@ type Stack struct {
8487
// TemplateDescription is the template description of the template used to create the stack.
8588
TemplateDescription *string
8689
}
90+
91+
// ResourceStatus is the status of a CloudFormation stack resource.
92+
type ResourceStatus string
93+
94+
const (
95+
// ResourceStatusCreateInProgress is the resource is being created.
96+
ResourceStatusCreateInProgress ResourceStatus = "CREATE_IN_PROGRESS"
97+
// ResourceStatusCreateFailed is the resource creation failed.
98+
ResourceStatusCreateFailed ResourceStatus = "CREATE_FAILED"
99+
// ResourceStatusCreateComplete is the resource has been created.
100+
ResourceStatusCreateComplete ResourceStatus = "CREATE_COMPLETE"
101+
// ResourceStatusDeleteInProgress is the resource is being deleted.
102+
ResourceStatusDeleteInProgress ResourceStatus = "DELETE_IN_PROGRESS"
103+
// ResourceStatusDeleteFailed is the resource deletion failed.
104+
ResourceStatusDeleteFailed ResourceStatus = "DELETE_FAILED"
105+
// ResourceStatusDeleteComplete is the resource has been deleted.
106+
ResourceStatusDeleteComplete ResourceStatus = "DELETE_COMPLETE"
107+
// ResourceStatusDeleteSkipped is the resource was not successfully deleted. It might still be
108+
ResourceStatusDeleteSkipped ResourceStatus = "DELETE_SKIPPED"
109+
// ResourceStatusUpdateInProgress is the resource is being updated.
110+
ResourceStatusUpdateInProgress ResourceStatus = "UPDATE_IN_PROGRESS"
111+
// ResourceStatusUpdateFailed is the resource update failed.
112+
ResourceStatusUpdateFailed ResourceStatus = "UPDATE_FAILED"
113+
// ResourceStatusUpdateComplete is the resource has been updated.
114+
ResourceStatusUpdateComplete ResourceStatus = "UPDATE_COMPLETE"
115+
// ResourceStatusImportFailed is the resource import failed.
116+
ResourceStatusImportFailed ResourceStatus = "IMPORT_FAILED"
117+
// ResourceStatusImportComplete is the resource has been imported.
118+
ResourceStatusImportComplete ResourceStatus = "IMPORT_COMPLETE"
119+
// ResourceStatusImportInProgress is the resource is being imported into a stack.
120+
ResourceStatusImportInProgress ResourceStatus = "IMPORT_IN_PROGRESS"
121+
// ResourceStatusImportRollbackInProgress is the resource is being rolled back to its previous
122+
ResourceStatusImportRollbackInProgress ResourceStatus = "IMPORT_ROLLBACK_IN_PROGRESS"
123+
// ResourceStatusImportRollbackFailed is the resource import failed and the resource is
124+
ResourceStatusImportRollbackFailed ResourceStatus = "IMPORT_ROLLBACK_FAILED"
125+
// ResourceStatusImportRollbackComplete is the resource was rolled back to its previous
126+
ResourceStatusImportRollbackComplete ResourceStatus = "IMPORT_ROLLBACK_COMPLETE"
127+
// ResourceStatusUpdateRollbackInProgress is the resource is being rolled back as part of a
128+
ResourceStatusUpdateRollbackInProgress ResourceStatus = "UPDATE_ROLLBACK_IN_PROGRESS"
129+
// ResourceStatusUpdateRollbackComplete is the resource was rolled back to its previous
130+
ResourceStatusUpdateRollbackComplete ResourceStatus = "UPDATE_ROLLBACK_COMPLETE"
131+
// ResourceStatusUpdateRollbackFailed is the resource update failed and the resource is being rolled back to its previous configuration.
132+
ResourceStatusUpdateRollbackFailed ResourceStatus = "UPDATE_ROLLBACK_FAILED"
133+
// ResourceStatusRollbackInProgress is the resource is being rolled back.
134+
ResourceStatusRollbackInProgress ResourceStatus = "ROLLBACK_IN_PROGRESS"
135+
// ResourceStatusRollbackComplete is the resource was rolled back.
136+
ResourceStatusRollbackComplete ResourceStatus = "ROLLBACK_COMPLETE"
137+
// ResourceStatusRollbackFailed is the resource rollback failed.
138+
ResourceStatusRollbackFailed ResourceStatus = "ROLLBACK_FAILED"
139+
)
140+
141+
// Values returns all known values for ResourceStatus. Note that this can be
142+
// expanded in the future, and so it is only as up to date as the client. The
143+
// ordering of this slice is not guaranteed to be stable across updates.
144+
func (ResourceStatus) Values() []ResourceStatus {
145+
return []ResourceStatus{
146+
ResourceStatusCreateInProgress,
147+
ResourceStatusCreateFailed,
148+
ResourceStatusCreateComplete,
149+
ResourceStatusDeleteInProgress,
150+
ResourceStatusDeleteFailed,
151+
ResourceStatusDeleteComplete,
152+
ResourceStatusDeleteSkipped,
153+
ResourceStatusUpdateInProgress,
154+
ResourceStatusUpdateFailed,
155+
ResourceStatusUpdateComplete,
156+
ResourceStatusImportFailed,
157+
ResourceStatusImportComplete,
158+
ResourceStatusImportInProgress,
159+
ResourceStatusImportRollbackInProgress,
160+
ResourceStatusImportRollbackFailed,
161+
ResourceStatusImportRollbackComplete,
162+
ResourceStatusUpdateRollbackInProgress,
163+
ResourceStatusUpdateRollbackComplete,
164+
ResourceStatusUpdateRollbackFailed,
165+
ResourceStatusRollbackInProgress,
166+
ResourceStatusRollbackComplete,
167+
ResourceStatusRollbackFailed,
168+
}
169+
}
170+
171+
// StackResourceDriftStatus is status of the resource's actual configuration
172+
type StackResourceDriftStatus string
173+
174+
const (
175+
// StackResourceDriftStatusInSync is the resource's actual configuration matches its expected
176+
StackResourceDriftStatusInSync StackResourceDriftStatus = "IN_SYNC"
177+
// StackResourceDriftStatusModified is the resource differs from its expected configuration.
178+
StackResourceDriftStatusModified StackResourceDriftStatus = "MODIFIED"
179+
// StackResourceDriftStatusDeleted is the resource differs from its expected configuration in that it has been deleted.
180+
StackResourceDriftStatusDeleted StackResourceDriftStatus = "DELETED"
181+
// StackResourceDriftStatusNotChecked is CloudFormation hasn't checked if the resource differs from its expected configuration.
182+
StackResourceDriftStatusNotChecked StackResourceDriftStatus = "NOT_CHECKED"
183+
)
184+
185+
// Values returns all known values for StackResourceDriftStatus. Note that this
186+
// can be expanded in the future, and so it is only as up to date as the client.
187+
// The ordering of this slice is not guaranteed to be stable across updates.
188+
func (StackResourceDriftStatus) Values() []StackResourceDriftStatus {
189+
return []StackResourceDriftStatus{
190+
StackResourceDriftStatusInSync,
191+
StackResourceDriftStatusModified,
192+
StackResourceDriftStatusDeleted,
193+
StackResourceDriftStatusNotChecked,
194+
}
195+
}
196+
197+
// StackResourceDriftInformationSummary is summarizes information about whether
198+
// the resource's actual configuration differs, or has drifted, from its expected configuration.
199+
type StackResourceDriftInformationSummary struct {
200+
// StackResourceDriftStatus is status of the resource's actual
201+
// configuration compared to its expected configuration.
202+
StackResourceDriftStatus StackResourceDriftStatus
203+
// LastCheckTimestamp is when CloudFormation last checked if the
204+
// resource had drifted from its expected configuration.
205+
LastCheckTimestamp *time.Time
206+
}
207+
208+
// ModuleInfo is contains information about the module from which the resource
209+
// was created, if the resource was created from a module included in the stack
210+
// template. For more information about modules, see Using modules to encapsulate
211+
// and reuse resource configurations (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/modules.html)
212+
// in the CloudFormation User Guide.
213+
type ModuleInfo struct {
214+
// LogicalIDHierarchy is a concatenated list of the logical IDs of the module
215+
// or modules containing the resource. Modules are listed starting with the
216+
// inner-most nested module, and separated by / .
217+
// In the following example, the resource was created from a module, moduleA,
218+
// that's nested inside a parent module, moduleB . moduleA/moduleB For more
219+
// information, see Referencing resources in a module
220+
// (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/modules.html#module-ref-resources)
221+
// in the CloudFormation User Guide.
222+
LogicalIDHierarchy *string
223+
// TypeHierarchy is a concatenated list of the module type or types containing
224+
// the resource. Module types are listed starting with the inner-most nested
225+
// module, and separated by /.
226+
// In the following example, the resource was created from a module of type
227+
// AWS::First::Example::MODULE , that's nested inside a parent module of type
228+
// AWS::Second::Example::MODULE .
229+
// AWS::First::Example::MODULE/AWS::Second::Example::MODULE
230+
TypeHierarchy *string
231+
}
232+
233+
// StackResource is a CloudFormation stack resource. It is same as types.StackResourceSummary.
234+
type StackResource struct {
235+
// LastUpdatedTimestamp is time the status was updated.
236+
LastUpdatedTimestamp *time.Time
237+
// LogicalResourceID is the logical name of the resource specified in the template.
238+
LogicalResourceID *string
239+
// ResourceStatus is current status of the resource.
240+
ResourceStatus ResourceStatus
241+
// ResourceType is type of resource. For more information, go to Amazon Web Services Resource
242+
// Types Reference (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-template-resource-type-ref.html)
243+
// in the CloudFormation User Guide.
244+
ResourceType *string
245+
// DriftInformation is information about whether the resource's actual
246+
// configuration differs, or has drifted, from its expected configuration,
247+
// as defined in the stack template and any values specified as template
248+
// parameters. For more information, see Detecting Unregulated Configuration
249+
// Changes to Stacks and Resources
250+
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-stack-drift.html
251+
DriftInformation *StackResourceDriftInformationSummary
252+
// ModuleInfo is contains information about the module from which the resource was created, if
253+
// the resource was created from a module included in the stack template.
254+
ModuleInfo *ModuleInfo
255+
// PhysicalResourceID is the name or unique identifier that corresponds to a
256+
// physical instance ID of the resource.
257+
PhysicalResourceID *string
258+
// ResourceStatusReason is success/failure message associated with the resource.
259+
ResourceStatusReason *string
260+
}

app/domain/service/cloudformation.go

+57-7
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,66 @@ import (
66
"github.com/nao1215/rainbow/app/domain/model"
77
)
88

9-
// CloudFormationStackListerInput is the input of the CloudFormationStackLister method.
10-
type CloudFormationStackListerInput struct{}
9+
// CFnStackListerInput is the input of the CFnStackLister method.
10+
type CFnStackListerInput struct{}
1111

12-
// CloudFormationStackListerOutput is the output of the CloudFormationStackLister method.
13-
type CloudFormationStackListerOutput struct {
12+
// CFnStackListerOutput is the output of the CFnStackLister method.
13+
type CFnStackListerOutput struct {
1414
// Stacks is a list of CloudFormation stacks.
1515
Stacks []*model.Stack
1616
}
1717

18-
// CloudFormationStackLister is the interface that wraps the basic CloudFormationStackLister method.
19-
type CloudFormationStackLister interface {
20-
CloudFormationStackLister(ctx context.Context, input *CloudFormationStackListerInput) (*CloudFormationStackListerOutput, error)
18+
// CFnStackLister is the interface that wraps the basic CFnStackLister method.
19+
type CFnStackLister interface {
20+
CFnStackLister(ctx context.Context, input *CFnStackListerInput) (*CFnStackListerOutput, error)
21+
}
22+
23+
// CFnStackResourceListerInput is the input of the CFnStackResourceLister method.
24+
type CFnStackResourceListerInput struct {
25+
// StackName is the name of the stack.
26+
StackName string
27+
}
28+
29+
// CFnStackResourceListerOutput is the output of the CFnStackResourceLister method.
30+
type CFnStackResourceListerOutput struct {
31+
// Resources is a list of CloudFormation stack resources.
32+
Resources []*model.StackResource
33+
}
34+
35+
// CFnStackResourceLister is the interface that wraps the basic CFnStackResourceLister method.
36+
type CFnStackResourceLister interface {
37+
CFnStackResourceLister(ctx context.Context, input *CFnStackResourceListerInput) (*CFnStackResourceListerOutput, error)
38+
}
39+
40+
// CFnStackCreatorInput is the input of the CFnStackCreator method.
41+
type CFnStackCreatorInput struct {
42+
// StackName is the name of the stack.
43+
StackName string
44+
// TemplateBody is the template body.
45+
TemplateBody string
46+
}
47+
48+
// CFnStackCreatorOutput is the output of the CFnStackCreator method.
49+
type CFnStackCreatorOutput struct {
50+
// StackID is the ID of the stack.
51+
StackID string
52+
}
53+
54+
// CFnStackCreator is the interface that wraps the basic CFnStackCreator method.
55+
type CFnStackCreator interface {
56+
CFnStackCreator(ctx context.Context, input *CFnStackCreatorInput) (*CFnStackCreatorOutput, error)
57+
}
58+
59+
// CFnStackDeleterInput is the input of the CFnStackDeleter method.
60+
type CFnStackDeleterInput struct {
61+
// StackName is the name of the stack.
62+
StackName string
63+
}
64+
65+
// CFnStackDeleterOutput is the output of the CFnStackDeleter method.
66+
type CFnStackDeleterOutput struct{}
67+
68+
// CFnStackDeleter is the interface that wraps the basic CFnStackDeleter method.
69+
type CFnStackDeleter interface {
70+
CFnStackDeleter(ctx context.Context, input *CFnStackDeleterInput) (*CFnStackDeleterOutput, error)
2171
}

0 commit comments

Comments
 (0)