|
| 1 | +package cloudformation |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/aws/aws-sdk-go-v2/service/cloudformation" |
| 7 | + "github.com/aws/aws-sdk-go-v2/service/cloudformation/types" |
| 8 | + "github.com/cloudquery/cloudquery/plugins/source/aws/client" |
| 9 | + "github.com/cloudquery/plugin-sdk/v2/schema" |
| 10 | + "github.com/cloudquery/plugin-sdk/v2/transformers" |
| 11 | +) |
| 12 | + |
| 13 | +func stackTemplates() *schema.Table { |
| 14 | + tableName := "aws_cloudformation_stack_templates" |
| 15 | + return &schema.Table{ |
| 16 | + Name: tableName, |
| 17 | + Description: `https://docs.aws.amazon.com/AWSCloudFormation/latest/APIReference/API_GetTemplate.html`, |
| 18 | + Resolver: fetchCloudformationStackTemplates, |
| 19 | + Multiplex: client.ServiceAccountRegionMultiplexer(tableName, "cloudformation"), |
| 20 | + Transform: transformers.TransformWithStruct(&cloudformation.GetTemplateOutput{}, transformers.WithSkipFields("ResultMetadata")), |
| 21 | + Columns: []schema.Column{ |
| 22 | + client.DefaultAccountIDColumn(false), |
| 23 | + client.DefaultRegionColumn(false), |
| 24 | + { |
| 25 | + Name: "stack_arn", |
| 26 | + Type: schema.TypeString, |
| 27 | + Resolver: schema.ParentColumnResolver("arn"), |
| 28 | + CreationOptions: schema.ColumnCreationOptions{ |
| 29 | + PrimaryKey: true, |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +func fetchCloudformationStackTemplates(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error { |
| 37 | + stack := parent.Item.(types.Stack) |
| 38 | + config := cloudformation.GetTemplateInput{ |
| 39 | + StackName: stack.StackName, |
| 40 | + } |
| 41 | + c := meta.(*client.Client) |
| 42 | + svc := c.Services().Cloudformation |
| 43 | + resp, err := svc.GetTemplate(ctx, &config, func(options *cloudformation.Options) { |
| 44 | + options.Region = c.Region |
| 45 | + }) |
| 46 | + if err != nil { |
| 47 | + return err |
| 48 | + } |
| 49 | + res <- resp |
| 50 | + return nil |
| 51 | +} |
0 commit comments