Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement module #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ This module can create CDN domain.

| Name | Description | Type | Default | Required |
|------|-------------|:----:|:-----:|:-----:|
| region | TencentCloud region to launch resources. | string | | no
| domain | Name of the acceleration domain. | string | "" | no
| service_type | Service type of acceleration domain name. | string | "" | no
| domain | Name of the acceleration domain. | string | "" | yes
| service_type | Service type of acceleration domain name. | string | "" | yes
| full_url_cache | Whether to enable full-path cache. | bool | true | no
| area | Domain name acceleration region. | string | null | no
| origin_type | Master origin server type. | string| "" | yes|
| origin_list | Master origin server list. Valid values can be ip or domain name. When modifying the origin server, you need to enter the corresponding `origin_type`. | list(string)| [] | yes |
| server_name | Host header used when accessing the master origin server. | string | null | no
| cos_private_access | When OriginType is COS, you can specify if access to private buckets is allowed. | string | off | no
| origin_pull_protocol | Origin-pull protocol configuration. | string | http | no
| https_switch | HTTPS configuration switch. | string| "off" | no |
| origin_type | Master origin server type. | string| "" | no|
| origin_list | Master origin server list. Valid values can be ip or domain name. When modifying the origin server, you need to enter the corresponding `origin_type`. | list(string)| [] | no |

| http2_switch | HTTP2 configuration switch. | string | off | no
| ocsp_stapling_switch | OCSP configuration switch. | string | off | no
| spdy_switch | Spdy configuration switch. | string | off | no
crab21 marked this conversation as resolved.
Show resolved Hide resolved
| verify_client | Client certificate authentication feature. | string | off | no
| server_certificate_config | Server certificate configuration information. | list | [] | no
| client_certificate_config | Client certificate configuration information. | list | [] | no
| tags | Tags of cdn domain. | map | null | no
## Outputs

| Name | Description |
Expand Down
24 changes: 24 additions & 0 deletions examples/exist-cdn-domain/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# CDN Module Example

This module will create new CDN domain.
crab21 marked this conversation as resolved.
Show resolved Hide resolved

## Usage

To run this example, you need first replace the configuration like `domain`, `service_type` etc, and then execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note, this example may create resources which cost money. Run `terraform destroy` if you don't need these resources.

## Outputs

| Name | Description |
|------|-------------|
| project_id | Project CDN belongs to. |
| cname | CNAME address of domain name. |
| create_time | Domain name creation time. |
| status | Acceleration service status. |
7 changes: 7 additions & 0 deletions examples/exist-cdn-domain/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module "cdn" {
source = "../../"
domain = "test.zhaoshaona.com"
service_type = "web"
origin_type = "ip"
origin_list = ["172.199.199.130"]
}
19 changes: 19 additions & 0 deletions examples/exist-cdn-domain/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "project_id" {
description = "Project CDN belongs to."
value = module.cdn.project_id
}

output "cname" {
description = "CNAME address of domain name."
value = module.cdn.cname
}

output "create_time" {
description = "Domain name creation time."
value = module.cdn.create_time
}

output "status" {
description = "Acceleration service status."
value = module.cdn.status
}
68 changes: 62 additions & 6 deletions examples/simple-cdn-domain/main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,68 @@
provider "tencentcloud" {
region = "ap-guangzhou"
}

module "cdn" {
source = "../../"
domain = "test999.zhaoshaona.com"
domain = "test.zhaoshaona.com"
service_type = "web"
https_switch = "off"
origin_type = "ip"
origin_list = ["172.199.199.130"]

https_switch = "on"
http2_switch = "on"
server_certificate_config = [{
certificate_content = <<EOT
-----BEGIN CERTIFICATE-----
MIIDuDCCAqACCQDJd98Shn/cJTANBgkqhkiG9w0BAQsFADCBnTELMAkGA1UEBhMC
Q04xEDAOBgNVBAgMB1RpYW5qaW4xEDAOBgNVBAcMB1RpYW5qaW4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GBAMFf
7nF2aJ/k0Fcl53Cabs/FIaAwL/GBvok6Ny8wWLwiMZCtsGUUywnUdN/qbfr2GwC5
g0w2iaxGqQPI+qw2qn0utAIfZ0Tz2VAH+P3aUTuG+M4XWHObHVXxBUqO61X9zgV2
sXRXcbDOx3HgZeDCjk0otcGVJoC3zgzaaEZi5mQVAoGAQer+2gQ1PUm27XmOmL78
bI+EjHbjhpKDbL95GnDrdKtIQZz8DuXBeEo6B+M6WDxBvpa0kyByrfmKo0jbW7JS
7JTYKqDuthL2MhVLx3dMa83pNVAZ7kqtdIGFL+TzvbSxnBk5VxDuhtC6Jd1rLfMA
jBNQ6eiOy5dzFCXkrnJspq8CgYAO4ISFsihmdMIakk31+cugrHfjzRFDMUopYJMy
TDPndXH+wX4aqLjeLrw3JeAEOL7nFV6mlGOPH3iNU/8FFMeVDezHZQca5O/JGnPr
g8pQHBg0MtOZQUvGet5/V/N/ECGzhegtHTUf9yic+DieTBmKkiE5nXHy4TE3B+6R
y7YR6QKBgQDUoNAFOnMZB4BQMeCb/pQQnzNkNTG+Y02eMKjo5eZZDfyusqIui29l
KKcVGqvwVh2r8ocP7OnrQPVK9ZW7BcoYiqM2DjdKyl7AtQKnvWfPMai++oXKzo0y
8sg7m1Ic26sKO9W9t87cfZtFKcbKVcImLWucd9R7Ny4M4r6xlRKWpA==
-----END RSA PRIVATE KEY-----
EOT
message = "test"
}]

}
59 changes: 44 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,56 @@
provider "tencentcloud" {
version = ">=1.19.0"
region = var.region != "" ? var.region : null
}

resource "tencentcloud_cdn_domain" "default" {
domain = trimspace(var.domain)
service_type = var.service_type
domain = trimspace(var.domain)
service_type = var.service_type
area = var.area
full_url_cache = var.full_url_cache

origin {
origin_type = var.origin_type
origin_list = var.origin_list
origin_type = var.origin_type
origin_list = var.origin_list
server_name = var.server_name
cos_private_access = var.cos_private_access
origin_pull_protocol = var.origin_pull_protocol
}

https_config {
https_switch = var.https_switch
}
https_switch = var.https_switch
http2_switch = var.http2_switch
ocsp_stapling_switch = var.ocsp_stapling_switch
spdy_switch = var.spdy_switch
verify_client = var.verify_client

}
dynamic "server_certificate_config" {
for_each = local.server_certificate_config
content {
certificate_id = lookup(server_certificate_config.value, "certificate_id")
certificate_content = lookup(server_certificate_config.value, "certificate_content")
private_key = lookup(server_certificate_config.value, "private_key")
message = lookup(server_certificate_config.value, "message")
}
}

data "tencentcloud_cdn_domains" "foo" {
domain = local.domain
dynamic "client_certificate_config" {
for_each = local.client_certificate_config
content {
certificate_content = lookup(client_certificate_config.value, "certificate_content")
}
}
}

tags = var.tags
}

locals {
domain = tencentcloud_cdn_domain.default.domain
server_certificate_config = flatten([
for _, obj in var.server_certificate_config : {
certificate_id = lookup(obj, "certificate_id", null)
certificate_content = lookup(obj, "certificate_content", null)
private_key = lookup(obj, "private_key", null)
message = lookup(obj, "message", null)
}])

client_certificate_config = flatten([
for _, obj in var.client_certificate_config : {
certificate_content = lookup(obj, "certificate_content", null)
}])
}
80 changes: 73 additions & 7 deletions variables.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
variable "region" {
description = "TencentCloud region to launch resources."
type = string
default = ""
}

variable "domain" {
description = "Name of the acceleration domain."
type = string
Expand Down Expand Up @@ -32,4 +26,76 @@ variable "https_switch" {
description = "HTTPS configuration switch."
type = string
default = "off"
}
}

variable "server_certificate_config" {
description = "Server certificate configuration information."
type = list
default = []
}

variable "client_certificate_config" {
description = "Client certificate configuration information."
type = list
default = []
}

variable "full_url_cache" {
description = "Whether to enable full-path cache."
type = bool
default = true
}

variable "area" {
description = "Domain name acceleration region."
type = string
default = null
}

variable "tags" {
description = "Tags of cdn domain."
type = map(string)
default = null
}

variable "server_name" {
description = "Host header used when accessing the master origin server."
type = string
default = null
}

variable "cos_private_access" {
description = "When OriginType is COS, you can specify if access to private buckets is allowed."
type = string
default = "off"
}

variable "origin_pull_protocol" {
description = "Origin-pull protocol configuration."
type = string
default = "http"
}

variable "http2_switch" {
description = "HTTP2 configuration switch."
type = string
default = "off"
}

variable "ocsp_stapling_switch" {
description = "OCSP configuration switch."
type = string
default = "off"
}

variable "spdy_switch" {
description = "Spdy configuration switch."
type = string
default = "off"
}

variable "verify_client" {
description = "Client certificate authentication feature."
type = string
default = "off"
}
4 changes: 4 additions & 0 deletions version.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
terraform {
required_version = ">= 0.12"

required_providers {
tencentcloud = ">=1.19.0"
}
}