-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Can handler the template - Add data source civo_template - Add new feature to the instances, can import now one instance, fixx error to add notes to a instance - Fix error message in the resource_loadbalance - Update to civogo v0.2.2 BREAKING CHANGE: No Signed-off-by: Alejandro JNM <alejandrojnm@gmail.com>
- Loading branch information
1 parent
04c84fe
commit 79ff73a
Showing
8 changed files
with
319 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package civo | ||
|
||
import ( | ||
"fmt" | ||
"github.com/civo/civogo" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/validation" | ||
) | ||
|
||
func dataSourceTemplate() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceTemplateRead, | ||
Schema: map[string]*schema.Schema{ | ||
"code": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "code of the image", | ||
ValidateFunc: validation.NoZeroValues, | ||
}, | ||
// computed attributes | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "name of the image", | ||
}, | ||
"volume_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "volume_id of the image", | ||
}, | ||
"image_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "image_id of the image", | ||
}, | ||
"short_description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "short_description of the image", | ||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "description of the image", | ||
}, | ||
"default_username": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "default_username of the image", | ||
}, | ||
"cloud_config": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "cloud_config of the image", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceTemplateRead(d *schema.ResourceData, m interface{}) error { | ||
apiClient := m.(*civogo.Client) | ||
|
||
code, hasCode := d.GetOk("code") | ||
|
||
if !hasCode { | ||
return fmt.Errorf("`code` must be assigned") | ||
} | ||
|
||
if hasCode { | ||
image, err := apiClient.GetTemplateByCode(code.(string)) | ||
if err != nil { | ||
fmt.Errorf("[ERR] failed to retrive template: %s", err) | ||
return err | ||
} | ||
|
||
d.SetId(image.ID) | ||
d.Set("code", image.Code) | ||
d.Set("name", image.Name) | ||
d.Set("volume_id", image.VolumeID) | ||
d.Set("image_id", image.ImageID) | ||
d.Set("short_description", image.ShortDescription) | ||
d.Set("description", image.Description) | ||
d.Set("default_username", image.DefaultUsername) | ||
d.Set("cloud_config", image.CloudConfig) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.