provider/azurerm: Fix CDN resources
This commit is contained in:
parent
0691c0eb91
commit
6ee2bd4a55
|
@ -45,9 +45,9 @@ func Provider() terraform.ResourceProvider {
|
||||||
|
|
||||||
ResourcesMap: map[string]*schema.Resource{
|
ResourcesMap: map[string]*schema.Resource{
|
||||||
// These resources use the Azure ARM SDK
|
// These resources use the Azure ARM SDK
|
||||||
"azurerm_availability_set": resourceArmAvailabilitySet(),
|
"azurerm_availability_set": resourceArmAvailabilitySet(),
|
||||||
//"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
|
"azurerm_cdn_endpoint": resourceArmCdnEndpoint(),
|
||||||
//"azurerm_cdn_profile": resourceArmCdnProfile(),
|
"azurerm_cdn_profile": resourceArmCdnProfile(),
|
||||||
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
"azurerm_local_network_gateway": resourceArmLocalNetworkGateway(),
|
||||||
"azurerm_network_interface": resourceArmNetworkInterface(),
|
"azurerm_network_interface": resourceArmNetworkInterface(),
|
||||||
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
|
"azurerm_network_security_group": resourceArmNetworkSecurityGroup(),
|
||||||
|
|
|
@ -1,451 +1,434 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "bytes"
|
"bytes"
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "log"
|
"log"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "strings"
|
"strings"
|
||||||
// "time"
|
|
||||||
//
|
"github.com/Azure/azure-sdk-for-go/arm/cdn"
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/cdn"
|
"github.com/hashicorp/terraform/helper/hashcode"
|
||||||
// "github.com/hashicorp/terraform/helper/hashcode"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
)
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
|
||||||
//)
|
func resourceArmCdnEndpoint() *schema.Resource {
|
||||||
//
|
return &schema.Resource{
|
||||||
//func resourceArmCdnEndpoint() *schema.Resource {
|
Create: resourceArmCdnEndpointCreate,
|
||||||
// return &schema.Resource{
|
Read: resourceArmCdnEndpointRead,
|
||||||
// Create: resourceArmCdnEndpointCreate,
|
Update: resourceArmCdnEndpointUpdate,
|
||||||
// Read: resourceArmCdnEndpointRead,
|
Delete: resourceArmCdnEndpointDelete,
|
||||||
// Update: resourceArmCdnEndpointUpdate,
|
|
||||||
// Delete: resourceArmCdnEndpointDelete,
|
Schema: map[string]*schema.Schema{
|
||||||
//
|
"name": {
|
||||||
// Schema: map[string]*schema.Schema{
|
Type: schema.TypeString,
|
||||||
// "name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"location": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "location": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
StateFunc: azureRMNormalizeLocation,
|
||||||
// ForceNew: true,
|
},
|
||||||
// StateFunc: azureRMNormalizeLocation,
|
|
||||||
// },
|
"resource_group_name": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "resource_group_name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"profile_name": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "profile_name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"origin_host_header": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "origin_host_header": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeString,
|
Computed: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Computed: true,
|
|
||||||
// },
|
"is_http_allowed": {
|
||||||
//
|
Type: schema.TypeBool,
|
||||||
// "is_http_allowed": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeBool,
|
Default: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Default: true,
|
|
||||||
// },
|
"is_https_allowed": {
|
||||||
//
|
Type: schema.TypeBool,
|
||||||
// "is_https_allowed": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeBool,
|
Default: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Default: true,
|
|
||||||
// },
|
"origin": {
|
||||||
//
|
Type: schema.TypeSet,
|
||||||
// "origin": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeSet,
|
Elem: &schema.Resource{
|
||||||
// Required: true,
|
Schema: map[string]*schema.Schema{
|
||||||
// Elem: &schema.Resource{
|
"name": {
|
||||||
// Schema: map[string]*schema.Schema{
|
Type: schema.TypeString,
|
||||||
// "name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
},
|
||||||
// Required: true,
|
|
||||||
// },
|
"host_name": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "host_name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
},
|
||||||
// Required: true,
|
|
||||||
// },
|
"http_port": {
|
||||||
//
|
Type: schema.TypeInt,
|
||||||
// "http_port": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeInt,
|
Computed: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Computed: true,
|
|
||||||
// },
|
"https_port": {
|
||||||
//
|
Type: schema.TypeInt,
|
||||||
// "https_port": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeInt,
|
Computed: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Computed: true,
|
},
|
||||||
// },
|
},
|
||||||
// },
|
Set: resourceArmCdnEndpointOriginHash,
|
||||||
// },
|
},
|
||||||
// Set: resourceArmCdnEndpointOriginHash,
|
|
||||||
// },
|
"origin_path": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "origin_path": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeString,
|
Computed: true,
|
||||||
// Optional: true,
|
},
|
||||||
// Computed: true,
|
|
||||||
// },
|
"querystring_caching_behaviour": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "querystring_caching_behaviour": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeString,
|
Default: "IgnoreQueryString",
|
||||||
// Optional: true,
|
ValidateFunc: validateCdnEndpointQuerystringCachingBehaviour,
|
||||||
// Default: "IgnoreQueryString",
|
},
|
||||||
// ValidateFunc: validateCdnEndpointQuerystringCachingBehaviour,
|
|
||||||
// },
|
"content_types_to_compress": {
|
||||||
//
|
Type: schema.TypeSet,
|
||||||
// "content_types_to_compress": &schema.Schema{
|
Optional: true,
|
||||||
// Type: schema.TypeSet,
|
Computed: true,
|
||||||
// Optional: true,
|
Elem: &schema.Schema{
|
||||||
// Computed: true,
|
Type: schema.TypeString,
|
||||||
// Elem: &schema.Schema{Type: schema.TypeString},
|
},
|
||||||
// Set: schema.HashString,
|
Set: schema.HashString,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "is_compression_enabled": &schema.Schema{
|
"is_compression_enabled": {
|
||||||
// Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
// Optional: true,
|
Optional: true,
|
||||||
// Default: false,
|
Default: false,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "host_name": &schema.Schema{
|
"host_name": {
|
||||||
// Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
// Computed: true,
|
Computed: true,
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// "tags": tagsSchema(),
|
"tags": tagsSchema(),
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func resourceArmCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
|
func resourceArmCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
// client := meta.(*ArmClient)
|
client := meta.(*ArmClient)
|
||||||
// cdnEndpointsClient := client.cdnEndpointsClient
|
cdnEndpointsClient := client.cdnEndpointsClient
|
||||||
//
|
|
||||||
// log.Printf("[INFO] preparing arguments for Azure ARM CDN EndPoint creation.")
|
log.Printf("[INFO] preparing arguments for Azure ARM CDN EndPoint creation.")
|
||||||
//
|
|
||||||
// name := d.Get("name").(string)
|
name := d.Get("name").(string)
|
||||||
// location := d.Get("location").(string)
|
location := d.Get("location").(string)
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// profileName := d.Get("profile_name").(string)
|
profileName := d.Get("profile_name").(string)
|
||||||
// http_allowed := d.Get("is_http_allowed").(bool)
|
http_allowed := d.Get("is_http_allowed").(bool)
|
||||||
// https_allowed := d.Get("is_https_allowed").(bool)
|
https_allowed := d.Get("is_https_allowed").(bool)
|
||||||
// compression_enabled := d.Get("is_compression_enabled").(bool)
|
compression_enabled := d.Get("is_compression_enabled").(bool)
|
||||||
// caching_behaviour := d.Get("querystring_caching_behaviour").(string)
|
caching_behaviour := d.Get("querystring_caching_behaviour").(string)
|
||||||
// tags := d.Get("tags").(map[string]interface{})
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
//
|
|
||||||
// properties := cdn.EndpointPropertiesCreateUpdateParameters{
|
properties := cdn.EndpointPropertiesCreateUpdateParameters{
|
||||||
// IsHTTPAllowed: &http_allowed,
|
IsHTTPAllowed: &http_allowed,
|
||||||
// IsHTTPSAllowed: &https_allowed,
|
IsHTTPSAllowed: &https_allowed,
|
||||||
// IsCompressionEnabled: &compression_enabled,
|
IsCompressionEnabled: &compression_enabled,
|
||||||
// QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
|
QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
|
origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
|
||||||
// if originsErr != nil {
|
if originsErr != nil {
|
||||||
// return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
|
return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
|
||||||
// }
|
}
|
||||||
// if len(origins) > 0 {
|
if len(origins) > 0 {
|
||||||
// properties.Origins = &origins
|
properties.Origins = &origins
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if v, ok := d.GetOk("origin_host_header"); ok {
|
if v, ok := d.GetOk("origin_host_header"); ok {
|
||||||
// host_header := v.(string)
|
host_header := v.(string)
|
||||||
// properties.OriginHostHeader = &host_header
|
properties.OriginHostHeader = &host_header
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if v, ok := d.GetOk("origin_path"); ok {
|
if v, ok := d.GetOk("origin_path"); ok {
|
||||||
// origin_path := v.(string)
|
origin_path := v.(string)
|
||||||
// properties.OriginPath = &origin_path
|
properties.OriginPath = &origin_path
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if v, ok := d.GetOk("content_types_to_compress"); ok {
|
if v, ok := d.GetOk("content_types_to_compress"); ok {
|
||||||
// var content_types []string
|
var content_types []string
|
||||||
// ctypes := v.(*schema.Set).List()
|
ctypes := v.(*schema.Set).List()
|
||||||
// for _, ct := range ctypes {
|
for _, ct := range ctypes {
|
||||||
// str := ct.(string)
|
str := ct.(string)
|
||||||
// content_types = append(content_types, str)
|
content_types = append(content_types, str)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// properties.ContentTypesToCompress = &content_types
|
properties.ContentTypesToCompress = &content_types
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// cdnEndpoint := cdn.EndpointCreateParameters{
|
cdnEndpoint := cdn.EndpointCreateParameters{
|
||||||
// Location: &location,
|
Location: &location,
|
||||||
// Properties: &properties,
|
Properties: &properties,
|
||||||
// Tags: expandTags(tags),
|
Tags: expandTags(tags),
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// resp, err := cdnEndpointsClient.Create(name, cdnEndpoint, profileName, resGroup)
|
_, err := cdnEndpointsClient.Create(name, cdnEndpoint, profileName, resGroup, make(chan struct{}))
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// d.SetId(*resp.ID)
|
read, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
||||||
//
|
if err != nil {
|
||||||
// log.Printf("[DEBUG] Waiting for CDN Endpoint (%s) to become available", name)
|
return err
|
||||||
// stateConf := &resource.StateChangeConf{
|
}
|
||||||
// Pending: []string{"Accepted", "Updating", "Creating"},
|
if read.ID == nil {
|
||||||
// Target: []string{"Succeeded"},
|
return fmt.Errorf("Cannot read CND Endpoint %s/%s (resource group %s) ID", profileName, name, resGroup)
|
||||||
// Refresh: cdnEndpointStateRefreshFunc(client, resGroup, profileName, name),
|
}
|
||||||
// Timeout: 10 * time.Minute,
|
|
||||||
// }
|
d.SetId(*read.ID)
|
||||||
// if _, err := stateConf.WaitForState(); err != nil {
|
|
||||||
// return fmt.Errorf("Error waiting for CDN Endpoint (%s) to become available: %s", name, err)
|
return resourceArmCdnEndpointRead(d, meta)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return resourceArmCdnEndpointRead(d, meta)
|
func resourceArmCdnEndpointRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
//}
|
cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient
|
||||||
//
|
|
||||||
//func resourceArmCdnEndpointRead(d *schema.ResourceData, meta interface{}) error {
|
id, err := parseAzureResourceID(d.Id())
|
||||||
// cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient
|
if err != nil {
|
||||||
//
|
return err
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
}
|
||||||
// if err != nil {
|
resGroup := id.ResourceGroup
|
||||||
// return err
|
name := id.Path["endpoints"]
|
||||||
// }
|
profileName := id.Path["profiles"]
|
||||||
// resGroup := id.ResourceGroup
|
if profileName == "" {
|
||||||
// name := id.Path["endpoints"]
|
profileName = id.Path["Profiles"]
|
||||||
// profileName := id.Path["profiles"]
|
}
|
||||||
// if profileName == "" {
|
log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
||||||
// profileName = id.Path["Profiles"]
|
resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
||||||
// }
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
d.SetId("")
|
||||||
// resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
return nil
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
}
|
||||||
// d.SetId("")
|
if err != nil {
|
||||||
// return nil
|
return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
||||||
// }
|
}
|
||||||
// if err != nil {
|
|
||||||
// return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
d.Set("name", resp.Name)
|
||||||
// }
|
d.Set("host_name", resp.Properties.HostName)
|
||||||
//
|
d.Set("is_compression_enabled", resp.Properties.IsCompressionEnabled)
|
||||||
// d.Set("name", resp.Name)
|
d.Set("is_http_allowed", resp.Properties.IsHTTPAllowed)
|
||||||
// d.Set("host_name", resp.Properties.HostName)
|
d.Set("is_https_allowed", resp.Properties.IsHTTPSAllowed)
|
||||||
// d.Set("is_compression_enabled", resp.Properties.IsCompressionEnabled)
|
d.Set("querystring_caching_behaviour", resp.Properties.QueryStringCachingBehavior)
|
||||||
// d.Set("is_http_allowed", resp.Properties.IsHTTPAllowed)
|
if resp.Properties.OriginHostHeader != nil && *resp.Properties.OriginHostHeader != "" {
|
||||||
// d.Set("is_https_allowed", resp.Properties.IsHTTPSAllowed)
|
d.Set("origin_host_header", resp.Properties.OriginHostHeader)
|
||||||
// d.Set("querystring_caching_behaviour", resp.Properties.QueryStringCachingBehavior)
|
}
|
||||||
// if resp.Properties.OriginHostHeader != nil && *resp.Properties.OriginHostHeader != "" {
|
if resp.Properties.OriginPath != nil && *resp.Properties.OriginPath != "" {
|
||||||
// d.Set("origin_host_header", resp.Properties.OriginHostHeader)
|
d.Set("origin_path", resp.Properties.OriginPath)
|
||||||
// }
|
}
|
||||||
// if resp.Properties.OriginPath != nil && *resp.Properties.OriginPath != "" {
|
if resp.Properties.ContentTypesToCompress != nil && len(*resp.Properties.ContentTypesToCompress) > 0 {
|
||||||
// d.Set("origin_path", resp.Properties.OriginPath)
|
d.Set("content_types_to_compress", flattenAzureRMCdnEndpointContentTypes(resp.Properties.ContentTypesToCompress))
|
||||||
// }
|
}
|
||||||
// if resp.Properties.ContentTypesToCompress != nil && len(*resp.Properties.ContentTypesToCompress) > 0 {
|
d.Set("origin", flattenAzureRMCdnEndpointOrigin(resp.Properties.Origins))
|
||||||
// d.Set("content_types_to_compress", flattenAzureRMCdnEndpointContentTypes(resp.Properties.ContentTypesToCompress))
|
|
||||||
// }
|
flattenAndSetTags(d, resp.Tags)
|
||||||
// d.Set("origin", flattenAzureRMCdnEndpointOrigin(resp.Properties.Origins))
|
|
||||||
//
|
return nil
|
||||||
// flattenAndSetTags(d, resp.Tags)
|
}
|
||||||
//
|
|
||||||
// return nil
|
func resourceArmCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
//}
|
cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient
|
||||||
//
|
|
||||||
//func resourceArmCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
|
if !d.HasChange("tags") {
|
||||||
// cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient
|
return nil
|
||||||
//
|
}
|
||||||
// if !d.HasChange("tags") {
|
|
||||||
// return nil
|
name := d.Get("name").(string)
|
||||||
// }
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
//
|
profileName := d.Get("profile_name").(string)
|
||||||
// name := d.Get("name").(string)
|
http_allowed := d.Get("is_http_allowed").(bool)
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
https_allowed := d.Get("is_https_allowed").(bool)
|
||||||
// profileName := d.Get("profile_name").(string)
|
compression_enabled := d.Get("is_compression_enabled").(bool)
|
||||||
// http_allowed := d.Get("is_http_allowed").(bool)
|
caching_behaviour := d.Get("querystring_caching_behaviour").(string)
|
||||||
// https_allowed := d.Get("is_https_allowed").(bool)
|
newTags := d.Get("tags").(map[string]interface{})
|
||||||
// compression_enabled := d.Get("is_compression_enabled").(bool)
|
|
||||||
// caching_behaviour := d.Get("querystring_caching_behaviour").(string)
|
properties := cdn.EndpointPropertiesCreateUpdateParameters{
|
||||||
// newTags := d.Get("tags").(map[string]interface{})
|
IsHTTPAllowed: &http_allowed,
|
||||||
//
|
IsHTTPSAllowed: &https_allowed,
|
||||||
// properties := cdn.EndpointPropertiesCreateUpdateParameters{
|
IsCompressionEnabled: &compression_enabled,
|
||||||
// IsHTTPAllowed: &http_allowed,
|
QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
|
||||||
// IsHTTPSAllowed: &https_allowed,
|
}
|
||||||
// IsCompressionEnabled: &compression_enabled,
|
|
||||||
// QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
|
if d.HasChange("origin") {
|
||||||
// }
|
origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
|
||||||
//
|
if originsErr != nil {
|
||||||
// if d.HasChange("origin") {
|
return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
|
||||||
// origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
|
}
|
||||||
// if originsErr != nil {
|
if len(origins) > 0 {
|
||||||
// return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
|
properties.Origins = &origins
|
||||||
// }
|
}
|
||||||
// if len(origins) > 0 {
|
}
|
||||||
// properties.Origins = &origins
|
|
||||||
// }
|
if d.HasChange("origin_host_header") {
|
||||||
// }
|
host_header := d.Get("origin_host_header").(string)
|
||||||
//
|
properties.OriginHostHeader = &host_header
|
||||||
// if d.HasChange("origin_host_header") {
|
}
|
||||||
// host_header := d.Get("origin_host_header").(string)
|
|
||||||
// properties.OriginHostHeader = &host_header
|
if d.HasChange("origin_path") {
|
||||||
// }
|
origin_path := d.Get("origin_path").(string)
|
||||||
//
|
properties.OriginPath = &origin_path
|
||||||
// if d.HasChange("origin_path") {
|
}
|
||||||
// origin_path := d.Get("origin_path").(string)
|
|
||||||
// properties.OriginPath = &origin_path
|
if d.HasChange("content_types_to_compress") {
|
||||||
// }
|
var content_types []string
|
||||||
//
|
ctypes := d.Get("content_types_to_compress").(*schema.Set).List()
|
||||||
// if d.HasChange("content_types_to_compress") {
|
for _, ct := range ctypes {
|
||||||
// var content_types []string
|
str := ct.(string)
|
||||||
// ctypes := d.Get("content_types_to_compress").(*schema.Set).List()
|
content_types = append(content_types, str)
|
||||||
// for _, ct := range ctypes {
|
}
|
||||||
// str := ct.(string)
|
|
||||||
// content_types = append(content_types, str)
|
properties.ContentTypesToCompress = &content_types
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// properties.ContentTypesToCompress = &content_types
|
updateProps := cdn.EndpointUpdateParameters{
|
||||||
// }
|
Tags: expandTags(newTags),
|
||||||
//
|
Properties: &properties,
|
||||||
// updateProps := cdn.EndpointUpdateParameters{
|
}
|
||||||
// Tags: expandTags(newTags),
|
|
||||||
// Properties: &properties,
|
_, err := cdnEndpointsClient.Update(name, updateProps, profileName, resGroup)
|
||||||
// }
|
if err != nil {
|
||||||
//
|
return fmt.Errorf("Error issuing Azure ARM update request to update CDN Endpoint %q: %s", name, err)
|
||||||
// _, err := cdnEndpointsClient.Update(name, updateProps, profileName, resGroup)
|
}
|
||||||
// if err != nil {
|
|
||||||
// return fmt.Errorf("Error issuing Azure ARM update request to update CDN Endpoint %q: %s", name, err)
|
return resourceArmCdnEndpointRead(d, meta)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return resourceArmCdnEndpointRead(d, meta)
|
func resourceArmCdnEndpointDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
//}
|
client := meta.(*ArmClient).cdnEndpointsClient
|
||||||
//
|
|
||||||
//func resourceArmCdnEndpointDelete(d *schema.ResourceData, meta interface{}) error {
|
id, err := parseAzureResourceID(d.Id())
|
||||||
// client := meta.(*ArmClient).cdnEndpointsClient
|
if err != nil {
|
||||||
//
|
return err
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
}
|
||||||
// if err != nil {
|
resGroup := id.ResourceGroup
|
||||||
// return err
|
profileName := id.Path["profiles"]
|
||||||
// }
|
if profileName == "" {
|
||||||
// resGroup := id.ResourceGroup
|
profileName = id.Path["Profiles"]
|
||||||
// profileName := id.Path["profiles"]
|
}
|
||||||
// if profileName == "" {
|
name := id.Path["endpoints"]
|
||||||
// profileName = id.Path["Profiles"]
|
|
||||||
// }
|
accResp, err := client.DeleteIfExists(name, profileName, resGroup, make(chan struct{}))
|
||||||
// name := id.Path["endpoints"]
|
if err != nil {
|
||||||
//
|
if accResp.StatusCode == http.StatusNotFound {
|
||||||
// accResp, err := client.DeleteIfExists(name, profileName, resGroup)
|
return nil
|
||||||
// if err != nil {
|
}
|
||||||
// if accResp.StatusCode == http.StatusNotFound {
|
return fmt.Errorf("Error issuing AzureRM delete request for CDN Endpoint %q: %s", name, err)
|
||||||
// return nil
|
}
|
||||||
// }
|
|
||||||
// return fmt.Errorf("Error issuing AzureRM delete request for CDN Endpoint %q: %s", name, err)
|
return err
|
||||||
// }
|
}
|
||||||
// _, err = pollIndefinitelyAsNeeded(client.Client, accResp.Response, http.StatusNotFound)
|
|
||||||
// if err != nil {
|
func validateCdnEndpointQuerystringCachingBehaviour(v interface{}, k string) (ws []string, errors []error) {
|
||||||
// return fmt.Errorf("Error polling for AzureRM delete request for CDN Endpoint %q: %s", name, err)
|
value := strings.ToLower(v.(string))
|
||||||
// }
|
cachingTypes := map[string]bool{
|
||||||
//
|
"ignorequerystring": true,
|
||||||
// return err
|
"bypasscaching": true,
|
||||||
//}
|
"usequerystring": true,
|
||||||
//
|
}
|
||||||
//func cdnEndpointStateRefreshFunc(client *ArmClient, resourceGroupName string, profileName string, name string) resource.StateRefreshFunc {
|
|
||||||
// return func() (interface{}, string, error) {
|
if !cachingTypes[value] {
|
||||||
// res, err := client.cdnEndpointsClient.Get(name, profileName, resourceGroupName)
|
errors = append(errors, fmt.Errorf("CDN Endpoint querystringCachingBehaviours can only be IgnoreQueryString, BypassCaching or UseQueryString"))
|
||||||
// if err != nil {
|
}
|
||||||
// return nil, "", fmt.Errorf("Error issuing read request in cdnEndpointStateRefreshFunc to Azure ARM for CDN Endpoint '%s' (RG: '%s'): %s", name, resourceGroupName, err)
|
return
|
||||||
// }
|
}
|
||||||
// return res, string(res.Properties.ProvisioningState), nil
|
|
||||||
// }
|
func resourceArmCdnEndpointOriginHash(v interface{}) int {
|
||||||
//}
|
var buf bytes.Buffer
|
||||||
//
|
m := v.(map[string]interface{})
|
||||||
//func validateCdnEndpointQuerystringCachingBehaviour(v interface{}, k string) (ws []string, errors []error) {
|
buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
|
||||||
// value := strings.ToLower(v.(string))
|
buf.WriteString(fmt.Sprintf("%s-", m["host_name"].(string)))
|
||||||
// cachingTypes := map[string]bool{
|
|
||||||
// "ignorequerystring": true,
|
return hashcode.String(buf.String())
|
||||||
// "bypasscaching": true,
|
}
|
||||||
// "usequerystring": true,
|
|
||||||
// }
|
func expandAzureRmCdnEndpointOrigins(d *schema.ResourceData) ([]cdn.DeepCreatedOrigin, error) {
|
||||||
//
|
configs := d.Get("origin").(*schema.Set).List()
|
||||||
// if !cachingTypes[value] {
|
origins := make([]cdn.DeepCreatedOrigin, 0, len(configs))
|
||||||
// errors = append(errors, fmt.Errorf("CDN Endpoint querystringCachingBehaviours can only be IgnoreQueryString, BypassCaching or UseQueryString"))
|
|
||||||
// }
|
for _, configRaw := range configs {
|
||||||
// return
|
data := configRaw.(map[string]interface{})
|
||||||
//}
|
|
||||||
//
|
host_name := data["host_name"].(string)
|
||||||
//func resourceArmCdnEndpointOriginHash(v interface{}) int {
|
|
||||||
// var buf bytes.Buffer
|
properties := cdn.DeepCreatedOriginProperties{
|
||||||
// m := v.(map[string]interface{})
|
HostName: &host_name,
|
||||||
// buf.WriteString(fmt.Sprintf("%s-", m["name"].(string)))
|
}
|
||||||
// buf.WriteString(fmt.Sprintf("%s-", m["host_name"].(string)))
|
|
||||||
//
|
if v, ok := data["https_port"]; ok {
|
||||||
// return hashcode.String(buf.String())
|
https_port := int32(v.(int))
|
||||||
//}
|
properties.HTTPSPort = &https_port
|
||||||
//
|
|
||||||
//func expandAzureRmCdnEndpointOrigins(d *schema.ResourceData) ([]cdn.DeepCreatedOrigin, error) {
|
}
|
||||||
// configs := d.Get("origin").(*schema.Set).List()
|
|
||||||
// origins := make([]cdn.DeepCreatedOrigin, 0, len(configs))
|
if v, ok := data["http_port"]; ok {
|
||||||
//
|
http_port := int32(v.(int))
|
||||||
// for _, configRaw := range configs {
|
properties.HTTPPort = &http_port
|
||||||
// data := configRaw.(map[string]interface{})
|
}
|
||||||
//
|
|
||||||
// host_name := data["host_name"].(string)
|
name := data["name"].(string)
|
||||||
//
|
|
||||||
// properties := cdn.DeepCreatedOriginProperties{
|
origin := cdn.DeepCreatedOrigin{
|
||||||
// HostName: &host_name,
|
Name: &name,
|
||||||
// }
|
Properties: &properties,
|
||||||
//
|
}
|
||||||
// if v, ok := data["https_port"]; ok {
|
|
||||||
// https_port := v.(int)
|
origins = append(origins, origin)
|
||||||
// properties.HTTPSPort = &https_port
|
}
|
||||||
//
|
|
||||||
// }
|
return origins, nil
|
||||||
//
|
}
|
||||||
// if v, ok := data["http_port"]; ok {
|
|
||||||
// http_port := v.(int)
|
func flattenAzureRMCdnEndpointOrigin(list *[]cdn.DeepCreatedOrigin) []map[string]interface{} {
|
||||||
// properties.HTTPPort = &http_port
|
result := make([]map[string]interface{}, 0, len(*list))
|
||||||
// }
|
for _, i := range *list {
|
||||||
//
|
l := map[string]interface{}{
|
||||||
// name := data["name"].(string)
|
"name": *i.Name,
|
||||||
//
|
"host_name": *i.Properties.HostName,
|
||||||
// origin := cdn.DeepCreatedOrigin{
|
}
|
||||||
// Name: &name,
|
|
||||||
// Properties: &properties,
|
if i.Properties.HTTPPort != nil {
|
||||||
// }
|
l["http_port"] = *i.Properties.HTTPPort
|
||||||
//
|
}
|
||||||
// origins = append(origins, origin)
|
if i.Properties.HTTPSPort != nil {
|
||||||
// }
|
l["https_port"] = *i.Properties.HTTPSPort
|
||||||
//
|
}
|
||||||
// return origins, nil
|
result = append(result, l)
|
||||||
//}
|
}
|
||||||
//
|
return result
|
||||||
//func flattenAzureRMCdnEndpointOrigin(list *[]cdn.DeepCreatedOrigin) []map[string]interface{} {
|
}
|
||||||
// result := make([]map[string]interface{}, 0, len(*list))
|
|
||||||
// for _, i := range *list {
|
func flattenAzureRMCdnEndpointContentTypes(list *[]string) []interface{} {
|
||||||
// l := map[string]interface{}{
|
vs := make([]interface{}, 0, len(*list))
|
||||||
// "name": *i.Name,
|
for _, v := range *list {
|
||||||
// "host_name": *i.Properties.HostName,
|
vs = append(vs, v)
|
||||||
// }
|
}
|
||||||
//
|
return vs
|
||||||
// if i.Properties.HTTPPort != nil {
|
}
|
||||||
// l["http_port"] = *i.Properties.HTTPPort
|
|
||||||
// }
|
|
||||||
// if i.Properties.HTTPSPort != nil {
|
|
||||||
// l["https_port"] = *i.Properties.HTTPSPort
|
|
||||||
// }
|
|
||||||
// result = append(result, l)
|
|
||||||
// }
|
|
||||||
// return result
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func flattenAzureRMCdnEndpointContentTypes(list *[]string) []interface{} {
|
|
||||||
// vs := make([]interface{}, 0, len(*list))
|
|
||||||
// for _, v := range *list {
|
|
||||||
// vs = append(vs, v)
|
|
||||||
// }
|
|
||||||
// return vs
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,215 +1,213 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "testing"
|
"testing"
|
||||||
//
|
|
||||||
// "github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func TestAccAzureRMCdnEndpoint_basic(t *testing.T) {
|
func TestAccAzureRMCdnEndpoint_basic(t *testing.T) {
|
||||||
//
|
ri := acctest.RandInt()
|
||||||
// ri := acctest.RandInt()
|
config := fmt.Sprintf(testAccAzureRMCdnEndpoint_basic, ri, ri, ri)
|
||||||
// config := fmt.Sprintf(testAccAzureRMCdnEndpoint_basic, ri, ri, ri)
|
|
||||||
//
|
resource.Test(t, resource.TestCase{
|
||||||
// resource.Test(t, resource.TestCase{
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
Providers: testAccProviders,
|
||||||
// Providers: testAccProviders,
|
CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
|
||||||
// CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
|
Steps: []resource.TestStep{
|
||||||
// Steps: []resource.TestStep{
|
{
|
||||||
// resource.TestStep{
|
Config: config,
|
||||||
// Config: config,
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
||||||
// testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
),
|
||||||
// ),
|
},
|
||||||
// },
|
},
|
||||||
// },
|
})
|
||||||
// })
|
}
|
||||||
//}
|
|
||||||
//
|
func TestAccAzureRMCdnEndpoint_withTags(t *testing.T) {
|
||||||
//func TestAccAzureRMCdnEndpoints_withTags(t *testing.T) {
|
ri := acctest.RandInt()
|
||||||
//
|
preConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTags, ri, ri, ri)
|
||||||
// ri := acctest.RandInt()
|
postConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTagsUpdate, ri, ri, ri)
|
||||||
// preConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTags, ri, ri, ri)
|
|
||||||
// postConfig := fmt.Sprintf(testAccAzureRMCdnEndpoint_withTagsUpdate, ri, ri, ri)
|
resource.Test(t, resource.TestCase{
|
||||||
//
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// resource.Test(t, resource.TestCase{
|
Providers: testAccProviders,
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
|
||||||
// Providers: testAccProviders,
|
Steps: []resource.TestStep{
|
||||||
// CheckDestroy: testCheckAzureRMCdnEndpointDestroy,
|
{
|
||||||
// Steps: []resource.TestStep{
|
Config: preConfig,
|
||||||
// resource.TestStep{
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// Config: preConfig,
|
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
resource.TestCheckResourceAttr(
|
||||||
// testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
"azurerm_cdn_endpoint.test", "tags.#", "2"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_endpoint.test", "tags.#", "2"),
|
"azurerm_cdn_endpoint.test", "tags.environment", "Production"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_endpoint.test", "tags.environment", "Production"),
|
"azurerm_cdn_endpoint.test", "tags.cost_center", "MSFT"),
|
||||||
// resource.TestCheckResourceAttr(
|
),
|
||||||
// "azurerm_cdn_endpoint.test", "tags.cost_center", "MSFT"),
|
},
|
||||||
// ),
|
|
||||||
// },
|
{
|
||||||
//
|
Config: postConfig,
|
||||||
// resource.TestStep{
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// Config: postConfig,
|
testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
resource.TestCheckResourceAttr(
|
||||||
// testCheckAzureRMCdnEndpointExists("azurerm_cdn_endpoint.test"),
|
"azurerm_cdn_endpoint.test", "tags.#", "1"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_endpoint.test", "tags.#", "1"),
|
"azurerm_cdn_endpoint.test", "tags.environment", "staging"),
|
||||||
// resource.TestCheckResourceAttr(
|
),
|
||||||
// "azurerm_cdn_endpoint.test", "tags.environment", "staging"),
|
},
|
||||||
// ),
|
},
|
||||||
// },
|
})
|
||||||
// },
|
}
|
||||||
// })
|
|
||||||
//}
|
func testCheckAzureRMCdnEndpointExists(name string) resource.TestCheckFunc {
|
||||||
//
|
return func(s *terraform.State) error {
|
||||||
//func testCheckAzureRMCdnEndpointExists(name string) resource.TestCheckFunc {
|
// Ensure we have enough information in state to look up in API
|
||||||
// return func(s *terraform.State) error {
|
rs, ok := s.RootModule().Resources[name]
|
||||||
// // Ensure we have enough information in state to look up in API
|
if !ok {
|
||||||
// rs, ok := s.RootModule().Resources[name]
|
return fmt.Errorf("Not found: %s", name)
|
||||||
// if !ok {
|
}
|
||||||
// return fmt.Errorf("Not found: %s", name)
|
|
||||||
// }
|
name := rs.Primary.Attributes["name"]
|
||||||
//
|
profileName := rs.Primary.Attributes["profile_name"]
|
||||||
// name := rs.Primary.Attributes["name"]
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
// profileName := rs.Primary.Attributes["profile_name"]
|
if !hasResourceGroup {
|
||||||
// resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
return fmt.Errorf("Bad: no resource group found in state for cdn endpoint: %s", name)
|
||||||
// if !hasResourceGroup {
|
}
|
||||||
// return fmt.Errorf("Bad: no resource group found in state for cdn endpoint: %s", name)
|
|
||||||
// }
|
conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
||||||
//
|
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
resp, err := conn.Get(name, profileName, resourceGroup)
|
||||||
//
|
if err != nil {
|
||||||
// resp, err := conn.Get(name, profileName, resourceGroup)
|
return fmt.Errorf("Bad: Get on cdnEndpointsClient: %s", err)
|
||||||
// if err != nil {
|
}
|
||||||
// return fmt.Errorf("Bad: Get on cdnEndpointsClient: %s", err)
|
|
||||||
// }
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
//
|
return fmt.Errorf("Bad: CDN Endpoint %q (resource group: %q) does not exist", name, resourceGroup)
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
}
|
||||||
// return fmt.Errorf("Bad: CDN Endpoint %q (resource group: %q) does not exist", name, resourceGroup)
|
|
||||||
// }
|
return nil
|
||||||
//
|
}
|
||||||
// return nil
|
}
|
||||||
// }
|
|
||||||
//}
|
func testCheckAzureRMCdnEndpointDestroy(s *terraform.State) error {
|
||||||
//
|
conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
||||||
//func testCheckAzureRMCdnEndpointDestroy(s *terraform.State) error {
|
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).cdnEndpointsClient
|
for _, rs := range s.RootModule().Resources {
|
||||||
//
|
if rs.Type != "azurerm_cdn_endpoint" {
|
||||||
// for _, rs := range s.RootModule().Resources {
|
continue
|
||||||
// if rs.Type != "azurerm_cdn_endpoint" {
|
}
|
||||||
// continue
|
|
||||||
// }
|
name := rs.Primary.Attributes["name"]
|
||||||
//
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
// name := rs.Primary.Attributes["name"]
|
profileName := rs.Primary.Attributes["profile_name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
|
||||||
// profileName := rs.Primary.Attributes["profile_name"]
|
resp, err := conn.Get(name, profileName, resourceGroup)
|
||||||
//
|
|
||||||
// resp, err := conn.Get(name, profileName, resourceGroup)
|
if err != nil {
|
||||||
//
|
return nil
|
||||||
// if err != nil {
|
}
|
||||||
// return nil
|
|
||||||
// }
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
//
|
return fmt.Errorf("CDN Endpoint still exists:\n%#v", resp.Properties)
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
}
|
||||||
// return fmt.Errorf("CDN Endpoint still exists:\n%#v", resp.Properties)
|
}
|
||||||
// }
|
|
||||||
// }
|
return nil
|
||||||
//
|
}
|
||||||
// return nil
|
|
||||||
//}
|
var testAccAzureRMCdnEndpoint_basic = `
|
||||||
//
|
resource "azurerm_resource_group" "test" {
|
||||||
//var testAccAzureRMCdnEndpoint_basic = `
|
name = "acctestrg-%d"
|
||||||
//resource "azurerm_resource_group" "test" {
|
location = "West US"
|
||||||
// name = "acctestrg-%d"
|
}
|
||||||
// location = "West US"
|
resource "azurerm_cdn_profile" "test" {
|
||||||
//}
|
name = "acctestcdnprof%d"
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
location = "West US"
|
||||||
// name = "acctestcdnprof%d"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
sku = "Standard"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
}
|
||||||
// sku = "Standard"
|
|
||||||
//}
|
resource "azurerm_cdn_endpoint" "test" {
|
||||||
//
|
name = "acctestcdnend%d"
|
||||||
//resource "azurerm_cdn_endpoint" "test" {
|
profile_name = "${azurerm_cdn_profile.test.name}"
|
||||||
// name = "acctestcdnend%d"
|
location = "West US"
|
||||||
// profile_name = "${azurerm_cdn_profile.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
origin {
|
||||||
//
|
name = "acceptanceTestCdnOrigin1"
|
||||||
// origin {
|
host_name = "www.example.com"
|
||||||
// name = "acceptanceTestCdnOrigin1"
|
https_port = 443
|
||||||
// host_name = "www.example.com"
|
http_port = 80
|
||||||
// https_port = 443
|
}
|
||||||
// http_port = 80
|
}
|
||||||
// }
|
`
|
||||||
//}
|
|
||||||
//`
|
var testAccAzureRMCdnEndpoint_withTags = `
|
||||||
//
|
resource "azurerm_resource_group" "test" {
|
||||||
//var testAccAzureRMCdnEndpoint_withTags = `
|
name = "acctestrg-%d"
|
||||||
//resource "azurerm_resource_group" "test" {
|
location = "West US"
|
||||||
// name = "acctestrg-%d"
|
}
|
||||||
// location = "West US"
|
resource "azurerm_cdn_profile" "test" {
|
||||||
//}
|
name = "acctestcdnprof%d"
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
location = "West US"
|
||||||
// name = "acctestcdnprof%d"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
sku = "Standard"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
}
|
||||||
// sku = "Standard"
|
|
||||||
//}
|
resource "azurerm_cdn_endpoint" "test" {
|
||||||
//
|
name = "acctestcdnend%d"
|
||||||
//resource "azurerm_cdn_endpoint" "test" {
|
profile_name = "${azurerm_cdn_profile.test.name}"
|
||||||
// name = "acctestcdnend%d"
|
location = "West US"
|
||||||
// profile_name = "${azurerm_cdn_profile.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
origin {
|
||||||
//
|
name = "acceptanceTestCdnOrigin2"
|
||||||
// origin {
|
host_name = "www.example.com"
|
||||||
// name = "acceptanceTestCdnOrigin2"
|
https_port = 443
|
||||||
// host_name = "www.example.com"
|
http_port = 80
|
||||||
// https_port = 443
|
}
|
||||||
// http_port = 80
|
|
||||||
// }
|
tags {
|
||||||
//
|
environment = "Production"
|
||||||
// tags {
|
cost_center = "MSFT"
|
||||||
// environment = "Production"
|
}
|
||||||
// cost_center = "MSFT"
|
}
|
||||||
// }
|
`
|
||||||
//}
|
|
||||||
//`
|
var testAccAzureRMCdnEndpoint_withTagsUpdate = `
|
||||||
//
|
resource "azurerm_resource_group" "test" {
|
||||||
//var testAccAzureRMCdnEndpoint_withTagsUpdate = `
|
name = "acctestrg-%d"
|
||||||
//resource "azurerm_resource_group" "test" {
|
location = "West US"
|
||||||
// name = "acctestrg-%d"
|
}
|
||||||
// location = "West US"
|
resource "azurerm_cdn_profile" "test" {
|
||||||
//}
|
name = "acctestcdnprof%d"
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
location = "West US"
|
||||||
// name = "acctestcdnprof%d"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
sku = "Standard"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
}
|
||||||
// sku = "Standard"
|
|
||||||
//}
|
resource "azurerm_cdn_endpoint" "test" {
|
||||||
//
|
name = "acctestcdnend%d"
|
||||||
//resource "azurerm_cdn_endpoint" "test" {
|
profile_name = "${azurerm_cdn_profile.test.name}"
|
||||||
// name = "acctestcdnend%d"
|
location = "West US"
|
||||||
// profile_name = "${azurerm_cdn_profile.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// location = "West US"
|
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
origin {
|
||||||
//
|
name = "acceptanceTestCdnOrigin2"
|
||||||
// origin {
|
host_name = "www.example.com"
|
||||||
// name = "acceptanceTestCdnOrigin2"
|
https_port = 443
|
||||||
// host_name = "www.example.com"
|
http_port = 80
|
||||||
// https_port = 443
|
}
|
||||||
// http_port = 80
|
|
||||||
// }
|
tags {
|
||||||
//
|
environment = "staging"
|
||||||
// tags {
|
}
|
||||||
// environment = "staging"
|
}
|
||||||
// }
|
`
|
||||||
//}
|
|
||||||
//`
|
|
||||||
|
|
|
@ -1,186 +1,171 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "log"
|
"log"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "strings"
|
"strings"
|
||||||
// "time"
|
|
||||||
//
|
"github.com/Azure/azure-sdk-for-go/arm/cdn"
|
||||||
// "github.com/Azure/azure-sdk-for-go/arm/cdn"
|
"github.com/hashicorp/terraform/helper/schema"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
)
|
||||||
// "github.com/hashicorp/terraform/helper/schema"
|
|
||||||
//)
|
func resourceArmCdnProfile() *schema.Resource {
|
||||||
//
|
return &schema.Resource{
|
||||||
//func resourceArmCdnProfile() *schema.Resource {
|
Create: resourceArmCdnProfileCreate,
|
||||||
// return &schema.Resource{
|
Read: resourceArmCdnProfileRead,
|
||||||
// Create: resourceArmCdnProfileCreate,
|
Update: resourceArmCdnProfileUpdate,
|
||||||
// Read: resourceArmCdnProfileRead,
|
Delete: resourceArmCdnProfileDelete,
|
||||||
// Update: resourceArmCdnProfileUpdate,
|
|
||||||
// Delete: resourceArmCdnProfileDelete,
|
Schema: map[string]*schema.Schema{
|
||||||
//
|
"name": {
|
||||||
// Schema: map[string]*schema.Schema{
|
Type: schema.TypeString,
|
||||||
// "name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"location": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "location": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
StateFunc: azureRMNormalizeLocation,
|
||||||
// ForceNew: true,
|
},
|
||||||
// StateFunc: azureRMNormalizeLocation,
|
|
||||||
// },
|
"resource_group_name": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "resource_group_name": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
},
|
||||||
// ForceNew: true,
|
|
||||||
// },
|
"sku": {
|
||||||
//
|
Type: schema.TypeString,
|
||||||
// "sku": &schema.Schema{
|
Required: true,
|
||||||
// Type: schema.TypeString,
|
ForceNew: true,
|
||||||
// Required: true,
|
ValidateFunc: validateCdnProfileSku,
|
||||||
// ForceNew: true,
|
},
|
||||||
// ValidateFunc: validateCdnProfileSku,
|
|
||||||
// },
|
"tags": tagsSchema(),
|
||||||
//
|
},
|
||||||
// "tags": tagsSchema(),
|
}
|
||||||
// },
|
}
|
||||||
// }
|
|
||||||
//}
|
func resourceArmCdnProfileCreate(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
client := meta.(*ArmClient)
|
||||||
//func resourceArmCdnProfileCreate(d *schema.ResourceData, meta interface{}) error {
|
cdnProfilesClient := client.cdnProfilesClient
|
||||||
// client := meta.(*ArmClient)
|
|
||||||
// cdnProfilesClient := client.cdnProfilesClient
|
log.Printf("[INFO] preparing arguments for Azure ARM CDN Profile creation.")
|
||||||
//
|
|
||||||
// log.Printf("[INFO] preparing arguments for Azure ARM CDN Profile creation.")
|
name := d.Get("name").(string)
|
||||||
//
|
location := d.Get("location").(string)
|
||||||
// name := d.Get("name").(string)
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// location := d.Get("location").(string)
|
sku := d.Get("sku").(string)
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
tags := d.Get("tags").(map[string]interface{})
|
||||||
// sku := d.Get("sku").(string)
|
|
||||||
// tags := d.Get("tags").(map[string]interface{})
|
properties := cdn.ProfilePropertiesCreateParameters{
|
||||||
//
|
Sku: &cdn.Sku{
|
||||||
// properties := cdn.ProfilePropertiesCreateParameters{
|
Name: cdn.SkuName(sku),
|
||||||
// Sku: &cdn.Sku{
|
},
|
||||||
// Name: cdn.SkuName(sku),
|
}
|
||||||
// },
|
|
||||||
// }
|
cdnProfile := cdn.ProfileCreateParameters{
|
||||||
//
|
Location: &location,
|
||||||
// cdnProfile := cdn.ProfileCreateParameters{
|
Properties: &properties,
|
||||||
// Location: &location,
|
Tags: expandTags(tags),
|
||||||
// Properties: &properties,
|
}
|
||||||
// Tags: expandTags(tags),
|
|
||||||
// }
|
_, err := cdnProfilesClient.Create(name, cdnProfile, resGroup, make(chan struct{}))
|
||||||
//
|
if err != nil {
|
||||||
// resp, err := cdnProfilesClient.Create(name, cdnProfile, resGroup)
|
return err
|
||||||
// if err != nil {
|
}
|
||||||
// return err
|
|
||||||
// }
|
read, err := cdnProfilesClient.Get(name, resGroup)
|
||||||
//
|
if err != nil {
|
||||||
// d.SetId(*resp.ID)
|
return err
|
||||||
//
|
}
|
||||||
// log.Printf("[DEBUG] Waiting for CDN Profile (%s) to become available", name)
|
if read.ID == nil {
|
||||||
// stateConf := &resource.StateChangeConf{
|
return fmt.Errorf("Cannot read CND Profile %s (resource group %s) ID", name, resGroup)
|
||||||
// Pending: []string{"Accepted", "Updating", "Creating"},
|
}
|
||||||
// Target: []string{"Succeeded"},
|
|
||||||
// Refresh: cdnProfileStateRefreshFunc(client, resGroup, name),
|
d.SetId(*read.ID)
|
||||||
// Timeout: 10 * time.Minute,
|
|
||||||
// }
|
return resourceArmCdnProfileRead(d, meta)
|
||||||
// if _, err := stateConf.WaitForState(); err != nil {
|
}
|
||||||
// return fmt.Errorf("Error waiting for CDN Profile (%s) to become available: %s", name, err)
|
|
||||||
// }
|
func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
||||||
// return resourceArmCdnProfileRead(d, meta)
|
|
||||||
//}
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
//func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
|
return err
|
||||||
// cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
}
|
||||||
//
|
resGroup := id.ResourceGroup
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
name := id.Path["Profiles"]
|
||||||
// if err != nil {
|
|
||||||
// return err
|
resp, err := cdnProfilesClient.Get(name, resGroup)
|
||||||
// }
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// resGroup := id.ResourceGroup
|
d.SetId("")
|
||||||
// name := id.Path["Profiles"]
|
return nil
|
||||||
//
|
}
|
||||||
// resp, err := cdnProfilesClient.Get(name, resGroup)
|
if err != nil {
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
||||||
// d.SetId("")
|
}
|
||||||
// return nil
|
|
||||||
// }
|
if resp.Properties != nil && resp.Properties.Sku != nil {
|
||||||
// if err != nil {
|
d.Set("sku", string(resp.Properties.Sku.Name))
|
||||||
// return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
}
|
||||||
// }
|
|
||||||
//
|
flattenAndSetTags(d, resp.Tags)
|
||||||
// if resp.Properties != nil && resp.Properties.Sku != nil {
|
|
||||||
// d.Set("sku", string(resp.Properties.Sku.Name))
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// flattenAndSetTags(d, resp.Tags)
|
func resourceArmCdnProfileUpdate(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
||||||
// return nil
|
|
||||||
//}
|
if !d.HasChange("tags") {
|
||||||
//
|
return nil
|
||||||
//func resourceArmCdnProfileUpdate(d *schema.ResourceData, meta interface{}) error {
|
}
|
||||||
// cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
|
||||||
//
|
name := d.Get("name").(string)
|
||||||
// if !d.HasChange("tags") {
|
resGroup := d.Get("resource_group_name").(string)
|
||||||
// return nil
|
newTags := d.Get("tags").(map[string]interface{})
|
||||||
// }
|
|
||||||
//
|
props := cdn.ProfileUpdateParameters{
|
||||||
// name := d.Get("name").(string)
|
Tags: expandTags(newTags),
|
||||||
// resGroup := d.Get("resource_group_name").(string)
|
}
|
||||||
// newTags := d.Get("tags").(map[string]interface{})
|
|
||||||
//
|
_, err := cdnProfilesClient.Update(name, props, resGroup)
|
||||||
// props := cdn.ProfileUpdateParameters{
|
if err != nil {
|
||||||
// Tags: expandTags(newTags),
|
return fmt.Errorf("Error issuing Azure ARM update request to update CDN Profile %q: %s", name, err)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// _, err := cdnProfilesClient.Update(name, props, resGroup)
|
return resourceArmCdnProfileRead(d, meta)
|
||||||
// if err != nil {
|
}
|
||||||
// return fmt.Errorf("Error issuing Azure ARM update request to update CDN Profile %q: %s", name, err)
|
|
||||||
// }
|
func resourceArmCdnProfileDelete(d *schema.ResourceData, meta interface{}) error {
|
||||||
//
|
cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
||||||
// return resourceArmCdnProfileRead(d, meta)
|
|
||||||
//}
|
id, err := parseAzureResourceID(d.Id())
|
||||||
//
|
if err != nil {
|
||||||
//func resourceArmCdnProfileDelete(d *schema.ResourceData, meta interface{}) error {
|
return err
|
||||||
// cdnProfilesClient := meta.(*ArmClient).cdnProfilesClient
|
}
|
||||||
//
|
resGroup := id.ResourceGroup
|
||||||
// id, err := parseAzureResourceID(d.Id())
|
name := id.Path["Profiles"]
|
||||||
// if err != nil {
|
|
||||||
// return err
|
_, err = cdnProfilesClient.DeleteIfExists(name, resGroup, make(chan struct{}))
|
||||||
// }
|
|
||||||
// resGroup := id.ResourceGroup
|
return err
|
||||||
// name := id.Path["Profiles"]
|
}
|
||||||
//
|
|
||||||
// _, err = cdnProfilesClient.DeleteIfExists(name, resGroup)
|
func validateCdnProfileSku(v interface{}, k string) (ws []string, errors []error) {
|
||||||
//
|
value := strings.ToLower(v.(string))
|
||||||
// return err
|
skus := map[string]bool{
|
||||||
//}
|
"standard": true,
|
||||||
//
|
"premium": true,
|
||||||
//func cdnProfileStateRefreshFunc(client *ArmClient, resourceGroupName string, cdnProfileName string) resource.StateRefreshFunc {
|
}
|
||||||
// return func() (interface{}, string, error) {
|
|
||||||
// res, err := client.cdnProfilesClient.Get(cdnProfileName, resourceGroupName)
|
if !skus[value] {
|
||||||
// if err != nil {
|
errors = append(errors, fmt.Errorf("CDN Profile SKU can only be Standard or Premium"))
|
||||||
// return nil, "", fmt.Errorf("Error issuing read request in cdnProfileStateRefreshFunc to Azure ARM for CND Profile '%s' (RG: '%s'): %s", cdnProfileName, resourceGroupName, err)
|
}
|
||||||
// }
|
return
|
||||||
// return res, string(res.Properties.ProvisioningState), nil
|
}
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func validateCdnProfileSku(v interface{}, k string) (ws []string, errors []error) {
|
|
||||||
// value := strings.ToLower(v.(string))
|
|
||||||
// skus := map[string]bool{
|
|
||||||
// "standard": true,
|
|
||||||
// "premium": true,
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if !skus[value] {
|
|
||||||
// errors = append(errors, fmt.Errorf("CDN Profile SKU can only be Standard or Premium"))
|
|
||||||
// }
|
|
||||||
// return
|
|
||||||
//}
|
|
||||||
|
|
|
@ -1,207 +1,207 @@
|
||||||
package azurerm
|
package azurerm
|
||||||
|
|
||||||
//import (
|
import (
|
||||||
// "fmt"
|
"fmt"
|
||||||
// "net/http"
|
"net/http"
|
||||||
// "testing"
|
"testing"
|
||||||
//
|
|
||||||
// "github.com/hashicorp/terraform/helper/acctest"
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
// "github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
// "github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
//)
|
)
|
||||||
//
|
|
||||||
//func TestResourceAzureRMCdnProfileSKU_validation(t *testing.T) {
|
func TestResourceAzureRMCdnProfileSKU_validation(t *testing.T) {
|
||||||
// cases := []struct {
|
cases := []struct {
|
||||||
// Value string
|
Value string
|
||||||
// ErrCount int
|
ErrCount int
|
||||||
// }{
|
}{
|
||||||
// {
|
{
|
||||||
// Value: "Random",
|
Value: "Random",
|
||||||
// ErrCount: 1,
|
ErrCount: 1,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "Standard",
|
Value: "Standard",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "Premium",
|
Value: "Premium",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "STANDARD",
|
Value: "STANDARD",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// {
|
{
|
||||||
// Value: "PREMIUM",
|
Value: "PREMIUM",
|
||||||
// ErrCount: 0,
|
ErrCount: 0,
|
||||||
// },
|
},
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// for _, tc := range cases {
|
for _, tc := range cases {
|
||||||
// _, errors := validateCdnProfileSku(tc.Value, "azurerm_cdn_profile")
|
_, errors := validateCdnProfileSku(tc.Value, "azurerm_cdn_profile")
|
||||||
//
|
|
||||||
// if len(errors) != tc.ErrCount {
|
if len(errors) != tc.ErrCount {
|
||||||
// t.Fatalf("Expected the Azure RM CDN Profile SKU to trigger a validation error")
|
t.Fatalf("Expected the Azure RM CDN Profile SKU to trigger a validation error")
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMCdnProfile_basic(t *testing.T) {
|
func TestAccAzureRMCdnProfile_basic(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// config := fmt.Sprintf(testAccAzureRMCdnProfile_basic, ri, ri)
|
config := fmt.Sprintf(testAccAzureRMCdnProfile_basic, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMCdnProfileDestroy,
|
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
{
|
||||||
// Config: config,
|
Config: config,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func TestAccAzureRMCdnProfile_withTags(t *testing.T) {
|
func TestAccAzureRMCdnProfile_withTags(t *testing.T) {
|
||||||
//
|
|
||||||
// ri := acctest.RandInt()
|
ri := acctest.RandInt()
|
||||||
// preConfig := fmt.Sprintf(testAccAzureRMCdnProfile_withTags, ri, ri)
|
preConfig := fmt.Sprintf(testAccAzureRMCdnProfile_withTags, ri, ri)
|
||||||
// postConfig := fmt.Sprintf(testAccAzureRMCdnProfile_withTagsUpdate, ri, ri)
|
postConfig := fmt.Sprintf(testAccAzureRMCdnProfile_withTagsUpdate, ri, ri)
|
||||||
//
|
|
||||||
// resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
// PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
// Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
// CheckDestroy: testCheckAzureRMCdnProfileDestroy,
|
CheckDestroy: testCheckAzureRMCdnProfileDestroy,
|
||||||
// Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
// resource.TestStep{
|
{
|
||||||
// Config: preConfig,
|
Config: preConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_profile.test", "tags.#", "2"),
|
"azurerm_cdn_profile.test", "tags.#", "2"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_profile.test", "tags.environment", "Production"),
|
"azurerm_cdn_profile.test", "tags.environment", "Production"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_profile.test", "tags.cost_center", "MSFT"),
|
"azurerm_cdn_profile.test", "tags.cost_center", "MSFT"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
//
|
|
||||||
// resource.TestStep{
|
{
|
||||||
// Config: postConfig,
|
Config: postConfig,
|
||||||
// Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
// testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
testCheckAzureRMCdnProfileExists("azurerm_cdn_profile.test"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_profile.test", "tags.#", "1"),
|
"azurerm_cdn_profile.test", "tags.#", "1"),
|
||||||
// resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
// "azurerm_cdn_profile.test", "tags.environment", "staging"),
|
"azurerm_cdn_profile.test", "tags.environment", "staging"),
|
||||||
// ),
|
),
|
||||||
// },
|
},
|
||||||
// },
|
},
|
||||||
// })
|
})
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMCdnProfileExists(name string) resource.TestCheckFunc {
|
func testCheckAzureRMCdnProfileExists(name string) resource.TestCheckFunc {
|
||||||
// return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
// // Ensure we have enough information in state to look up in API
|
// Ensure we have enough information in state to look up in API
|
||||||
// rs, ok := s.RootModule().Resources[name]
|
rs, ok := s.RootModule().Resources[name]
|
||||||
// if !ok {
|
if !ok {
|
||||||
// return fmt.Errorf("Not found: %s", name)
|
return fmt.Errorf("Not found: %s", name)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// name := rs.Primary.Attributes["name"]
|
name := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
// if !hasResourceGroup {
|
if !hasResourceGroup {
|
||||||
// return fmt.Errorf("Bad: no resource group found in state for cdn profile: %s", name)
|
return fmt.Errorf("Bad: no resource group found in state for cdn profile: %s", name)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).cdnProfilesClient
|
conn := testAccProvider.Meta().(*ArmClient).cdnProfilesClient
|
||||||
//
|
|
||||||
// resp, err := conn.Get(name, resourceGroup)
|
resp, err := conn.Get(name, resourceGroup)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return fmt.Errorf("Bad: Get on cdnProfilesClient: %s", err)
|
return fmt.Errorf("Bad: Get on cdnProfilesClient: %s", err)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode == http.StatusNotFound {
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
// return fmt.Errorf("Bad: CDN Profile %q (resource group: %q) does not exist", name, resourceGroup)
|
return fmt.Errorf("Bad: CDN Profile %q (resource group: %q) does not exist", name, resourceGroup)
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//func testCheckAzureRMCdnProfileDestroy(s *terraform.State) error {
|
func testCheckAzureRMCdnProfileDestroy(s *terraform.State) error {
|
||||||
// conn := testAccProvider.Meta().(*ArmClient).cdnProfilesClient
|
conn := testAccProvider.Meta().(*ArmClient).cdnProfilesClient
|
||||||
//
|
|
||||||
// for _, rs := range s.RootModule().Resources {
|
for _, rs := range s.RootModule().Resources {
|
||||||
// if rs.Type != "azurerm_cdn_profile" {
|
if rs.Type != "azurerm_cdn_profile" {
|
||||||
// continue
|
continue
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// name := rs.Primary.Attributes["name"]
|
name := rs.Primary.Attributes["name"]
|
||||||
// resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
resourceGroup := rs.Primary.Attributes["resource_group_name"]
|
||||||
//
|
|
||||||
// resp, err := conn.Get(name, resourceGroup)
|
resp, err := conn.Get(name, resourceGroup)
|
||||||
//
|
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return nil
|
return nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if resp.StatusCode != http.StatusNotFound {
|
if resp.StatusCode != http.StatusNotFound {
|
||||||
// return fmt.Errorf("CDN Profile still exists:\n%#v", resp.Properties)
|
return fmt.Errorf("CDN Profile still exists:\n%#v", resp.Properties)
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return nil
|
return nil
|
||||||
//}
|
}
|
||||||
//
|
|
||||||
//var testAccAzureRMCdnProfile_basic = `
|
var testAccAzureRMCdnProfile_basic = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
resource "azurerm_cdn_profile" "test" {
|
||||||
// name = "acctestcdnprof%d"
|
name = "acctestcdnprof%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// sku = "Standard"
|
sku = "Standard"
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMCdnProfile_withTags = `
|
var testAccAzureRMCdnProfile_withTags = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
resource "azurerm_cdn_profile" "test" {
|
||||||
// name = "acctestcdnprof%d"
|
name = "acctestcdnprof%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// sku = "Standard"
|
sku = "Standard"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "Production"
|
environment = "Production"
|
||||||
// cost_center = "MSFT"
|
cost_center = "MSFT"
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
//
|
|
||||||
//var testAccAzureRMCdnProfile_withTagsUpdate = `
|
var testAccAzureRMCdnProfile_withTagsUpdate = `
|
||||||
//resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
// name = "acctestrg-%d"
|
name = "acctestrg-%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
//}
|
}
|
||||||
//resource "azurerm_cdn_profile" "test" {
|
resource "azurerm_cdn_profile" "test" {
|
||||||
// name = "acctestcdnprof%d"
|
name = "acctestcdnprof%d"
|
||||||
// location = "West US"
|
location = "West US"
|
||||||
// resource_group_name = "${azurerm_resource_group.test.name}"
|
resource_group_name = "${azurerm_resource_group.test.name}"
|
||||||
// sku = "Standard"
|
sku = "Standard"
|
||||||
//
|
|
||||||
// tags {
|
tags {
|
||||||
// environment = "staging"
|
environment = "staging"
|
||||||
// }
|
}
|
||||||
//}
|
}
|
||||||
//`
|
`
|
||||||
|
|
Loading…
Reference in New Issue