github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/aws/resource_aws_db_parameter_group_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "math/rand" 6 "testing" 7 "time" 8 9 "github.com/aws/aws-sdk-go/aws" 10 "github.com/aws/aws-sdk-go/aws/awserr" 11 "github.com/aws/aws-sdk-go/service/rds" 12 "github.com/hashicorp/terraform/helper/acctest" 13 "github.com/hashicorp/terraform/helper/resource" 14 "github.com/hashicorp/terraform/terraform" 15 ) 16 17 func TestAccAWSDBParameterGroup_limit(t *testing.T) { 18 var v rds.DBParameterGroup 19 20 groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt()) 21 22 resource.Test(t, resource.TestCase{ 23 PreCheck: func() { testAccPreCheck(t) }, 24 Providers: testAccProviders, 25 CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, 26 Steps: []resource.TestStep{ 27 resource.TestStep{ 28 Config: createAwsDbParameterGroupsExceedDefaultAwsLimit(groupName), 29 Check: resource.ComposeTestCheckFunc( 30 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.large", &v), 31 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 32 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "name", groupName), 33 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "family", "mysql5.6"), 34 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "description", "RDS default parameter group: Exceed default AWS parameter group limit of twenty"), 35 36 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2421266705.name", "character_set_server"), 37 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2421266705.value", "utf8"), 38 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2478663599.name", "character_set_client"), 39 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2478663599.value", "utf8"), 40 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1680942586.name", "collation_server"), 41 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1680942586.value", "utf8_general_ci"), 42 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2450940716.name", "collation_connection"), 43 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2450940716.value", "utf8_general_ci"), 44 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.242489837.name", "join_buffer_size"), 45 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.242489837.value", "16777216"), 46 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2026669454.name", "key_buffer_size"), 47 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2026669454.value", "67108864"), 48 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2705275319.name", "max_connections"), 49 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2705275319.value", "3200"), 50 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3512697936.name", "max_heap_table_size"), 51 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3512697936.value", "67108864"), 52 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.780730667.name", "performance_schema"), 53 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.780730667.value", "1"), 54 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2020346918.name", "performance_schema_users_size"), 55 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2020346918.value", "1048576"), 56 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1460834103.name", "query_cache_limit"), 57 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1460834103.value", "2097152"), 58 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.484865451.name", "query_cache_size"), 59 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.484865451.value", "67108864"), 60 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.255276438.name", "sort_buffer_size"), 61 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.255276438.value", "16777216"), 62 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2981725119.name", "table_open_cache"), 63 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2981725119.value", "4096"), 64 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2703661820.name", "tmp_table_size"), 65 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2703661820.value", "67108864"), 66 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2386583229.name", "binlog_cache_size"), 67 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2386583229.value", "131072"), 68 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.4012389720.name", "innodb_flush_log_at_trx_commit"), 69 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.4012389720.value", "0"), 70 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2688783017.name", "innodb_open_files"), 71 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2688783017.value", "4000"), 72 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.782983977.name", "innodb_read_io_threads"), 73 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.782983977.value", "64"), 74 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2809980413.name", "innodb_thread_concurrency"), 75 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2809980413.value", "0"), 76 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3599115250.name", "innodb_write_io_threads"), 77 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3599115250.value", "64"), 78 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2557156277.name", "character_set_connection"), 79 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2557156277.value", "utf8"), 80 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2475346812.name", "character_set_database"), 81 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2475346812.value", "utf8"), 82 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1986528518.name", "character_set_filesystem"), 83 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1986528518.value", "utf8"), 84 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1708034931.name", "character_set_results"), 85 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1708034931.value", "utf8"), 86 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1937131004.name", "event_scheduler"), 87 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1937131004.value", "on"), 88 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3437079877.name", "innodb_buffer_pool_dump_at_shutdown"), 89 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3437079877.value", "1"), 90 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1092112861.name", "innodb_file_format"), 91 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1092112861.value", "barracuda"), 92 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.615571931.name", "innodb_io_capacity"), 93 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.615571931.value", "2000"), 94 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1065962799.name", "innodb_io_capacity_max"), 95 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1065962799.value", "3000"), 96 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1411161182.name", "innodb_lock_wait_timeout"), 97 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1411161182.value", "120"), 98 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3133315879.name", "innodb_max_dirty_pages_pct"), 99 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3133315879.value", "90"), 100 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.950177639.name", "log_bin_trust_function_creators"), 101 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.950177639.value", "1"), 102 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.591700516.name", "log_warnings"), 103 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.591700516.value", "2"), 104 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1918306725.name", "log_output"), 105 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1918306725.value", "file"), 106 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.386204433.name", "max_allowed_packet"), 107 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.386204433.value", "1073741824"), 108 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1700901269.name", "max_connect_errors"), 109 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1700901269.value", "100"), 110 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2839701698.name", "query_cache_min_res_unit"), 111 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2839701698.value", "512"), 112 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.427634017.name", "slow_query_log"), 113 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.427634017.value", "1"), 114 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.881816039.name", "sync_binlog"), 115 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.881816039.value", "0"), 116 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.748684209.name", "tx_isolation"), 117 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.748684209.value", "repeatable-read"), 118 ), 119 }, 120 resource.TestStep{ 121 Config: updateAwsDbParameterGroupsExceedDefaultAwsLimit(groupName), 122 Check: resource.ComposeTestCheckFunc( 123 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.large", &v), 124 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 125 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "name", groupName), 126 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "family", "mysql5.6"), 127 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "description", "Updated RDS default parameter group: Exceed default AWS parameter group limit of twenty"), 128 129 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2421266705.name", "character_set_server"), 130 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2421266705.value", "utf8"), 131 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2478663599.name", "character_set_client"), 132 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2478663599.value", "utf8"), 133 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1680942586.name", "collation_server"), 134 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1680942586.value", "utf8_general_ci"), 135 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2450940716.name", "collation_connection"), 136 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2450940716.value", "utf8_general_ci"), 137 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.242489837.name", "join_buffer_size"), 138 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.242489837.value", "16777216"), 139 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2026669454.name", "key_buffer_size"), 140 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2026669454.value", "67108864"), 141 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2705275319.name", "max_connections"), 142 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2705275319.value", "3200"), 143 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3512697936.name", "max_heap_table_size"), 144 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3512697936.value", "67108864"), 145 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.780730667.name", "performance_schema"), 146 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.780730667.value", "1"), 147 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2020346918.name", "performance_schema_users_size"), 148 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2020346918.value", "1048576"), 149 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1460834103.name", "query_cache_limit"), 150 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1460834103.value", "2097152"), 151 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.484865451.name", "query_cache_size"), 152 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.484865451.value", "67108864"), 153 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.255276438.name", "sort_buffer_size"), 154 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.255276438.value", "16777216"), 155 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2981725119.name", "table_open_cache"), 156 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2981725119.value", "4096"), 157 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2703661820.name", "tmp_table_size"), 158 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2703661820.value", "67108864"), 159 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2386583229.name", "binlog_cache_size"), 160 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2386583229.value", "131072"), 161 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.4012389720.name", "innodb_flush_log_at_trx_commit"), 162 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.4012389720.value", "0"), 163 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2688783017.name", "innodb_open_files"), 164 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2688783017.value", "4000"), 165 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.782983977.name", "innodb_read_io_threads"), 166 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.782983977.value", "64"), 167 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2809980413.name", "innodb_thread_concurrency"), 168 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2809980413.value", "0"), 169 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3599115250.name", "innodb_write_io_threads"), 170 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3599115250.value", "64"), 171 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2557156277.name", "character_set_connection"), 172 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2557156277.value", "utf8"), 173 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2475346812.name", "character_set_database"), 174 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2475346812.value", "utf8"), 175 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1986528518.name", "character_set_filesystem"), 176 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1986528518.value", "utf8"), 177 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1708034931.name", "character_set_results"), 178 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1708034931.value", "utf8"), 179 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1937131004.name", "event_scheduler"), 180 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1937131004.value", "on"), 181 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3437079877.name", "innodb_buffer_pool_dump_at_shutdown"), 182 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3437079877.value", "1"), 183 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1092112861.name", "innodb_file_format"), 184 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1092112861.value", "barracuda"), 185 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.615571931.name", "innodb_io_capacity"), 186 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.615571931.value", "2000"), 187 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1065962799.name", "innodb_io_capacity_max"), 188 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1065962799.value", "3000"), 189 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1411161182.name", "innodb_lock_wait_timeout"), 190 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1411161182.value", "120"), 191 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3133315879.name", "innodb_max_dirty_pages_pct"), 192 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.3133315879.value", "90"), 193 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.950177639.name", "log_bin_trust_function_creators"), 194 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.950177639.value", "1"), 195 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.591700516.name", "log_warnings"), 196 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.591700516.value", "2"), 197 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1918306725.name", "log_output"), 198 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1918306725.value", "file"), 199 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.386204433.name", "max_allowed_packet"), 200 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.386204433.value", "1073741824"), 201 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1700901269.name", "max_connect_errors"), 202 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.1700901269.value", "100"), 203 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2839701698.name", "query_cache_min_res_unit"), 204 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.2839701698.value", "512"), 205 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.427634017.name", "slow_query_log"), 206 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.427634017.value", "1"), 207 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.881816039.name", "sync_binlog"), 208 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.881816039.value", "0"), 209 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.748684209.name", "tx_isolation"), 210 resource.TestCheckResourceAttr("aws_db_parameter_group.large", "parameter.748684209.value", "repeatable-read"), 211 ), 212 }, 213 }, 214 }) 215 } 216 217 func TestAccAWSDBParameterGroup_basic(t *testing.T) { 218 var v rds.DBParameterGroup 219 220 groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt()) 221 222 resource.Test(t, resource.TestCase{ 223 PreCheck: func() { testAccPreCheck(t) }, 224 Providers: testAccProviders, 225 CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, 226 Steps: []resource.TestStep{ 227 resource.TestStep{ 228 Config: testAccAWSDBParameterGroupConfig(groupName), 229 Check: resource.ComposeTestCheckFunc( 230 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), 231 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 232 resource.TestCheckResourceAttr( 233 "aws_db_parameter_group.bar", "name", groupName), 234 resource.TestCheckResourceAttr( 235 "aws_db_parameter_group.bar", "family", "mysql5.6"), 236 resource.TestCheckResourceAttr( 237 "aws_db_parameter_group.bar", "description", "Managed by Terraform"), 238 resource.TestCheckResourceAttr( 239 "aws_db_parameter_group.bar", "parameter.1708034931.name", "character_set_results"), 240 resource.TestCheckResourceAttr( 241 "aws_db_parameter_group.bar", "parameter.1708034931.value", "utf8"), 242 resource.TestCheckResourceAttr( 243 "aws_db_parameter_group.bar", "parameter.2421266705.name", "character_set_server"), 244 resource.TestCheckResourceAttr( 245 "aws_db_parameter_group.bar", "parameter.2421266705.value", "utf8"), 246 resource.TestCheckResourceAttr( 247 "aws_db_parameter_group.bar", "parameter.2478663599.name", "character_set_client"), 248 resource.TestCheckResourceAttr( 249 "aws_db_parameter_group.bar", "parameter.2478663599.value", "utf8"), 250 resource.TestCheckResourceAttr( 251 "aws_db_parameter_group.bar", "tags.%", "1"), 252 ), 253 }, 254 resource.TestStep{ 255 Config: testAccAWSDBParameterGroupAddParametersConfig(groupName), 256 Check: resource.ComposeTestCheckFunc( 257 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), 258 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 259 resource.TestCheckResourceAttr( 260 "aws_db_parameter_group.bar", "name", groupName), 261 resource.TestCheckResourceAttr( 262 "aws_db_parameter_group.bar", "family", "mysql5.6"), 263 resource.TestCheckResourceAttr( 264 "aws_db_parameter_group.bar", "description", "Test parameter group for terraform"), 265 resource.TestCheckResourceAttr( 266 "aws_db_parameter_group.bar", "parameter.1706463059.name", "collation_connection"), 267 resource.TestCheckResourceAttr( 268 "aws_db_parameter_group.bar", "parameter.1706463059.value", "utf8_unicode_ci"), 269 resource.TestCheckResourceAttr( 270 "aws_db_parameter_group.bar", "parameter.1708034931.name", "character_set_results"), 271 resource.TestCheckResourceAttr( 272 "aws_db_parameter_group.bar", "parameter.1708034931.value", "utf8"), 273 resource.TestCheckResourceAttr( 274 "aws_db_parameter_group.bar", "parameter.2421266705.name", "character_set_server"), 275 resource.TestCheckResourceAttr( 276 "aws_db_parameter_group.bar", "parameter.2421266705.value", "utf8"), 277 resource.TestCheckResourceAttr( 278 "aws_db_parameter_group.bar", "parameter.2475805061.name", "collation_server"), 279 resource.TestCheckResourceAttr( 280 "aws_db_parameter_group.bar", "parameter.2475805061.value", "utf8_unicode_ci"), 281 resource.TestCheckResourceAttr( 282 "aws_db_parameter_group.bar", "parameter.2478663599.name", "character_set_client"), 283 resource.TestCheckResourceAttr( 284 "aws_db_parameter_group.bar", "parameter.2478663599.value", "utf8"), 285 resource.TestCheckResourceAttr( 286 "aws_db_parameter_group.bar", "tags.%", "2"), 287 ), 288 }, 289 }, 290 }) 291 } 292 293 func TestAccAWSDBParameterGroup_withApplyMethod(t *testing.T) { 294 var v rds.DBParameterGroup 295 296 groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt()) 297 298 resource.Test(t, resource.TestCase{ 299 PreCheck: func() { testAccPreCheck(t) }, 300 Providers: testAccProviders, 301 CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, 302 Steps: []resource.TestStep{ 303 resource.TestStep{ 304 Config: testAccAWSDBParameterGroupConfigWithApplyMethod(groupName), 305 Check: resource.ComposeTestCheckFunc( 306 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), 307 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 308 resource.TestCheckResourceAttr( 309 "aws_db_parameter_group.bar", "name", groupName), 310 resource.TestCheckResourceAttr( 311 "aws_db_parameter_group.bar", "family", "mysql5.6"), 312 resource.TestCheckResourceAttr( 313 "aws_db_parameter_group.bar", "description", "Managed by Terraform"), 314 resource.TestCheckResourceAttr( 315 "aws_db_parameter_group.bar", "parameter.2421266705.name", "character_set_server"), 316 resource.TestCheckResourceAttr( 317 "aws_db_parameter_group.bar", "parameter.2421266705.value", "utf8"), 318 resource.TestCheckResourceAttr( 319 "aws_db_parameter_group.bar", "parameter.2421266705.apply_method", "immediate"), 320 resource.TestCheckResourceAttr( 321 "aws_db_parameter_group.bar", "parameter.2478663599.name", "character_set_client"), 322 resource.TestCheckResourceAttr( 323 "aws_db_parameter_group.bar", "parameter.2478663599.value", "utf8"), 324 resource.TestCheckResourceAttr( 325 "aws_db_parameter_group.bar", "parameter.2478663599.apply_method", "pending-reboot"), 326 ), 327 }, 328 }, 329 }) 330 } 331 332 func TestAccAWSDBParameterGroup_Only(t *testing.T) { 333 var v rds.DBParameterGroup 334 335 groupName := fmt.Sprintf("parameter-group-test-terraform-%d", acctest.RandInt()) 336 resource.Test(t, resource.TestCase{ 337 PreCheck: func() { testAccPreCheck(t) }, 338 Providers: testAccProviders, 339 CheckDestroy: testAccCheckAWSDBParameterGroupDestroy, 340 Steps: []resource.TestStep{ 341 resource.TestStep{ 342 Config: testAccAWSDBParameterGroupOnlyConfig(groupName), 343 Check: resource.ComposeTestCheckFunc( 344 testAccCheckAWSDBParameterGroupExists("aws_db_parameter_group.bar", &v), 345 testAccCheckAWSDBParameterGroupAttributes(&v, groupName), 346 resource.TestCheckResourceAttr( 347 "aws_db_parameter_group.bar", "name", groupName), 348 resource.TestCheckResourceAttr( 349 "aws_db_parameter_group.bar", "family", "mysql5.6"), 350 ), 351 }, 352 }, 353 }) 354 } 355 356 func TestResourceAWSDBParameterGroupName_validation(t *testing.T) { 357 cases := []struct { 358 Value string 359 ErrCount int 360 }{ 361 { 362 Value: "tEsting123", 363 ErrCount: 1, 364 }, 365 { 366 Value: "testing123!", 367 ErrCount: 1, 368 }, 369 { 370 Value: "1testing123", 371 ErrCount: 1, 372 }, 373 { 374 Value: "testing--123", 375 ErrCount: 1, 376 }, 377 { 378 Value: "testing123-", 379 ErrCount: 1, 380 }, 381 { 382 Value: randomString(256), 383 ErrCount: 1, 384 }, 385 } 386 387 for _, tc := range cases { 388 _, errors := validateDbParamGroupName(tc.Value, "aws_db_parameter_group_name") 389 390 if len(errors) != tc.ErrCount { 391 t.Fatalf("Expected the DB Parameter Group Name to trigger a validation error") 392 } 393 } 394 } 395 396 func testAccCheckAWSDBParameterGroupDestroy(s *terraform.State) error { 397 conn := testAccProvider.Meta().(*AWSClient).rdsconn 398 399 for _, rs := range s.RootModule().Resources { 400 if rs.Type != "aws_db_parameter_group" { 401 continue 402 } 403 404 // Try to find the Group 405 resp, err := conn.DescribeDBParameterGroups( 406 &rds.DescribeDBParameterGroupsInput{ 407 DBParameterGroupName: aws.String(rs.Primary.ID), 408 }) 409 410 if err == nil { 411 if len(resp.DBParameterGroups) != 0 && 412 *resp.DBParameterGroups[0].DBParameterGroupName == rs.Primary.ID { 413 return fmt.Errorf("DB Parameter Group still exists") 414 } 415 } 416 417 // Verify the error 418 newerr, ok := err.(awserr.Error) 419 if !ok { 420 return err 421 } 422 if newerr.Code() != "DBParameterGroupNotFound" { 423 return err 424 } 425 } 426 427 return nil 428 } 429 430 func testAccCheckAWSDBParameterGroupAttributes(v *rds.DBParameterGroup, name string) resource.TestCheckFunc { 431 return func(s *terraform.State) error { 432 433 if *v.DBParameterGroupName != name { 434 return fmt.Errorf("Bad Parameter Group name, expected (%s), got (%s)", name, *v.DBParameterGroupName) 435 } 436 437 if *v.DBParameterGroupFamily != "mysql5.6" { 438 return fmt.Errorf("bad family: %#v", v.DBParameterGroupFamily) 439 } 440 441 return nil 442 } 443 } 444 445 func testAccCheckAWSDBParameterGroupExists(n string, v *rds.DBParameterGroup) resource.TestCheckFunc { 446 return func(s *terraform.State) error { 447 rs, ok := s.RootModule().Resources[n] 448 if !ok { 449 return fmt.Errorf("Not found: %s", n) 450 } 451 452 if rs.Primary.ID == "" { 453 return fmt.Errorf("No DB Parameter Group ID is set") 454 } 455 456 conn := testAccProvider.Meta().(*AWSClient).rdsconn 457 458 opts := rds.DescribeDBParameterGroupsInput{ 459 DBParameterGroupName: aws.String(rs.Primary.ID), 460 } 461 462 resp, err := conn.DescribeDBParameterGroups(&opts) 463 464 if err != nil { 465 return err 466 } 467 468 if len(resp.DBParameterGroups) != 1 || 469 *resp.DBParameterGroups[0].DBParameterGroupName != rs.Primary.ID { 470 return fmt.Errorf("DB Parameter Group not found") 471 } 472 473 *v = *resp.DBParameterGroups[0] 474 475 return nil 476 } 477 } 478 479 func randomString(strlen int) string { 480 rand.Seed(time.Now().UTC().UnixNano()) 481 const chars = "abcdefghijklmnopqrstuvwxyz" 482 result := make([]byte, strlen) 483 for i := 0; i < strlen; i++ { 484 result[i] = chars[rand.Intn(len(chars))] 485 } 486 return string(result) 487 } 488 489 func testAccAWSDBParameterGroupConfig(n string) string { 490 return fmt.Sprintf(` 491 resource "aws_db_parameter_group" "bar" { 492 name = "%s" 493 family = "mysql5.6" 494 parameter { 495 name = "character_set_server" 496 value = "utf8" 497 } 498 parameter { 499 name = "character_set_client" 500 value = "utf8" 501 } 502 parameter{ 503 name = "character_set_results" 504 value = "utf8" 505 } 506 tags { 507 foo = "bar" 508 } 509 }`, n) 510 } 511 512 func testAccAWSDBParameterGroupConfigWithApplyMethod(n string) string { 513 return fmt.Sprintf(` 514 resource "aws_db_parameter_group" "bar" { 515 name = "%s" 516 family = "mysql5.6" 517 parameter { 518 name = "character_set_server" 519 value = "utf8" 520 } 521 parameter { 522 name = "character_set_client" 523 value = "utf8" 524 apply_method = "pending-reboot" 525 } 526 tags { 527 foo = "bar" 528 } 529 }`, n) 530 } 531 532 func testAccAWSDBParameterGroupAddParametersConfig(n string) string { 533 return fmt.Sprintf(` 534 resource "aws_db_parameter_group" "bar" { 535 name = "%s" 536 family = "mysql5.6" 537 description = "Test parameter group for terraform" 538 parameter { 539 name = "character_set_server" 540 value = "utf8" 541 } 542 parameter { 543 name = "character_set_client" 544 value = "utf8" 545 } 546 parameter{ 547 name = "character_set_results" 548 value = "utf8" 549 } 550 parameter { 551 name = "collation_server" 552 value = "utf8_unicode_ci" 553 } 554 parameter { 555 name = "collation_connection" 556 value = "utf8_unicode_ci" 557 } 558 tags { 559 foo = "bar" 560 baz = "foo" 561 } 562 }`, n) 563 } 564 565 func testAccAWSDBParameterGroupOnlyConfig(n string) string { 566 return fmt.Sprintf(` 567 resource "aws_db_parameter_group" "bar" { 568 name = "%s" 569 family = "mysql5.6" 570 description = "Test parameter group for terraform" 571 }`, n) 572 } 573 574 func createAwsDbParameterGroupsExceedDefaultAwsLimit(n string) string { 575 return fmt.Sprintf(` 576 resource "aws_db_parameter_group" "large" { 577 name = "%s" 578 family = "mysql5.6" 579 description = "RDS default parameter group: Exceed default AWS parameter group limit of twenty" 580 581 parameter { name = "binlog_cache_size" value = 131072 } 582 parameter { name = "character_set_client" value = "utf8" } 583 parameter { name = "character_set_connection" value = "utf8" } 584 parameter { name = "character_set_database" value = "utf8" } 585 parameter { name = "character_set_filesystem" value = "utf8" } 586 parameter { name = "character_set_results" value = "utf8" } 587 parameter { name = "character_set_server" value = "utf8" } 588 parameter { name = "collation_connection" value = "utf8_general_ci" } 589 parameter { name = "collation_server" value = "utf8_general_ci" } 590 parameter { name = "event_scheduler" value = "ON" } 591 parameter { name = "innodb_buffer_pool_dump_at_shutdown" value = 1 } 592 parameter { name = "innodb_file_format" value = "Barracuda" } 593 parameter { name = "innodb_flush_log_at_trx_commit" value = 0 } 594 parameter { name = "innodb_io_capacity" value = 2000 } 595 parameter { name = "innodb_io_capacity_max" value = 3000 } 596 parameter { name = "innodb_lock_wait_timeout" value = 120 } 597 parameter { name = "innodb_max_dirty_pages_pct" value = 90 } 598 parameter { name = "innodb_open_files" value = 4000 apply_method = "pending-reboot" } 599 parameter { name = "innodb_read_io_threads" value = 64 apply_method = "pending-reboot" } 600 parameter { name = "innodb_thread_concurrency" value = 0 } 601 parameter { name = "innodb_write_io_threads" value = 64 apply_method = "pending-reboot" } 602 parameter { name = "join_buffer_size" value = 16777216 } 603 parameter { name = "key_buffer_size" value = 67108864 } 604 parameter { name = "log_bin_trust_function_creators" value = 1 } 605 parameter { name = "log_warnings" value = 2 } 606 parameter { name = "log_output" value = "FILE" } 607 parameter { name = "max_allowed_packet" value = 1073741824 } 608 parameter { name = "max_connect_errors" value = 100 } 609 parameter { name = "max_connections" value = 3200 } 610 parameter { name = "max_heap_table_size" value = 67108864 } 611 parameter { name = "performance_schema" value = 1 apply_method = "pending-reboot" } 612 parameter { name = "performance_schema_users_size" value = 1048576 apply_method = "pending-reboot" } 613 parameter { name = "query_cache_limit" value = 2097152 } 614 parameter { name = "query_cache_min_res_unit" value = 512 } 615 parameter { name = "query_cache_size" value = 67108864 } 616 parameter { name = "slow_query_log" value = 1 } 617 parameter { name = "sort_buffer_size" value = 16777216 } 618 parameter { name = "sync_binlog" value = 0 } 619 parameter { name = "table_open_cache" value = 4096 } 620 parameter { name = "tmp_table_size" value = 67108864 } 621 parameter { name = "tx_isolation" value = "REPEATABLE-READ" } 622 }`, n) 623 } 624 625 func updateAwsDbParameterGroupsExceedDefaultAwsLimit(n string) string { 626 return fmt.Sprintf(` 627 resource "aws_db_parameter_group" "large" { 628 name = "%s" 629 family = "mysql5.6" 630 description = "Updated RDS default parameter group: Exceed default AWS parameter group limit of twenty" 631 parameter { name = "binlog_cache_size" value = 131072 } 632 parameter { name = "character_set_client" value = "utf8" } 633 parameter { name = "character_set_connection" value = "utf8" } 634 parameter { name = "character_set_database" value = "utf8" } 635 parameter { name = "character_set_filesystem" value = "utf8" } 636 parameter { name = "character_set_results" value = "utf8" } 637 parameter { name = "character_set_server" value = "utf8" } 638 parameter { name = "collation_connection" value = "utf8_general_ci" } 639 parameter { name = "collation_server" value = "utf8_general_ci" } 640 parameter { name = "event_scheduler" value = "ON" } 641 parameter { name = "innodb_buffer_pool_dump_at_shutdown" value = 1 } 642 parameter { name = "innodb_file_format" value = "Barracuda" } 643 parameter { name = "innodb_flush_log_at_trx_commit" value = 0 } 644 parameter { name = "innodb_io_capacity" value = 2000 } 645 parameter { name = "innodb_io_capacity_max" value = 3000 } 646 parameter { name = "innodb_lock_wait_timeout" value = 120 } 647 parameter { name = "innodb_max_dirty_pages_pct" value = 90 } 648 parameter { name = "innodb_open_files" value = 4000 apply_method = "pending-reboot" } 649 parameter { name = "innodb_read_io_threads" value = 64 apply_method = "pending-reboot" } 650 parameter { name = "innodb_thread_concurrency" value = 0 } 651 parameter { name = "innodb_write_io_threads" value = 64 apply_method = "pending-reboot" } 652 parameter { name = "join_buffer_size" value = 16777216 } 653 parameter { name = "key_buffer_size" value = 67108864 } 654 parameter { name = "log_bin_trust_function_creators" value = 1 } 655 parameter { name = "log_warnings" value = 2 } 656 parameter { name = "log_output" value = "FILE" } 657 parameter { name = "max_allowed_packet" value = 1073741824 } 658 parameter { name = "max_connect_errors" value = 100 } 659 parameter { name = "max_connections" value = 3200 } 660 parameter { name = "max_heap_table_size" value = 67108864 } 661 parameter { name = "performance_schema" value = 1 apply_method = "pending-reboot" } 662 parameter { name = "performance_schema_users_size" value = 1048576 apply_method = "pending-reboot" } 663 parameter { name = "query_cache_limit" value = 2097152 } 664 parameter { name = "query_cache_min_res_unit" value = 512 } 665 parameter { name = "query_cache_size" value = 67108864 } 666 parameter { name = "slow_query_log" value = 1 } 667 parameter { name = "sort_buffer_size" value = 16777216 } 668 parameter { name = "sync_binlog" value = 0 } 669 parameter { name = "table_open_cache" value = 4096 } 670 parameter { name = "tmp_table_size" value = 67108864 } 671 parameter { name = "tx_isolation" value = "REPEATABLE-READ" } 672 }`, n) 673 }