-
Notifications
You must be signed in to change notification settings - Fork 16
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
resource with terraform-plugin-framework
#246
Conversation
@@ -303,7 +303,6 @@ resource "mackerel_aws_integration" "foo" { | |||
|
|||
ec2 { | |||
enable = true | |||
role = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The role
field accepts a role ID($service_name: $role_name
) or null. Empty string is some kind of pathological case and is not supported currently.
serviceSchema := schema.SetNestedBlock{ | ||
Description: schemaAWSIntegrationServiceDesc, | ||
Validators: []validator.Set{ | ||
setvalidator.SizeAtMost(1), | ||
}, | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"enable": schema.BoolAttribute{ | ||
Description: schemaAWSIntegrationServiceEnableDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(true), | ||
}, | ||
"role": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationServiceRoleDesc, | ||
Optional: true, | ||
}, | ||
"excluded_metrics": schema.ListAttribute{ | ||
Description: schemaAWSIntegrationServiceExcludedMetricsDesc, | ||
ElementType: types.StringType, | ||
Optional: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
serviceSchemaWithRetireAutomatically := schema.SetNestedBlock{ | ||
Description: schemaAWSIntegrationServiceDesc, | ||
Validators: []validator.Set{ | ||
setvalidator.SizeAtMost(1), | ||
}, | ||
NestedObject: schema.NestedBlockObject{ | ||
Attributes: map[string]schema.Attribute{ | ||
"enable": schema.BoolAttribute{ | ||
Description: schemaAWSIntegrationServiceEnableDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(true), | ||
}, | ||
"role": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationServiceRoleDesc, | ||
Optional: true, | ||
}, | ||
"excluded_metrics": schema.ListAttribute{ | ||
Description: schemaAWSIntegrationServiceExcludedMetricsDesc, | ||
ElementType: types.StringType, | ||
Optional: true, | ||
}, | ||
"retire_automatically": schema.BoolAttribute{ | ||
Description: schemaAWSIntegrationServiceRetireAutomaticallyDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: booldefault.StaticBool(false), | ||
}, | ||
}, | ||
}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original schema:
var awsIntegrationServiceResourceWithRetireAutomatically = &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"enable": { | |
Type: schema.TypeBool, | |
Optional: true, | |
Default: true, | |
}, | |
"role": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"excluded_metrics": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Schema{ | |
Type: schema.TypeString, | |
}, | |
}, | |
"retire_automatically": { | |
Type: schema.TypeBool, | |
Optional: true, | |
}, | |
}, | |
} | |
var awsIntegrationServiceSchemaWithRetireAutomatically = &schema.Schema{ | |
Type: schema.TypeSet, | |
Optional: true, | |
MaxItems: 1, | |
Elem: awsIntegrationServiceResourceWithRetireAutomatically, | |
} | |
var awsIntegrationServiceResource = &schema.Resource{ | |
Schema: map[string]*schema.Schema{ | |
"enable": { | |
Type: schema.TypeBool, | |
Optional: true, | |
Default: true, | |
}, | |
"role": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"excluded_metrics": { | |
Type: schema.TypeList, | |
Optional: true, | |
Elem: &schema.Schema{ | |
Type: schema.TypeString, | |
}, | |
}, | |
}, | |
} | |
var awsIntegrationServiceSchema = &schema.Schema{ | |
Type: schema.TypeSet, | |
Optional: true, | |
MaxItems: 1, | |
Elem: awsIntegrationServiceResource, | |
} |
Attributes: map[string]schema.Attribute{ | ||
"id": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationIDDesc, | ||
Computed: true, | ||
PlanModifiers: []planmodifier.String{ | ||
stringplanmodifier.UseStateForUnknown(), // immutable | ||
}, | ||
}, | ||
"name": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationNameDesc, | ||
Required: true, | ||
}, | ||
"memo": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationMemoDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"key": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationKeyDesc, | ||
Optional: true, | ||
Sensitive: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
Validators: []validator.String{ | ||
// With Access Key, secret access key is need too. | ||
stringvalidator.AlsoRequires(path.MatchRoot("secret_key")), | ||
}, | ||
}, | ||
"secret_key": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationSecretKeyDesc, | ||
Optional: true, | ||
Sensitive: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
Validators: []validator.String{ | ||
// Secret access key cannot be set alone | ||
stringvalidator.AlsoRequires(path.MatchRoot("key")), | ||
}, | ||
}, | ||
"role_arn": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationRoleARNDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"external_id": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationExternalIDDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
Validators: []validator.String{ | ||
// External ID cannot be set alone | ||
stringvalidator.AlsoRequires(path.MatchRoot("role_arn")), | ||
}, | ||
}, | ||
"region": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationRegionDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"included_tags": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationIncludedTagsDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
"excluded_tags": schema.StringAttribute{ | ||
Description: schemaAWSIntegrationExcludedTagsDesc, | ||
Optional: true, | ||
Computed: true, | ||
Default: stringdefault.StaticString(""), | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Original schema:
terraform-provider-mackerel/mackerel/resource_mackerel_aws_integration.go
Lines 110 to 150 in 5955898
Schema: map[string]*schema.Schema{ | |
"name": { | |
Type: schema.TypeString, | |
Required: true, | |
}, | |
"memo": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"key": { | |
Type: schema.TypeString, | |
Optional: true, | |
Sensitive: true, | |
}, | |
"secret_key": { | |
Type: schema.TypeString, | |
Optional: true, | |
Sensitive: true, | |
}, | |
"role_arn": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"external_id": { | |
Type: schema.TypeString, | |
Optional: true, | |
Sensitive: true, | |
}, | |
"region": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"included_tags": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
"excluded_tags": { | |
Type: schema.TypeString, | |
Optional: true, | |
}, | |
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙆♀️
Part of #243
Output from acceptance testing: