github.com/yorinasub17/go-cloud@v0.27.40/mysql/awsmysql/main.tf (about)

     1  # Copyright 2018 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.12"
    19  }
    20  
    21  provider "aws" {
    22    version = "~> 2.7"
    23    region  = var.region
    24  }
    25  
    26  provider "random" {
    27    version = "~> 2.1"
    28  }
    29  
    30  variable "region" {
    31    type        = string
    32    description = "Region to create resources in. See https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html for valid values."
    33  }
    34  
    35  resource "aws_security_group" "main" {
    36    name_prefix = "testdb"
    37    description = "Security group for the Go CDK MySQL test database."
    38  
    39    ingress {
    40      from_port   = 3306
    41      to_port     = 3306
    42      protocol    = "tcp"
    43      cidr_blocks = ["0.0.0.0/0"]
    44      description = "Public MySQL access"
    45    }
    46  
    47    egress {
    48      from_port   = 0
    49      to_port     = 0
    50      protocol    = "-1"
    51      cidr_blocks = ["0.0.0.0/0"]
    52      description = "All outgoing traffic allowed"
    53    }
    54  }
    55  
    56  resource "random_string" "db_password" {
    57    keepers = {
    58      region = var.region
    59    }
    60  
    61    special = false
    62    length  = 20
    63  }
    64  
    65  resource "aws_db_instance" "main" {
    66    identifier_prefix      = "go-cloud-test"
    67    engine                 = "mysql"
    68    engine_version         = "5.6.39"
    69    instance_class         = "db.t2.micro"
    70    allocated_storage      = 20
    71    username               = "root"
    72    password               = random_string.db_password.result
    73    name                   = "testdb"
    74    publicly_accessible    = true
    75    vpc_security_group_ids = [aws_security_group.main.id]
    76    skip_final_snapshot    = true
    77  }
    78  
    79  output "endpoint" {
    80    value       = aws_db_instance.main.endpoint
    81    description = "The RDS instance's host/port."
    82  }
    83  
    84  output "username" {
    85    value       = "root"
    86    description = "The MySQL username to connect with."
    87  }
    88  
    89  output "password" {
    90    value       = random_string.db_password.result
    91    sensitive   = true
    92    description = "The RDS instance password for the user."
    93  }
    94  
    95  output "database" {
    96    value       = "testdb"
    97    description = "The name of the database inside the RDS instance."
    98  }
    99