Пример #1
0
func resourceArmCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*ArmClient)
	cdnEndpointsClient := client.cdnEndpointsClient

	log.Printf("[INFO] preparing arguments for Azure ARM CDN EndPoint creation.")

	name := d.Get("name").(string)
	location := d.Get("location").(string)
	resGroup := d.Get("resource_group_name").(string)
	profileName := d.Get("profile_name").(string)
	http_allowed := d.Get("is_http_allowed").(bool)
	https_allowed := d.Get("is_https_allowed").(bool)
	compression_enabled := d.Get("is_compression_enabled").(bool)
	caching_behaviour := d.Get("querystring_caching_behaviour").(string)
	tags := d.Get("tags").(map[string]interface{})

	properties := cdn.EndpointPropertiesCreateUpdateParameters{
		IsHTTPAllowed:              &http_allowed,
		IsHTTPSAllowed:             &https_allowed,
		IsCompressionEnabled:       &compression_enabled,
		QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
	}

	origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
	if originsErr != nil {
		return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
	}
	if len(origins) > 0 {
		properties.Origins = &origins
	}

	if v, ok := d.GetOk("origin_host_header"); ok {
		host_header := v.(string)
		properties.OriginHostHeader = &host_header
	}

	if v, ok := d.GetOk("origin_path"); ok {
		origin_path := v.(string)
		properties.OriginPath = &origin_path
	}

	if v, ok := d.GetOk("content_types_to_compress"); ok {
		var content_types []string
		ctypes := v.(*schema.Set).List()
		for _, ct := range ctypes {
			str := ct.(string)
			content_types = append(content_types, str)
		}

		properties.ContentTypesToCompress = &content_types
	}

	cdnEndpoint := cdn.EndpointCreateParameters{
		Location:   &location,
		Properties: &properties,
		Tags:       expandTags(tags),
	}

	resp, err := cdnEndpointsClient.Create(name, cdnEndpoint, profileName, resGroup)
	if err != nil {
		return err
	}

	d.SetId(*resp.ID)

	log.Printf("[DEBUG] Waiting for CDN Endpoint (%s) to become available", name)
	stateConf := &resource.StateChangeConf{
		Pending: []string{"Accepted", "Updating", "Creating"},
		Target:  []string{"Succeeded"},
		Refresh: cdnEndpointStateRefreshFunc(client, resGroup, profileName, name),
		Timeout: 10 * time.Minute,
	}
	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)
}
Пример #2
0
func resourceArmCdnEndpointUpdate(d *schema.ResourceData, meta interface{}) error {
	cdnEndpointsClient := meta.(*ArmClient).cdnEndpointsClient

	if !d.HasChange("tags") {
		return nil
	}

	name := d.Get("name").(string)
	resGroup := d.Get("resource_group_name").(string)
	profileName := d.Get("profile_name").(string)
	http_allowed := d.Get("is_http_allowed").(bool)
	https_allowed := d.Get("is_https_allowed").(bool)
	compression_enabled := d.Get("is_compression_enabled").(bool)
	caching_behaviour := d.Get("querystring_caching_behaviour").(string)
	newTags := d.Get("tags").(map[string]interface{})

	properties := cdn.EndpointPropertiesCreateUpdateParameters{
		IsHTTPAllowed:              &http_allowed,
		IsHTTPSAllowed:             &https_allowed,
		IsCompressionEnabled:       &compression_enabled,
		QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
	}

	if d.HasChange("origin") {
		origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
		if originsErr != nil {
			return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
		}
		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_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()
		for _, ct := range ctypes {
			str := ct.(string)
			content_types = append(content_types, str)
		}

		properties.ContentTypesToCompress = &content_types
	}

	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)
	}

	return resourceArmCdnEndpointRead(d, meta)
}
func resourceArmCdnEndpointCreate(d *schema.ResourceData, meta interface{}) error {
	client := meta.(*ArmClient)
	cdnEndpointsClient := client.cdnEndpointsClient

	log.Printf("[INFO] preparing arguments for Azure ARM CDN EndPoint creation.")

	name := d.Get("name").(string)
	location := d.Get("location").(string)
	resGroup := d.Get("resource_group_name").(string)
	profileName := d.Get("profile_name").(string)
	http_allowed := d.Get("is_http_allowed").(bool)
	https_allowed := d.Get("is_https_allowed").(bool)
	compression_enabled := d.Get("is_compression_enabled").(bool)
	caching_behaviour := d.Get("querystring_caching_behaviour").(string)
	tags := d.Get("tags").(map[string]interface{})

	properties := cdn.EndpointPropertiesCreateUpdateParameters{
		IsHTTPAllowed:              &http_allowed,
		IsHTTPSAllowed:             &https_allowed,
		IsCompressionEnabled:       &compression_enabled,
		QueryStringCachingBehavior: cdn.QueryStringCachingBehavior(caching_behaviour),
	}

	origins, originsErr := expandAzureRmCdnEndpointOrigins(d)
	if originsErr != nil {
		return fmt.Errorf("Error Building list of CDN Endpoint Origins: %s", originsErr)
	}
	if len(origins) > 0 {
		properties.Origins = &origins
	}

	if v, ok := d.GetOk("origin_host_header"); ok {
		host_header := v.(string)
		properties.OriginHostHeader = &host_header
	}

	if v, ok := d.GetOk("origin_path"); ok {
		origin_path := v.(string)
		properties.OriginPath = &origin_path
	}

	if v, ok := d.GetOk("content_types_to_compress"); ok {
		var content_types []string
		ctypes := v.(*schema.Set).List()
		for _, ct := range ctypes {
			str := ct.(string)
			content_types = append(content_types, str)
		}

		properties.ContentTypesToCompress = &content_types
	}

	cdnEndpoint := cdn.EndpointCreateParameters{
		Location:   &location,
		Properties: &properties,
		Tags:       expandTags(tags),
	}

	_, err := cdnEndpointsClient.Create(name, cdnEndpoint, profileName, resGroup, make(chan struct{}))
	if err != nil {
		return err
	}

	read, err := cdnEndpointsClient.Get(name, profileName, resGroup)
	if err != nil {
		return err
	}
	if read.ID == nil {
		return fmt.Errorf("Cannot read CND Endpoint %s/%s (resource group %s) ID", profileName, name, resGroup)
	}

	d.SetId(*read.ID)

	return resourceArmCdnEndpointRead(d, meta)
}