aliyun / terraform-provider-alicloud

Terraform AliCloud provider
https://www.terraform.io/docs/providers/alicloud/
Mozilla Public License 2.0
587 stars 553 forks source link

Feature Request: DCDN management #1623

Open justabaka opened 5 years ago

justabaka commented 5 years ago

Hi there, I think that DCDN domains are not supported/not being created as intended. A quick AddDcdnDomain search gave me nothing yet I've still tried to use alicloud_cdn_domain_new.

Terraform Version

Terraform v0.12.7
+ provider.alicloud v1.55.1

Affected Resource(s)

Terraform Configuration Files

resource "alicloud_cdn_domain_new" "www_example_com" {
  domain_name = var.domain_name
  cdn_type    = "web"
  scope       = "overseas"

  sources {
    content  = "47.52.138.33"
    type     = "ipaddr"
    priority = 20
    port     = 443
    weight   = 10
  }

  certificate_config {
    server_certificate_status = "on"
    cert_type = "upload"
    force_set = 0

    cert_name = var.certificate_name
    server_certificate = "${file("certs/fullchain.pem")}"
    private_key  = "${file("certs/privkey.pem")}"
  }
}

resource "alicloud_cdn_domain_config" "dcdn" {
  domain_name   = alicloud_cdn_domain_new.www_example_com.domain_name
  function_name = "dynamic"
  function_args {
    arg_name  = "enable"
    arg_value = "on"
  }

  function_args{
    arg_name = "dynamic_route_origin"
    arg_value = "https"
  }

  function_args {
    arg_name = "static_route_type"
    arg_value = "mp3,wma,flv,mp4,wmv,ogg,avi,doc,docx,xls,xlsx,ppt,pptx,txt,pdf,zip,exe,tat,ico,css,js,swf,gif,png,bmp,jpg,jpeg"
  }

  function_args {
    arg_name = "static_route_path"
    arg_value = "/frontend,/default,/pages,/global,/products"
  }
}

resource "alicloud_cdn_domain_config" "nocache_rules_by_route" {
  domain_name   = alicloud_cdn_domain_new.www_example_com.domain_name
  function_name = "path_based_ttl_set"
  function_args {
    arg_name  = "ttl"
    arg_value = 0  # don't cache
  }

  function_args {
    arg_name = "path"
    arg_value = "/customers,/health"
  }

  function_args {
    arg_name = "weight"
    arg_value = 99
  }
}
...

Expected Behavior

A DCDN entity is created and managed.

Actual Behavior

A regular CDN entity is created which is instantly conflicting with its own rules. This output is snown after a second terraform plan/apply is run:

Terraform will perform the following actions:

# alicloud_cdn_domain_config.cache_rules_by_route_default will be updated in-place
~ resource "alicloud_cdn_domain_config" "cache_rules_by_route_default" {
    domain_name   = "www.example.com"
    function_name = "path_based_ttl_set"
    id            = "www.example.com:path_based_ttl_set"

    + function_args {
        + arg_name  = "path"
        + arg_value = "/"
    }
    - function_args {
        - arg_name  = "path" -> null
        - arg_value = "/customers,/supportcontactnew,/supportcancelsubscription,/reviewerscopy,/api/v1,/health,/success.html,/search" -> null
    }
    - function_args {
        - arg_name  = "ttl" -> null
        - arg_value = "0" -> null
    }
    + function_args {
        + arg_name  = "ttl"
        + arg_value = "86400"
    }
    function_args {
        arg_name  = "weight"
        arg_value = "99"
    }
}

# alicloud_cdn_domain_config.http2 must be replaced
-/+ resource "alicloud_cdn_domain_config" "http2" {
    domain_name   = "www.example.com"
    function_name = "https_option"
    ~ id            = "www.example.com:https_option" -> (known after apply)

    <...> 
} 

# alicloud_cdn_domain_config.nocache_rules_by_route will be updated in-place
~ resource "alicloud_cdn_domain_config" "nocache_rules_by_route" {
    domain_name   = "www.example.com"
    function_name = "path_based_ttl_set"
    id            = "www.example.com:path_based_ttl_set"

    - function_args {
        - arg_name  = "path" -> null
        - arg_value = "/" -> null
    }
    + function_args {
        + arg_name  = "path"
        + arg_value = "/customers,/health"
    }
    + function_args {
        + arg_name  = "ttl"
        + arg_value = "0"
    }
    - function_args {
        - arg_name  = "ttl" -> null
        - arg_value = "86400" -> null
    }
    function_args {
        arg_name  = "weight"
        arg_value = "99"
    }
}

Steps to Reproduce

  1. terraform apply to create a domain
  2. terraform apply to see the diff
Lexsss commented 5 years ago

Hi @justabaka , I've tried to reproduce the problem with

Terraform v0.12.7
+ provider.alicloud v1.55.1

but after apply twice I got Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Now please check the .tfstate file generate by terraform after first apply, if something wrong, we can find why the state file got error.

And you should run terraform plan after first apply, we can see the different between 2 applies and analyze the cause of the problem.

justabaka commented 5 years ago

Thank you for the reply @Lexsss, could you please check and confirm that you have a DCDN after applying your configuration? Regular CDN is a slightly different thing and the API calls used to create them are different.

Lexsss commented 5 years ago

Hi, @justabaka , Our project does not yet support DCDN, We will support it in future versions, thank you for your support.

xijia37 commented 4 years ago

Hi, @justabaka , Our project does not yet support DCDN, We will support it in future versions, thank you for your support.

when will that be?

martinkubrak commented 4 years ago

DCDN resource needed here as well!