Commit d187bc9d authored by admin's avatar admin
Browse files

环境代码变更

No related merge requests found
Showing with 222 additions and 0 deletions
+222 -0
main.tf 0 → 100644
#module "group" {
# source = "./modules/resource_group"
# group_name = var.group_name
#}
module "key-pair" {
source = "./modules/resource_key-pair"
public_key = var.public_key
group_name = "default"
}
module "vpc" {
source = "./modules/resource_vpc"
group_name = "default"
cidr_block = var.vpc_cidr
vpc_name = var.vpc_name
}
module "vswitch" {
source = "./modules/resource_vswitch"
for_each = var.vswitches
vswitch_name = each.key
cidr_block = each.value.cidr
vpc_name = var.vpc_name
zone_id = each.value.zone_id
depends_on = [module.vpc]
}
module "security_group" {
source = "./modules/resource_security-group"
name = var.security_group_name
vpc_name = var.vpc_name
depends_on = [module.vpc]
}
\ No newline at end of file
resource "alicloud_resource_manager_resource_group" "instance" {
resource_group_name = var.group_name
display_name = var.group_name
}
\ No newline at end of file
output "resource_group_id" {
value = alicloud_resource_manager_resource_group.instance.id
}
\ No newline at end of file
variable "group_name" {
type = string
default = "ydd"
description = "资源组名称"
}
\ No newline at end of file
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.212.0"
}
}
}
\ No newline at end of file
data "alicloud_resource_manager_resource_groups" "group" {
name_regex = var.group_name
}
resource "alicloud_ecs_key_pair" "instance" {
resource_group_id = data.alicloud_resource_manager_resource_groups.group.groups[0].id
key_pair_name = var.key-pair_name
public_key = var.public_key
}
\ No newline at end of file
output "ecs_key_pair_id" {
value = alicloud_ecs_key_pair.instance.id
}
\ No newline at end of file
variable "group_name" {
type = string
description = "资源组名称"
}
variable "key-pair_name" {
type = string
default = "yddpro"
description = "密钥对名称"
}
variable "public_key" {
type = string
description = "需要导入的公钥内容"
}
\ No newline at end of file
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.212.0"
}
}
}
\ No newline at end of file
data "alicloud_vpcs" "info"{
vpc_name = var.vpc_name
}
resource "alicloud_security_group" "instance" {
name = var.name
vpc_id = data.alicloud_vpcs.info.vpcs.0.id
}
resource "alicloud_security_group_rule" "rules" {
for_each = var.rules
type = each.value.type
ip_protocol = each.value.ip_protocol
nic_type = each.value.nic_type
policy = each.value.policy
port_range = each.value.port_range
priority = each.value.priority
cidr_ip = each.value.cidr_ip
security_group_id = alicloud_security_group.instance.id
}
\ No newline at end of file
output "security_group_id" {
value = alicloud_security_group.instance.id
}
\ No newline at end of file
variable "name" {
type = string
description = "安全组名称"
}
variable "vpc_name" {
type = string
description = "安全组所作用的子网"
}
variable "rules" {
type = map(object({
type = string
ip_protocol = string
nic_type = string
policy = string
port_range = string
priority = number
cidr_ip = string
}))
default = {
rule1 = {
type = "ingress",
ip_protocol = "all"
nic_type = "intranet"
policy = "accept"
port_range = "-1/-1"
priority = 1
cidr_ip = "0.0.0.0/0"
}
}
description = "安全组规则"
}
\ No newline at end of file
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.212.0"
}
}
}
\ No newline at end of file
data "alicloud_resource_manager_resource_groups" "group" {
name_regex = var.group_name
}
resource "alicloud_vpc" "instance" {
vpc_name = var.vpc_name
cidr_block = var.cidr_block
resource_group_id = data.alicloud_resource_manager_resource_groups.group.groups[0].id
}
\ No newline at end of file
output "vpc_id" {
value = alicloud_vpc.instance.id
}
\ No newline at end of file
variable "vpc_name" {
type = string
description = "专有网络名称"
}
variable "cidr_block" {
type = string
description = "专有网络子网划分"
}
variable "group_name" {
type = string
description = "资源组名称"
}
\ No newline at end of file
terraform {
required_providers {
alicloud = {
source = "aliyun/alicloud"
version = "1.212.0"
}
}
}
\ No newline at end of file
data "alicloud_vpcs" "info"{
vpc_name = var.vpc_name
}
resource "alicloud_vswitch" "instance" {
vswitch_name = var.vswitch_name
cidr_block = var.cidr_block
vpc_id = data.alicloud_vpcs.info.vpcs.0.id
zone_id = var.zone_id
}
\ No newline at end of file
output "resource_vswitch_id" {
value = alicloud_vswitch.instance.id
}
\ No newline at end of file
variable "cidr_block" {
type = string
description = "专有网络子网划分"
}
variable "vpc_name" {
type = string
description = "专有网络子网id"
}
variable "vswitch_name" {
type = string
description = "虚拟交换机名称"
}
variable "zone_id" {
type = string
description = "交换机区划id"
}
\ 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