Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reimplement "mackerel_aws_integration" data source with terraform-plugin-framework #247

Merged
merged 6 commits into from
Nov 5, 2024

Conversation

tosuke
Copy link
Contributor

@tosuke tosuke commented Oct 31, 2024

Part of #243 . This PR adds a new "mackerel_aws_integration" data source implementation using AWSIntegrationModel introduced in #244 .

Output from acceptance testing:

$ MACKEREL_EXPERIMENTAL_TFFRAMEWORK=1 make testacc TESTS='"AccDataSourceMackerelAWSIntegration"'
TF_ACC=1 go test -v ./mackerel/... -run "AccDataSourceMackerelAWSIntegration" -timeout 120m
2024/10/31 20:40:44 [INFO] mackerel: use terraform-plugin-framework based implementation
=== RUN   TestAccDataSourceMackerelAWSIntegrationIAMRole
=== PAUSE TestAccDataSourceMackerelAWSIntegrationIAMRole
=== RUN   TestAccDataSourceMackerelAWSIntegrationCredential
=== PAUSE TestAccDataSourceMackerelAWSIntegrationCredential
=== CONT  TestAccDataSourceMackerelAWSIntegrationIAMRole
=== CONT  TestAccDataSourceMackerelAWSIntegrationCredential
--- PASS: TestAccDataSourceMackerelAWSIntegrationCredential (4.05s)
--- PASS: TestAccDataSourceMackerelAWSIntegrationIAMRole (4.34s)
PASS
ok      github.com/mackerelio-labs/terraform-provider-mackerel/mackerel 5.223s

Name types.String `tfsdk:"name"`
Memo types.String `tfsdk:"memo"`
Key types.String `tfsdk:"key"`
SecretKey types.String `tfsdk:"-"`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWS Integration resources contain an AWS secret key in their state, whereas data sources do not.

Comment on lines 64 to 101
attrs := map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: schemaAWSIntegrationIDDesc,
Required: true,
},
"name": schema.StringAttribute{
Description: schemaAWSIntegrationNameDesc,
Computed: true,
},
"memo": schema.StringAttribute{
Description: schemaAWSIntegrationMemoDesc,
Computed: true,
},
"key": schema.StringAttribute{
Description: schemaAWSIntegrationKeyDesc,
Computed: true,
},
"role_arn": schema.StringAttribute{
Description: schemaAWSIntegrationRoleARNDesc,
Computed: true,
},
"external_id": schema.StringAttribute{
Description: schemaAWSIntegrationExternalIDDesc,
Computed: true,
},
"region": schema.StringAttribute{
Description: schemaAWSIntegrationRegionDesc,
Computed: true,
},
"included_tags": schema.StringAttribute{
Description: schemaAWSIntegrationIncludedTagsDesc,
Computed: true,
},
"excluded_tags": schema.StringAttribute{
Description: schemaAWSIntegrationExcludedTagsDesc,
Computed: true,
},
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original schema:

Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"name": {
Type: schema.TypeString,
Computed: true,
},
"memo": {
Type: schema.TypeString,
Computed: true,
},
"key": {
Type: schema.TypeString,
Computed: true,
},
"role_arn": {
Type: schema.TypeString,
Computed: true,
},
"external_id": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
},
"included_tags": {
Type: schema.TypeString,
Computed: true,
},
"excluded_tags": {
Type: schema.TypeString,
Computed: true,
},
},

Comment on lines +104 to +131
if spec.supportsAutoRetire {
attrs[name] = schema.SetAttribute{
Computed: true,
ElementType: types.ObjectType{
AttrTypes: map[string]attr.Type{
"enable": types.BoolType,
"role": types.StringType,
"excluded_metrics": types.ListType{
ElemType: types.StringType,
},
"retire_automatically": types.BoolType,
},
},
}
} else {
attrs[name] = schema.SetAttribute{
Computed: true,
ElementType: types.ObjectType{
AttrTypes: map[string]attr.Type{
"enable": types.BoolType,
"role": types.StringType,
"excluded_metrics": types.ListType{
ElemType: types.StringType,
},
},
},
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original schema:

var awsIntegrationServiceDataResourceWithRetireAutomatically = &schema.Resource{
Schema: map[string]*schema.Schema{
"enable": {
Type: schema.TypeBool,
Computed: true,
},
"role": {
Type: schema.TypeString,
Computed: true,
},
"excluded_metrics": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"retire_automatically": {
Type: schema.TypeBool,
Computed: true,
},
},
}
var awsIntegrationServiceDataSchemaWithRetireAutomatically = &schema.Schema{
Type: schema.TypeSet,
Computed: true,
Elem: awsIntegrationServiceDataResourceWithRetireAutomatically,
}
var awsIntegrationServiceDataResource = &schema.Resource{
Schema: map[string]*schema.Schema{
"enable": {
Type: schema.TypeBool,
Computed: true,
},
"role": {
Type: schema.TypeString,
Computed: true,
},
"excluded_metrics": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
}

@tosuke tosuke marked this pull request as ready for review October 31, 2024 11:50
yohfee

This comment was marked as duplicate.

Copy link
Contributor

@yohfee yohfee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@tosuke tosuke merged commit 522f343 into main Nov 5, 2024
1 check passed
@tosuke tosuke deleted the framework-aws-integration-data-source branch November 5, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants