Skip to content

Commit 3fde704

Browse files
authored
feat: Add AWS SSM Parameters resource (#1222)
1 parent dd69948 commit 3fde704

File tree

8 files changed

+262
-0
lines changed

8 files changed

+262
-0
lines changed

plugins/source/aws/client/mocks/mock_ssm.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/source/aws/client/services.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ type SSMClient interface {
786786
DescribeDocument(ctx context.Context, params *ssm.DescribeDocumentInput, optFns ...func(*ssm.Options)) (*ssm.DescribeDocumentOutput, error)
787787
DescribeDocumentPermission(ctx context.Context, params *ssm.DescribeDocumentPermissionInput, optFns ...func(*ssm.Options)) (*ssm.DescribeDocumentPermissionOutput, error)
788788
DescribeInstanceInformation(ctx context.Context, params *ssm.DescribeInstanceInformationInput, optFns ...func(*ssm.Options)) (*ssm.DescribeInstanceInformationOutput, error)
789+
DescribeParameters(ctx context.Context, params *ssm.DescribeParametersInput, optFns ...func(*ssm.Options)) (*ssm.DescribeParametersOutput, error)
789790
ListComplianceItems(ctx context.Context, params *ssm.ListComplianceItemsInput, optFns ...func(*ssm.Options)) (*ssm.ListComplianceItemsOutput, error)
790791
ListDocuments(ctx context.Context, params *ssm.ListDocumentsInput, optFns ...func(*ssm.Options)) (*ssm.ListDocumentsOutput, error)
791792
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
# Table: aws_ssm_parameter_policies
3+
One or more policies assigned to a parameter
4+
## Columns
5+
| Name | Type | Description |
6+
| ------------- | ------------- | ----- |
7+
|parameter_cq_id|uuid|Unique CloudQuery ID of aws_ssm_parameters table (FK)|
8+
|policy_status|text|The status of the policy|
9+
|policy_text|text|The JSON text of the policy|
10+
|policy_type|text|The type of policy|
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
# Table: aws_ssm_parameters
3+
Metadata includes information like the ARN of the last user and the date/time the parameter was last used
4+
## Columns
5+
| Name | Type | Description |
6+
| ------------- | ------------- | ----- |
7+
|account_id|text|The AWS Account ID of the resource|
8+
|region|text|The AWS Region of the resource|
9+
|allowed_pattern|text|A parameter name can include only the following letters and symbols a-zA-Z0-9_-|
10+
|data_type|text|The data type of the parameter, such as text or aws:ec2:image|
11+
|description|text|Description of the parameter actions|
12+
|key_id|text|The ID of the query key used for this parameter|
13+
|last_modified_date|timestamp without time zone|Date the parameter was last changed or updated|
14+
|last_modified_user|text|Amazon Resource Name (ARN) of the Amazon Web Services user who last changed the parameter|
15+
|name|text|The parameter name|
16+
|tier|text|The parameter tier|
17+
|type|text|The type of parameter|
18+
|version|bigint|The parameter version|

plugins/source/aws/resources/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ func Provider() *provider.Provider {
283283
"sqs.queues": sqs.SQSQueues(),
284284
"ssm.documents": ssm.SsmDocuments(),
285285
"ssm.instances": ssm.SsmInstances(),
286+
"ssm.parameters": ssm.Parameters(),
286287
"waf.rule_groups": waf.WafRuleGroups(),
287288
"waf.rules": waf.WafRules(),
288289
"waf.subscribed_rule_groups": waf.WafSubscribedRuleGroups(),
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
package ssm
2+
3+
import (
4+
"context"
5+
6+
"github.com/aws/aws-sdk-go-v2/aws"
7+
"github.com/aws/aws-sdk-go-v2/service/ssm"
8+
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
9+
"github.com/cloudquery/cq-provider-sdk/provider/diag"
10+
"github.com/cloudquery/cq-provider-sdk/provider/schema"
11+
)
12+
13+
//go:generate cq-gen --resource parameters --config resources/services/ssm/parameters.hcl --output .
14+
func Parameters() *schema.Table {
15+
return &schema.Table{
16+
Name: "aws_ssm_parameters",
17+
Description: "Metadata includes information like the ARN of the last user and the date/time the parameter was last used",
18+
Resolver: fetchSsmParameters,
19+
Multiplex: client.ServiceAccountRegionMultiplexer("ssm"),
20+
IgnoreError: client.IgnoreAccessDeniedServiceDisabled,
21+
DeleteFilter: client.DeleteAccountRegionFilter,
22+
Options: schema.TableCreationOptions{PrimaryKeys: []string{"account_id", "region", "name"}},
23+
Columns: []schema.Column{
24+
{
25+
Name: "account_id",
26+
Description: "The AWS Account ID of the resource",
27+
Type: schema.TypeString,
28+
Resolver: client.ResolveAWSAccount,
29+
},
30+
{
31+
Name: "region",
32+
Description: "The AWS Region of the resource",
33+
Type: schema.TypeString,
34+
Resolver: client.ResolveAWSRegion,
35+
},
36+
{
37+
Name: "allowed_pattern",
38+
Description: "A parameter name can include only the following letters and symbols a-zA-Z0-9_-",
39+
Type: schema.TypeString,
40+
},
41+
{
42+
Name: "data_type",
43+
Description: "The data type of the parameter, such as text or aws:ec2:image",
44+
Type: schema.TypeString,
45+
},
46+
{
47+
Name: "description",
48+
Description: "Description of the parameter actions",
49+
Type: schema.TypeString,
50+
},
51+
{
52+
Name: "key_id",
53+
Description: "The ID of the query key used for this parameter",
54+
Type: schema.TypeString,
55+
},
56+
{
57+
Name: "last_modified_date",
58+
Description: "Date the parameter was last changed or updated",
59+
Type: schema.TypeTimestamp,
60+
},
61+
{
62+
Name: "last_modified_user",
63+
Description: "Amazon Resource Name (ARN) of the Amazon Web Services user who last changed the parameter",
64+
Type: schema.TypeString,
65+
},
66+
{
67+
Name: "name",
68+
Description: "The parameter name",
69+
Type: schema.TypeString,
70+
},
71+
{
72+
Name: "tier",
73+
Description: "The parameter tier",
74+
Type: schema.TypeString,
75+
},
76+
{
77+
Name: "type",
78+
Description: "The type of parameter",
79+
Type: schema.TypeString,
80+
},
81+
{
82+
Name: "version",
83+
Description: "The parameter version",
84+
Type: schema.TypeBigInt,
85+
},
86+
},
87+
Relations: []*schema.Table{
88+
{
89+
Name: "aws_ssm_parameter_policies",
90+
Description: "One or more policies assigned to a parameter",
91+
Resolver: schema.PathTableResolver("Policies"),
92+
Columns: []schema.Column{
93+
{
94+
Name: "parameter_cq_id",
95+
Description: "Unique CloudQuery ID of aws_ssm_parameters table (FK)",
96+
Type: schema.TypeUUID,
97+
Resolver: schema.ParentIdResolver,
98+
},
99+
{
100+
Name: "policy_status",
101+
Description: "The status of the policy",
102+
Type: schema.TypeString,
103+
},
104+
{
105+
Name: "policy_text",
106+
Description: "The JSON text of the policy",
107+
Type: schema.TypeString,
108+
},
109+
{
110+
Name: "policy_type",
111+
Description: "The type of policy",
112+
Type: schema.TypeString,
113+
},
114+
},
115+
},
116+
},
117+
}
118+
}
119+
120+
// ====================================================================================================================
121+
// Table Resolver Functions
122+
// ====================================================================================================================
123+
124+
func fetchSsmParameters(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
125+
cl := meta.(*client.Client)
126+
svc := cl.Services().SSM
127+
params := ssm.DescribeParametersInput{}
128+
for {
129+
output, err := svc.DescribeParameters(ctx, &params)
130+
if err != nil {
131+
return diag.WrapError(err)
132+
}
133+
res <- output.Parameters
134+
if aws.ToString(output.NextToken) == "" {
135+
break
136+
}
137+
params.NextToken = output.NextToken
138+
}
139+
return nil
140+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
service = "aws"
2+
output_directory = "."
3+
add_generate = true
4+
5+
description_modifier "remove_read_only" {
6+
words = [" This member is required"]
7+
}
8+
9+
resource "aws" "ssm" "parameters" {
10+
path = "github.com/aws/aws-sdk-go-v2/service/ssm/types.ParameterMetadata"
11+
ignoreError "IgnoreAccessDenied" {
12+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.IgnoreAccessDeniedServiceDisabled"
13+
}
14+
deleteFilter "AccountRegionFilter" {
15+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.DeleteAccountRegionFilter"
16+
}
17+
multiplex "AwsAccountRegion" {
18+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ServiceAccountRegionMultiplexer"
19+
params = ["ssm"]
20+
}
21+
22+
userDefinedColumn "account_id" {
23+
description = "The AWS Account ID of the resource"
24+
type = "string"
25+
resolver "resolveAWSAccount" {
26+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ResolveAWSAccount"
27+
}
28+
}
29+
userDefinedColumn "region" {
30+
type = "string"
31+
description = "The AWS Region of the resource"
32+
resolver "resolveAWSRegion" {
33+
path = "github.com/cloudquery/cloudquery/plugins/source/aws/client.ResolveAWSRegion"
34+
}
35+
}
36+
37+
options {
38+
primary_keys = ["account_id", "region", "name"]
39+
}
40+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ssm
2+
3+
import (
4+
"testing"
5+
6+
"github.com/aws/aws-sdk-go-v2/service/ssm"
7+
"github.com/aws/aws-sdk-go-v2/service/ssm/types"
8+
"github.com/cloudquery/cloudquery/plugins/source/aws/client"
9+
"github.com/cloudquery/cloudquery/plugins/source/aws/client/mocks"
10+
"github.com/cloudquery/faker/v3"
11+
"github.com/golang/mock/gomock"
12+
)
13+
14+
func buildParameters(t *testing.T, ctrl *gomock.Controller) client.Services {
15+
mock := mocks.NewMockSSMClient(ctrl)
16+
var pm types.ParameterMetadata
17+
if err := faker.FakeData(&pm); err != nil {
18+
t.Fatal(err)
19+
}
20+
mock.EXPECT().DescribeParameters(
21+
gomock.Any(),
22+
&ssm.DescribeParametersInput{},
23+
).Return(
24+
&ssm.DescribeParametersOutput{Parameters: []types.ParameterMetadata{pm}},
25+
nil,
26+
)
27+
return client.Services{SSM: mock}
28+
}
29+
30+
func TestParameters(t *testing.T) {
31+
client.AwsMockTestHelper(t, Parameters(), buildParameters, client.TestOptions{})
32+
}

0 commit comments

Comments
 (0)