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

Use Values functions to validate SDK Enums: K-M #16732

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions aws/resource_aws_kinesis_firehose_delivery_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ func resourceAwsKinesisFirehoseDeliveryStream() *schema.Resource {
value := v.(string)
return strings.ToLower(value)
},
//lintignore:AWSV001 // internal constants
ValidateFunc: validation.StringInSlice([]string{
firehoseDestinationTypeS3,
firehoseDestinationTypeExtendedS3,
Expand Down Expand Up @@ -1417,13 +1418,10 @@ func resourceAwsKinesisFirehoseDeliveryStream() *schema.Resource {
},

"hec_endpoint_type": {
Type: schema.TypeString,
Optional: true,
Default: firehose.HECEndpointTypeRaw,
ValidateFunc: validation.StringInSlice([]string{
firehose.HECEndpointTypeRaw,
firehose.HECEndpointTypeEvent,
}, false),
Type: schema.TypeString,
Optional: true,
Default: firehose.HECEndpointTypeRaw,
ValidateFunc: validation.StringInSlice(firehose.HECEndpointType_Values(), false),
},

"hec_token": {
Expand All @@ -1432,13 +1430,10 @@ func resourceAwsKinesisFirehoseDeliveryStream() *schema.Resource {
},

"s3_backup_mode": {
Type: schema.TypeString,
Optional: true,
Default: firehose.SplunkS3BackupModeFailedEventsOnly,
ValidateFunc: validation.StringInSlice([]string{
firehose.SplunkS3BackupModeFailedEventsOnly,
firehose.SplunkS3BackupModeAllEvents,
}, false),
Type: schema.TypeString,
Optional: true,
Default: firehose.SplunkS3BackupModeFailedEventsOnly,
ValidateFunc: validation.StringInSlice(firehose.SplunkS3BackupMode_Values(), false),
},

"retry_duration": {
Expand Down
11 changes: 4 additions & 7 deletions aws/resource_aws_kinesis_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,10 @@ func resourceAwsKinesisStream() *schema.Resource {
},

"encryption_type": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
ValidateFunc: validation.StringInSlice([]string{
kinesis.EncryptionTypeNone,
kinesis.EncryptionTypeKms,
}, true),
Type: schema.TypeString,
Optional: true,
Default: "NONE",
ValidateFunc: validation.StringInSlice(kinesis.EncryptionType_Values(), true),
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
return strings.EqualFold(old, new)
},
Expand Down
32 changes: 10 additions & 22 deletions aws/resource_aws_kms_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,18 @@ func resourceAwsKmsKey() *schema.Resource {
Computed: true,
},
"key_usage": {
Type: schema.TypeString,
Optional: true,
Default: kms.KeyUsageTypeEncryptDecrypt,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
kms.KeyUsageTypeEncryptDecrypt,
kms.KeyUsageTypeSignVerify,
}, false),
Type: schema.TypeString,
Optional: true,
Default: kms.KeyUsageTypeEncryptDecrypt,
ForceNew: true,
ValidateFunc: validation.StringInSlice(kms.KeyUsageType_Values(), false),
},
"customer_master_key_spec": {
Type: schema.TypeString,
Optional: true,
Default: kms.CustomerMasterKeySpecSymmetricDefault,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
kms.CustomerMasterKeySpecSymmetricDefault,
kms.CustomerMasterKeySpecRsa2048,
kms.CustomerMasterKeySpecRsa3072,
kms.CustomerMasterKeySpecRsa4096,
kms.CustomerMasterKeySpecEccNistP256,
kms.CustomerMasterKeySpecEccNistP384,
kms.CustomerMasterKeySpecEccNistP521,
kms.CustomerMasterKeySpecEccSecgP256k1,
}, false),
Type: schema.TypeString,
Optional: true,
Default: kms.CustomerMasterKeySpecSymmetricDefault,
ForceNew: true,
ValidateFunc: validation.StringInSlice(kms.CustomerMasterKeySpec_Values(), false),
},
"policy": {
Type: schema.TypeString,
Expand Down
9 changes: 3 additions & 6 deletions aws/resource_aws_lambda_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,9 @@ func resourceAwsLambdaFunction() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"mode": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
lambda.TracingModeActive,
lambda.TracingModePassThrough},
true),
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(lambda.TracingMode_Values(), true),
},
},
},
Expand Down
44 changes: 16 additions & 28 deletions aws/resource_aws_launch_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,9 @@ func resourceAwsLaunchTemplate() *schema.Resource {
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"capacity_reservation_preference": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
ec2.CapacityReservationPreferenceOpen,
ec2.CapacityReservationPreferenceNone,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(ec2.CapacityReservationPreference_Values(), false),
},
"capacity_reservation_target": {
Type: schema.TypeList,
Expand Down Expand Up @@ -291,12 +288,9 @@ func resourceAwsLaunchTemplate() *schema.Resource {
},

"instance_initiated_shutdown_behavior": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
ec2.ShutdownBehaviorStop,
ec2.ShutdownBehaviorTerminate,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(ec2.ShutdownBehavior_Values(), false),
},

"instance_market_options": {
Expand All @@ -308,7 +302,7 @@ func resourceAwsLaunchTemplate() *schema.Resource {
"market_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{ec2.MarketTypeSpot}, false),
ValidateFunc: validation.StringInSlice(ec2.MarketType_Values(), false),
},
"spot_options": {
Type: schema.TypeList,
Expand All @@ -329,12 +323,9 @@ func resourceAwsLaunchTemplate() *schema.Resource {
Optional: true,
},
"spot_instance_type": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
ec2.SpotInstanceTypeOneTime,
ec2.SpotInstanceTypePersistent,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(ec2.SpotInstanceType_Values(), false),
},
"valid_until": {
Type: schema.TypeString,
Expand Down Expand Up @@ -389,13 +380,13 @@ func resourceAwsLaunchTemplate() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{ec2.LaunchTemplateInstanceMetadataEndpointStateEnabled, ec2.LaunchTemplateInstanceMetadataEndpointStateDisabled}, false),
ValidateFunc: validation.StringInSlice(ec2.LaunchTemplateInstanceMetadataEndpointState_Values(), false),
},
"http_tokens": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validation.StringInSlice([]string{ec2.LaunchTemplateHttpTokensStateOptional, ec2.LaunchTemplateHttpTokensStateRequired}, false),
ValidateFunc: validation.StringInSlice(ec2.LaunchTemplateHttpTokensState_Values(), false),
},
"http_put_response_hop_limit": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -554,13 +545,9 @@ func resourceAwsLaunchTemplate() *schema.Resource {
Optional: true,
},
"tenancy": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
ec2.TenancyDedicated,
ec2.TenancyDefault,
ec2.TenancyHost,
}, false),
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringInSlice(ec2.Tenancy_Values(), false),
},
"partition_number": {
Type: schema.TypeInt,
Expand Down Expand Up @@ -597,6 +584,7 @@ func resourceAwsLaunchTemplate() *schema.Resource {
"resource_type": {
Type: schema.TypeString,
Optional: true,
//lintignore:AWSV001 // only a limited number of resource types are handled by launch templates
ValidateFunc: validation.StringInSlice([]string{
ec2.ResourceTypeInstance,
ec2.ResourceTypeVolume,
Expand Down
11 changes: 4 additions & 7 deletions aws/resource_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,10 @@ func resourceAwsLb() *schema.Resource {
},

"ip_address_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice([]string{
elbv2.IpAddressTypeIpv4,
elbv2.IpAddressTypeDualstack,
}, false),
Type: schema.TypeString,
Computed: true,
Optional: true,
ValidateFunc: validation.StringInSlice(elbv2.IpAddressType_Values(), false),
},

"customer_owned_ipv4_pool": {
Expand Down
3 changes: 3 additions & 0 deletions aws/resource_aws_lb_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func resourceAwsLbListener() *schema.Resource {
"alpn_policy": {
Type: schema.TypeString,
Optional: true,
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"HTTP1Only",
"HTTP2Only",
Expand Down Expand Up @@ -192,6 +193,7 @@ func resourceAwsLbListener() *schema.Resource {
"content_type": {
Type: schema.TypeString,
Required: true,
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"text/plain",
"text/css",
Expand Down Expand Up @@ -296,6 +298,7 @@ func resourceAwsLbListener() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "#{protocol}",
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"#{protocol}",
"HTTP",
Expand Down
2 changes: 2 additions & 0 deletions aws/resource_aws_lb_listener_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func resourceAwsLbbListenerRule() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: "#{protocol}",
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"#{protocol}",
"HTTP",
Expand Down Expand Up @@ -190,6 +191,7 @@ func resourceAwsLbbListenerRule() *schema.Resource {
"content_type": {
Type: schema.TypeString,
Required: true,
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"text/plain",
"text/css",
Expand Down
9 changes: 4 additions & 5 deletions aws/resource_aws_lb_target_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ func resourceAwsLbTargetGroup() *schema.Resource {
StateFunc: func(v interface{}) string {
return strings.ToUpper(v.(string))
},
ValidateFunc: validation.StringInSlice([]string{
elbv2.ProtocolEnumHttp,
elbv2.ProtocolEnumHttps,
elbv2.ProtocolEnumTcp,
}, true),
ValidateFunc: validation.StringInSlice(elbv2.ProtocolEnum_Values(), true),
DiffSuppressFunc: suppressIfTargetType(elbv2.TargetTypeEnumLambda),
},
"timeout": {
Expand All @@ -132,6 +128,7 @@ func resourceAwsLbTargetGroup() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Computed: true,
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"round_robin",
"least_outstanding_requests",
Expand Down Expand Up @@ -182,6 +179,7 @@ func resourceAwsLbTargetGroup() *schema.Resource {
StateFunc: func(v interface{}) string {
return strings.ToUpper(v.(string))
},
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"GRPC",
"HTTP1",
Expand Down Expand Up @@ -241,6 +239,7 @@ func resourceAwsLbTargetGroup() *schema.Resource {
"type": {
Type: schema.TypeString,
Required: true,
//lintignore:AWSV001 // no enum in AWS SDK
ValidateFunc: validation.StringInSlice([]string{
"lb_cookie", // Only for ALBs
"app_cookie", // Only for ALBs
Expand Down
13 changes: 4 additions & 9 deletions aws/resource_aws_licensemanager_license_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ func resourceAwsLicenseManagerLicenseConfiguration() *schema.Resource {
Default: false,
},
"license_counting_type": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
licensemanager.LicenseCountingTypeVCpu,
licensemanager.LicenseCountingTypeInstance,
licensemanager.LicenseCountingTypeCore,
licensemanager.LicenseCountingTypeSocket,
}, false),
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice(licensemanager.LicenseCountingType_Values(), false),
},
"license_rules": {
Type: schema.TypeList,
Expand Down
4 changes: 2 additions & 2 deletions aws/resource_aws_macie_s3_bucket_association.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func resourceAwsMacieS3BucketAssociation() *schema.Resource {
Type: schema.TypeString,
Optional: true,
Default: macie.S3ContinuousClassificationTypeFull,
ValidateFunc: validation.StringInSlice([]string{macie.S3ContinuousClassificationTypeFull}, false),
ValidateFunc: validation.StringInSlice(macie.S3ContinuousClassificationType_Values(), false),
},
"one_time": {
Type: schema.TypeString,
Optional: true,
Default: macie.S3OneTimeClassificationTypeNone,
ValidateFunc: validation.StringInSlice([]string{macie.S3OneTimeClassificationTypeFull, macie.S3OneTimeClassificationTypeNone}, false),
ValidateFunc: validation.StringInSlice(macie.S3OneTimeClassificationType_Values(), false),
},
},
},
Expand Down
Loading