Commit e191ff1d authored by admin's avatar admin
Browse files

环境代码变更

parent a95a52ee
Showing with 530 additions and 79 deletions
+530 -79
# e5b3e0-aliyun-tencent-wordpress-ecs
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.yun.shop/eos-test/e5b3e0-aliyun-tencent-wordpress-ecs.git
git branch -M master
git push -uf origin master
# 腾讯云单机WordPress模块
## terraform-tencentcloud-tencent-wordpress-ecs
## examples
- simple
```hcl
provider "tencentcloud" {
secret_id = "xxxxxx"
secret_key = "xxxxxx"
region = "ap-shanghai"
}
module "wordpress-ecs" {
source = "../../"
instance_name = "wordpress-test"
cpu_core_count = 2
memory_size = 4
system_disk_type = "CLOUD_BSSD"
system_disk_size = 50
instance_tags = { UseFor = "wordpress" }
# vpc_id = "vpc-2xjtuwqw"
# subnet_id = "subnet-9lahjucz"
# security_group_id = "sg-p14xggro"
}
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.yun.shop/eos-test/e5b3e0-aliyun-tencent-wordpress-ecs/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Requirements
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
| Name | Version |
|------------------------------------------------------------------------------------|-----------|
| <a name="requirement_tencentcloud"></a> [tencentcloud](#requirement\_tencentcloud) | >=1.81.16 |
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Providers
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
No providers.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Modules
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
| Name | Source | Version |
|-----------------------------------------------------------------|------------------------------------------------|---------|
| <a name="module_instance"></a> [instance](#module\_instance) | ./modules/terraform-tencentcloud-spot-instance | n/a |
| <a name="module_wordpress"></a> [wordpress](#module\_wordpress) | ./modules/terraform-tencentcloud-wordpress | n/a |
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
## Resources
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
No resources.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Inputs
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
| Name | Description | Type | Default | Required |
|-------------------------------------------------------------------------------------------|------------------|---------------|----------------|:--------:|
| <a name="input_cpu_core_count"></a> [cpu\_core\_count](#input\_cpu\_core\_count) | CPU核心数 | `number` | `2` | no |
| <a name="input_instance_name"></a> [instance\_name](#input\_instance\_name) | 实例名称 | `string` | `"wordpress"` | no |
| <a name="input_instance_tags"></a> [instance\_tags](#input\_instance\_tags) | 实例标签 | `map(string)` | `{}` | no |
| <a name="input_memory_size"></a> [memory\_size](#input\_memory\_size) | 内存大小 | `number` | `4` | no |
| <a name="input_security_group_id"></a> [security\_group\_id](#input\_security\_group\_id) | 安全组SecurityGroup | `string` | `null` | no |
| <a name="input_subnet_id"></a> [subnet\_id](#input\_subnet\_id) | 子网Subnet | `string` | `null` | no |
| <a name="input_system_disk_size"></a> [system\_disk\_size](#input\_system\_disk\_size) | 系统盘大小 | `number` | `50` | no |
| <a name="input_system_disk_type"></a> [system\_disk\_type](#input\_system\_disk\_type) | 系统盘类型 | `string` | `"CLOUD_BSSD"` | no |
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | 私有网络VPC | `string` | `null` | no |
## License
For open source projects, say how it is licensed.
## Outputs
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
| Name | Description |
|---------------------------------------------------------------------------------------------------|----------------|
| <a name="output_instance_id"></a> [instance\_id](#output\_instance\_id) | 实例ID |
| <a name="output_instance_name"></a> [instance\_name](#output\_instance\_name) | 实例名称 |
| <a name="output_instance_password"></a> [instance\_password](#output\_instance\_password) | 实例密码 |
| <a name="output_mysql_database"></a> [mysql\_database](#output\_mysql\_database) | mysql数据库名 |
| <a name="output_mysql_password"></a> [mysql\_password](#output\_mysql\_password) | mysql密码 |
| <a name="output_mysql_username"></a> [mysql\_username](#output\_mysql\_username) | mysql账号 |
| <a name="output_nginx_dir"></a> [nginx\_dir](#output\_nginx\_dir) | Nginx目录 |
| <a name="output_wordpress_admin_url"></a> [wordpress\_admin\_url](#output\_wordpress\_admin\_url) | WordPress管理员地址 |
| <a name="output_wordpress_dir"></a> [wordpress\_dir](#output\_wordpress\_dir) | WordPress目录 |
| <a name="output_wordpress_url"></a> [wordpress\_url](#output\_wordpress\_url) | WordPress地址 |
## Requirements
| Name | Version |
|------------------------------------------------------------------------------------|-----------|
| <a name="requirement_tencentcloud"></a> [tencentcloud](#requirement\_tencentcloud) | >=1.81.16 |
## Providers
No providers.
## Modules
| Name | Source | Version |
|-----------------------------------------------------------------------------|--------|---------|
| <a name="module_wordpress-ecs"></a> [wordpress-ecs](#module\_wordpress-ecs) | ../../ | n/a |
## Resources
No resources.
## Inputs
No inputs.
## Outputs
| Name | Description |
|---------------------------------------------------------------------------------------------------|----------------|
| <a name="output_instance_id"></a> [instance\_id](#output\_instance\_id) | 实例ID |
| <a name="output_instance_name"></a> [instance\_name](#output\_instance\_name) | 实例名称 |
| <a name="output_instance_password"></a> [instance\_password](#output\_instance\_password) | 实例密码 |
| <a name="output_mysql_database"></a> [mysql\_database](#output\_mysql\_database) | mysql数据库名 |
| <a name="output_mysql_password"></a> [mysql\_password](#output\_mysql\_password) | mysql密码 |
| <a name="output_mysql_username"></a> [mysql\_username](#output\_mysql\_username) | mysql账号 |
| <a name="output_nginx_dir"></a> [nginx\_dir](#output\_nginx\_dir) | Nginx目录 |
| <a name="output_wordpress_admin_url"></a> [wordpress\_admin\_url](#output\_wordpress\_admin\_url) | WordPress管理员地址 |
| <a name="output_wordpress_dir"></a> [wordpress\_dir](#output\_wordpress\_dir) | WordPress目录 |
| <a name="output_wordpress_url"></a> [wordpress\_url](#output\_wordpress\_url) | WordPress地址 |
provider "tencentcloud" {
secret_id = "xxxxxx"
secret_key = "xxxxxx"
region = "ap-shanghai"
}
module "wordpress-ecs" {
source = "../../"
instance_name = "wordpress-test"
cpu_core_count = 2
memory_size = 4
system_disk_type = "CLOUD_BSSD"
system_disk_size = 50
instance_tags = { UseFor = "wordpress" }
# vpc_id = "vpc-2xjtuwqw"
# subnet_id = "subnet-9lahjucz"
# security_group_id = "sg-p14xggro"
}
\ No newline at end of file
output "instance_id" {
value = module.wordpress-ecs.instance_id
description = "实例ID"
}
output "instance_name" {
value = module.wordpress-ecs.instance_name
description = "实例名称"
}
output "instance_password" {
value = module.wordpress-ecs.instance_password
description = "实例密码"
}
output "wordpress_url" {
value = module.wordpress-ecs.wordpress_url
description = "WordPress地址"
}
output "wordpress_admin_url" {
value = module.wordpress-ecs.wordpress_admin_url
description = "WordPress管理员地址"
}
output "wordpress_dir" {
value = module.wordpress-ecs.wordpress_dir
description = "WordPress目录"
}
output "nginx_dir" {
value = module.wordpress-ecs.nginx_dir
description = "Nginx目录"
}
output "mysql_username" {
value = module.wordpress-ecs.mysql_username
description = "mysql账号"
}
output "mysql_password" {
value = module.wordpress-ecs.instance_id
description = "mysql密码"
}
output "mysql_database" {
value = module.wordpress-ecs.mysql_database
description = "mysql数据库名"
}
\ No newline at end of file
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = ">=1.81.16"
}
}
}
\ No newline at end of file
main.tf 0 → 100644
module "wordpress" {
source = "./modules/terraform-tencentcloud-wordpress"
}
module "instance" {
source = "./modules/terraform-tencentcloud-spot-instance"
image_id = module.wordpress.image_id
vpc_id = var.vpc_id
subnet_id = var.subnet_id
security_group_id = var.security_group_id
cpu_core_count = var.cpu_core_count
memory_size = var.memory_size
system_disk_type = var.system_disk_type
system_disk_size = var.system_disk_size
instance_name = var.instance_name
instance_tags = var.instance_tags
}
\ No newline at end of file
locals {
has_spot = length(data.tencentcloud_instance_types.spot.instance_types)>0
availability_zone = local.has_spot? data.tencentcloud_instance_types.spot.instance_types[0].availability_zone : data.tencentcloud_instance_types.od.instance_types[0].availability_zone
instance_type = local.has_spot? data.tencentcloud_instance_types.spot.instance_types[0].instance_type : data.tencentcloud_instance_types.od.instance_types[0].instance_type
instance_charge_type = local.has_spot? data.tencentcloud_instance_types.spot.instance_types[0].instance_charge_type : data.tencentcloud_instance_types.od.instance_types[0].instance_charge_type
}
############################################################
# spot寻址,当spot不足,转为onDemand
############################################################
data "tencentcloud_instance_types" "spot" {
cpu_core_count = var.cpu_core_count
memory_size = var.memory_size
exclude_sold_out = true
filter {
name = "instance-charge-type"
values = ["SPOTPAID"]
}
}
data "tencentcloud_instance_types" "od" {
cpu_core_count = var.cpu_core_count
memory_size = var.memory_size
exclude_sold_out = true
filter {
name = "instance-charge-type"
values = ["POSTPAID_BY_HOUR"]
}
}
############################################################
# 网络,vpc、subnet、security_group可选,不传时自动创建
############################################################
resource "random_integer" "this" {
max = 99999
min = 10000
}
resource "tencentcloud_vpc" "vpc" {
count = var.vpc_id!=null? 0 : 1
cidr_block = var.vpc_cidr_block
name = "Vpc-${random_integer.this.result}"
}
resource "tencentcloud_subnet" "subnet" {
count = var.subnet_id!=null? 0 : 1
vpc_id = tencentcloud_vpc.vpc[0].id
availability_zone = local.availability_zone
cidr_block = var.subnet_cidr_block
name = "Subnet-${random_integer.this.result}"
}
resource "tencentcloud_security_group" "security_group" {
count = var.security_group_id!=null? 0 : 1
name = "SecurityGroup-${random_integer.this.result}"
}
# 开放全部端口
resource "tencentcloud_security_group_lite_rule" "security_group_lite_rule" {
count = var.security_group_id!=null? 0 : 1
security_group_id = tencentcloud_security_group.security_group[0].id
ingress = ["ACCEPT#0.0.0.0/0#ALL#ALL"]
egress = ["ACCEPT#0.0.0.0/0#ALL#ALL"]
}
############################################################
# 创建实例
############################################################
resource "tencentcloud_instance" "instance" {
availability_zone = local.availability_zone
instance_charge_type = local.instance_charge_type
instance_type = local.instance_type
image_id = var.image_id
instance_name = var.instance_name
password = var.instance_password
vpc_id = var.vpc_id!=null? var.vpc_id : tencentcloud_vpc.vpc[0].id
subnet_id = var.subnet_id!=null? var.subnet_id : tencentcloud_subnet.subnet[0].id
orderly_security_groups = [
var.security_group_id!=null? var.security_group_id : tencentcloud_security_group.security_group[0].id
]
system_disk_type = var.system_disk_type
system_disk_size = var.system_disk_size
allocate_public_ip = true
internet_charge_type = "TRAFFIC_POSTPAID_BY_HOUR"
internet_max_bandwidth_out = 10
tags = merge({ Type = local.has_spot?"spot" : "onDemand" }, var.instance_tags)
}
\ No newline at end of file
output "instance_id" {
value = tencentcloud_instance.instance.id
description = "实例ID"
}
output "instance_name" {
value = tencentcloud_instance.instance.instance_name
description = "实例名称"
}
output "instance_password" {
value = var.instance_password
description = "实例密码"
}
output "instance_tags" {
value = tencentcloud_instance.instance.tags
description = "实例标签"
}
output "private_ip" {
value = tencentcloud_instance.instance.private_ip
description = "私有IP"
}
output "public_ip" {
value = tencentcloud_instance.instance.public_ip
description = "公网IP"
}
\ No newline at end of file
variable "vpc_id" {
type = string
description = "私有网络VPC"
default = null
}
variable "vpc_cidr_block" {
type = string
description = "VPC网段"
default = "172.16.0.0/12"
}
variable "subnet_id" {
type = string
description = "子网Subnet"
default = null
}
variable "subnet_cidr_block" {
type = string
description = "Subnet网段"
default = "172.16.0.0/24"
}
variable "security_group_id" {
type = string
description = "安全组SecurityGroup"
default = null
}
variable "image_id" {
type = string
description = "镜像id"
nullable = false
}
variable "cpu_core_count" {
type = number
description = "CPU核心数"
}
variable "memory_size" {
type = number
description = "内存大小"
}
variable "instance_name" {
type = string
description = "实例名称"
default = ""
}
variable "instance_password" {
type = string
description = "实例密码"
default = null
}
variable "system_disk_type" {
type = string
description = "系统盘类型"
}
variable "system_disk_size" {
type = number
description = "系统盘大小"
}
variable "instance_tags" {
type = map(string)
description = "实例标签"
default = {}
}
\ No newline at end of file
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = ">=1.81.16"
}
}
}
\ No newline at end of file
output "image_id" {
value = "img-ierr6c85"
description = "镜像id"
}
output "mysql_username" {
value = "root"
description = "mysql账号"
}
output "mysql_database" {
value = "wordpress"
description = "mysql数据库名"
}
output "wordpress_dir" {
value = "/var/www/wordpress"
description = "WordPress目录"
}
output "nginx_dir" {
value = "/etc/nginx"
description = "Nginx目录"
}
\ No newline at end of file
outputs.tf 0 → 100644
output "instance_id" {
value = module.instance.instance_id
description = "实例ID"
}
output "instance_name" {
value = module.instance.instance_name
description = "实例名称"
}
output "instance_password" {
value = module.instance.instance_password
description = "实例密码"
}
output "wordpress_url" {
value = format("http://%s", module.instance.public_ip)
description = "WordPress地址"
}
output "wordpress_admin_url" {
value = format("http://%s/wp-admin", module.instance.public_ip)
description = "WordPress管理员地址"
}
output "wordpress_dir" {
value = module.wordpress.wordpress_dir
description = "WordPress目录"
}
output "nginx_dir" {
value = module.wordpress.nginx_dir
description = "Nginx目录"
}
output "mysql_username" {
value = module.wordpress.mysql_username
description = "mysql账号"
}
output "mysql_password" {
value = module.instance.instance_id
description = "mysql密码"
}
output "mysql_database" {
value = module.wordpress.mysql_database
description = "mysql数据库名"
}
\ No newline at end of file
variable "vpc_id" {
type = string
description = "私有网络VPC"
default = null
}
variable "subnet_id" {
type = string
description = "子网Subnet"
default = null
}
variable "security_group_id" {
type = string
description = "安全组SecurityGroup"
default = null
}
variable "cpu_core_count" {
type = number
description = "CPU核心数"
default = 2
}
variable "memory_size" {
type = number
description = "内存大小"
default = 4
}
variable "instance_name" {
type = string
description = "实例名称"
default = "wordpress"
}
variable "system_disk_type" {
type = string
description = "系统盘类型"
default = "CLOUD_BSSD"
}
variable "system_disk_size" {
type = number
description = "系统盘大小"
default = 50
}
variable "instance_tags" {
type = map(string)
description = "实例标签"
default = {}
}
\ No newline at end of file
terraform {
required_providers {
tencentcloud = {
source = "tencentcloudstack/tencentcloud"
version = ">=1.81.16"
}
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment