@@ -42,6 +42,61 @@ func resourceCloudStackServiceOffering() *schema.Resource {
4242 Type : schema .TypeString ,
4343 Required : true ,
4444 },
45+ "cpu_number" : {
46+ Description : "Number of CPU cores" ,
47+ Type : schema .TypeInt ,
48+ Optional : true ,
49+ ForceNew : true ,
50+ },
51+ "cpu_speed" : {
52+ Description : "Speed of CPU in Mhz" ,
53+ Type : schema .TypeInt ,
54+ Optional : true ,
55+ ForceNew : true ,
56+ },
57+ "host_tags" : {
58+ Description : "The host tag for this service offering" ,
59+ Type : schema .TypeString ,
60+ Optional : true ,
61+ },
62+ "limit_cpu_use" : {
63+ Description : "Restrict the CPU usage to committed service offering" ,
64+ Type : schema .TypeBool ,
65+ Optional : true ,
66+ ForceNew : true ,
67+ Default : false ,
68+ },
69+ "memory" : {
70+ Description : "The total memory of the service offering in MB" ,
71+ Type : schema .TypeInt ,
72+ Optional : true ,
73+ ForceNew : true ,
74+ },
75+ "offer_ha" : {
76+ Description : "The HA for the service offering" ,
77+ Type : schema .TypeBool ,
78+ Optional : true ,
79+ ForceNew : true ,
80+ Default : false ,
81+ },
82+ "storage_type" : {
83+ Description : "The storage type of the service offering. Values are local and shared" ,
84+ Type : schema .TypeString ,
85+ Optional : true ,
86+ ForceNew : true ,
87+ Default : "shared" ,
88+ ValidateFunc : func (val interface {}, key string ) (warns []string , errs []error ) {
89+ v := val .(string )
90+
91+ if v == "local" || v == "shared" {
92+ return
93+ }
94+
95+ errs = append (errs , fmt .Errorf ("storage type should be either local or shared, got %s" , v ))
96+
97+ return
98+ },
99+ },
45100 },
46101 }
47102}
@@ -53,6 +108,33 @@ func resourceCloudStackServiceOfferingCreate(d *schema.ResourceData, meta interf
53108
54109 // Create a new parameter struct
55110 p := cs .ServiceOffering .NewCreateServiceOfferingParams (display_text , name )
111+ if v , ok := d .GetOk ("cpu_number" ); ok {
112+ p .SetCpunumber (v .(int ))
113+ }
114+
115+ if v , ok := d .GetOk ("cpu_speed" ); ok {
116+ p .SetCpuspeed (v .(int ))
117+ }
118+
119+ if v , ok := d .GetOk ("host_tags" ); ok {
120+ p .SetHosttags (v .(string ))
121+ }
122+
123+ if v , ok := d .GetOk ("limit_cpu_use" ); ok {
124+ p .SetLimitcpuuse (v .(bool ))
125+ }
126+
127+ if v , ok := d .GetOk ("memory" ); ok {
128+ p .SetMemory (v .(int ))
129+ }
130+
131+ if v , ok := d .GetOk ("offer_ha" ); ok {
132+ p .SetOfferha (v .(bool ))
133+ }
134+
135+ if v , ok := d .GetOk ("storage_type" ); ok {
136+ p .SetStoragetype (v .(string ))
137+ }
56138
57139 log .Printf ("[DEBUG] Creating Service Offering %s" , name )
58140 s , err := cs .ServiceOffering .CreateServiceOffering (p )
@@ -84,8 +166,22 @@ func resourceCloudStackServiceOfferingRead(d *schema.ResourceData, meta interfac
84166 }
85167
86168 d .SetId (s .Id )
87- d .Set ("name" , s .Name )
88- d .Set ("display_text" , s .Displaytext )
169+
170+ fields := map [string ]interface {}{
171+ "name" : s .Name ,
172+ "display_text" : s .Displaytext ,
173+ "cpu_number" : s .Cpunumber ,
174+ "cpu_speed" : s .Cpuspeed ,
175+ "host_tags" : s .Hosttags ,
176+ "limit_cpu_use" : s .Limitcpuuse ,
177+ "memory" : s .Memory ,
178+ "offer_ha" : s .Offerha ,
179+ "storage_type" : s .Storagetype ,
180+ }
181+
182+ for k , v := range fields {
183+ d .Set (k , v )
184+ }
89185
90186 return nil
91187}
@@ -136,6 +232,25 @@ func resourceCloudStackServiceOfferingUpdate(d *schema.ResourceData, meta interf
136232 d .SetPartial ("display_text" )
137233 }
138234
235+ if d .HasChange ("host_tags" ) {
236+ log .Printf ("[DEBUG] Host tags changed for %s, starting update" , name )
237+
238+ // Create a new parameter struct
239+ p := cs .ServiceOffering .NewUpdateServiceOfferingParams (d .Id ())
240+
241+ // Set the new host tags
242+ p .SetHosttags (d .Get ("host_tags" ).(string ))
243+
244+ // Update the host tags
245+ _ , err := cs .ServiceOffering .UpdateServiceOffering (p )
246+ if err != nil {
247+ return fmt .Errorf (
248+ "Error updating the host tags for service offering %s: %s" , name , err )
249+ }
250+
251+ d .SetPartial ("host_tags" )
252+ }
253+
139254 d .Partial (false )
140255
141256 return resourceCloudStackServiceOfferingRead (d , meta )
0 commit comments