github.com/yorinasub17/go-cloud@v0.27.40/mysql/main.tf (about) 1 # Copyright 2020 The Go Cloud Development Kit Authors 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # https://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 15 # Harness for MySQL tests. 16 17 terraform { 18 required_version = ">= 0.13" 19 required_providers { 20 docker = { 21 source = "terraform-providers/docker" 22 version = "~> 2.0" 23 } 24 random = { 25 source = "hashicorp/random" 26 version = "~> 2.0" 27 } 28 } 29 } 30 31 variable port { 32 type = number 33 description = "Port exposed out of the MySQL container." 34 default = 3306 35 } 36 37 resource random_pet mysql {} 38 39 resource random_password db_password { 40 special = false 41 length = 20 42 } 43 44 locals { 45 db_name = "testdb" 46 } 47 48 resource docker_container mysql { 49 name = random_pet.mysql.id 50 image = docker_image.mysql.latest 51 52 env = [ 53 "MYSQL_ROOT_PASSWORD=${random_password.db_password.result}", 54 "MYSQL_DATABASE=${local.db_name}", 55 ] 56 ports { 57 internal = 3306 58 external = var.port 59 } 60 } 61 62 resource docker_image mysql { 63 name = "mysql" 64 } 65 66 output endpoint { 67 value = "localhost:${var.port}" 68 description = "The MySQL instance's host/port." 69 } 70 71 output username { 72 value = "root" 73 description = "The MySQL username to connect with." 74 } 75 76 output password { 77 value = random_password.db_password.result 78 sensitive = true 79 description = "The MySQL instance password for the user." 80 } 81 82 output database { 83 value = local.db_name 84 description = "The name of the database inside the MySQL instance." 85 } 86