Skip to content

Commit

Permalink
Merge pull request #247 from mackerelio-labs/framework-aws-integratio…
Browse files Browse the repository at this point in the history
…n-data-source

Reimplement "mackerel_aws_integration" data source with terraform-plugin-framework
  • Loading branch information
tosuke authored Nov 5, 2024
2 parents 0f86842 + 68f021b commit 522f343
Show file tree
Hide file tree
Showing 6 changed files with 296 additions and 103 deletions.
25 changes: 24 additions & 1 deletion internal/mackerel/aws_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,25 @@ type AWSIntegrationModel struct {
IncludedTags types.String `tfsdk:"included_tags"`
ExcludedTags types.String `tfsdk:"excluded_tags"`

AWSIntegrationSerfvices
}

type AWSIntegrationDataSourceModel struct {
ID types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
Memo types.String `tfsdk:"memo"`
Key types.String `tfsdk:"key"`
SecretKey types.String `tfsdk:"-"`
RoleARN types.String `tfsdk:"role_arn"`
ExternalID types.String `tfsdk:"external_id"`
Region types.String `tfsdk:"region"`
IncludedTags types.String `tfsdk:"included_tags"`
ExcludedTags types.String `tfsdk:"excluded_tags"`

AWSIntegrationSerfvices
}

type AWSIntegrationSerfvices struct {
EC2 AWSIntegrationServiceWithRetireAutomaticallyOpt `tfsdk:"ec2"`
ELB AWSIntegrationServiceOpt `tfsdk:"elb"`
ALB AWSIntegrationServiceOpt `tfsdk:"alb"`
Expand Down Expand Up @@ -69,6 +88,10 @@ type AWSIntegrationServiceWithRetireAutomatically struct {

type AWSIntegrationServiceWithRetireAutomaticallyOpt []AWSIntegrationServiceWithRetireAutomatically // length <= 1

func ReadAWSIntegration(_ context.Context, client *Client, id string) (*AWSIntegrationModel, error) {
return readAWSIntegration(client, id)
}

func readAWSIntegration(client *Client, id string) (*AWSIntegrationModel, error) {
mackerelAWSIntegration, err := client.FindAWSIntegration(id)
if err != nil {
Expand Down Expand Up @@ -259,7 +282,7 @@ func (m *AWSIntegrationModel) merge(newModel AWSIntegrationModel) {
type awsServiceEachFunc func(name string, service *AWSIntegrationService) *AWSIntegrationService

// Iterates and updates over services by name
func (m *AWSIntegrationModel) each(fn awsServiceEachFunc) {
func (m *AWSIntegrationSerfvices) each(fn awsServiceEachFunc) {
m.EC2.each("EC2", fn)
m.ELB.each("ELB", fn)
m.ALB.each("ALB", fn)
Expand Down
208 changes: 106 additions & 102 deletions internal/mackerel/aws_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,57 +192,59 @@ func Test_AWSIntegration_fromAPI(t *testing.T) {
IncludedTags: types.StringValue("Name:production-server,Environment:production"),
ExcludedTags: types.StringValue("Name:staging-server,Environment:staging"),

EC2: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(true),
}},
ELB: []AWSIntegrationService{},
ALB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"alb.request.count", "alb.bytes.processed"},
RetireAutomatically: types.BoolValue(false),
}},
NLB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
RDS: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"rds.cpu.used"},
RetireAutomatically: types.BoolValue(false),
}},
Redshift: []AWSIntegrationService{},
ElastiCache: []AWSIntegrationServiceWithRetireAutomatically{},
SQS: []AWSIntegrationService{},
Lambda: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
DynamoDB: []AWSIntegrationService{},
CloudFront: []AWSIntegrationService{},
APIGateway: []AWSIntegrationService{},
Kinesis: []AWSIntegrationService{},
S3: []AWSIntegrationService{},
ES: []AWSIntegrationService{},
ECSCluster: []AWSIntegrationService{},
SES: []AWSIntegrationService{},
States: []AWSIntegrationService{},
EFS: []AWSIntegrationService{},
Firehose: []AWSIntegrationService{},
Batch: []AWSIntegrationService{},
WAF: []AWSIntegrationService{},
Billing: []AWSIntegrationService{},
Route53: []AWSIntegrationService{},
Connect: []AWSIntegrationService{},
DocDB: []AWSIntegrationService{},
CodeBuild: []AWSIntegrationService{},
AWSIntegrationSerfvices: AWSIntegrationSerfvices{
EC2: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(true),
}},
ELB: []AWSIntegrationService{},
ALB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"alb.request.count", "alb.bytes.processed"},
RetireAutomatically: types.BoolValue(false),
}},
NLB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
RDS: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"rds.cpu.used"},
RetireAutomatically: types.BoolValue(false),
}},
Redshift: []AWSIntegrationService{},
ElastiCache: []AWSIntegrationServiceWithRetireAutomatically{},
SQS: []AWSIntegrationService{},
Lambda: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
DynamoDB: []AWSIntegrationService{},
CloudFront: []AWSIntegrationService{},
APIGateway: []AWSIntegrationService{},
Kinesis: []AWSIntegrationService{},
S3: []AWSIntegrationService{},
ES: []AWSIntegrationService{},
ECSCluster: []AWSIntegrationService{},
SES: []AWSIntegrationService{},
States: []AWSIntegrationService{},
EFS: []AWSIntegrationService{},
Firehose: []AWSIntegrationService{},
Batch: []AWSIntegrationService{},
WAF: []AWSIntegrationService{},
Billing: []AWSIntegrationService{},
Route53: []AWSIntegrationService{},
Connect: []AWSIntegrationService{},
DocDB: []AWSIntegrationService{},
CodeBuild: []AWSIntegrationService{},
},
},
},
}
Expand Down Expand Up @@ -285,57 +287,59 @@ func Test_AWSIntegration_toAPI(t *testing.T) {
IncludedTags: types.StringValue("Name:production-server,Environment:production"),
ExcludedTags: types.StringValue("Name:staging-server,Environment:staging"),

EC2: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(true),
}},
ELB: []AWSIntegrationService{},
ALB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"alb.request.count", "alb.bytes.processed"},
RetireAutomatically: types.BoolValue(false),
}},
NLB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
RDS: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"rds.cpu.used"},
RetireAutomatically: types.BoolValue(false),
}},
Redshift: []AWSIntegrationService{},
ElastiCache: []AWSIntegrationServiceWithRetireAutomatically{},
SQS: []AWSIntegrationService{},
Lambda: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
DynamoDB: []AWSIntegrationService{},
CloudFront: []AWSIntegrationService{},
APIGateway: []AWSIntegrationService{},
Kinesis: []AWSIntegrationService{},
S3: []AWSIntegrationService{},
ES: []AWSIntegrationService{},
ECSCluster: []AWSIntegrationService{},
SES: []AWSIntegrationService{},
States: []AWSIntegrationService{},
EFS: []AWSIntegrationService{},
Firehose: []AWSIntegrationService{},
Batch: []AWSIntegrationService{},
WAF: []AWSIntegrationService{},
Billing: []AWSIntegrationService{},
Route53: []AWSIntegrationService{},
Connect: []AWSIntegrationService{},
DocDB: []AWSIntegrationService{},
CodeBuild: []AWSIntegrationService{},
AWSIntegrationSerfvices: AWSIntegrationSerfvices{
EC2: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(true),
}},
ELB: []AWSIntegrationService{},
ALB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"alb.request.count", "alb.bytes.processed"},
RetireAutomatically: types.BoolValue(false),
}},
NLB: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
RDS: []AWSIntegrationServiceWithRetireAutomatically{{
Enable: types.BoolValue(true),
Role: types.StringValue("service: role"),
ExcludedMetrics: []string{"rds.cpu.used"},
RetireAutomatically: types.BoolValue(false),
}},
Redshift: []AWSIntegrationService{},
ElastiCache: []AWSIntegrationServiceWithRetireAutomatically{},
SQS: []AWSIntegrationService{},
Lambda: []AWSIntegrationService{{
Enable: types.BoolValue(true),
Role: types.StringNull(),
ExcludedMetrics: []string{},
RetireAutomatically: types.BoolValue(false),
}},
DynamoDB: []AWSIntegrationService{},
CloudFront: []AWSIntegrationService{},
APIGateway: []AWSIntegrationService{},
Kinesis: []AWSIntegrationService{},
S3: []AWSIntegrationService{},
ES: []AWSIntegrationService{},
ECSCluster: []AWSIntegrationService{},
SES: []AWSIntegrationService{},
States: []AWSIntegrationService{},
EFS: []AWSIntegrationService{},
Firehose: []AWSIntegrationService{},
Batch: []AWSIntegrationService{},
WAF: []AWSIntegrationService{},
Billing: []AWSIntegrationService{},
Route53: []AWSIntegrationService{},
Connect: []AWSIntegrationService{},
DocDB: []AWSIntegrationService{},
CodeBuild: []AWSIntegrationService{},
},
},
param: mackerel.CreateAWSIntegrationParam{
Name: "aws-integration",
Expand Down
Loading

0 comments on commit 522f343

Please sign in to comment.