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