Skip to content

Commit 9a89e1e

Browse files
committed
Update params options
1 parent 17fc1f2 commit 9a89e1e

10 files changed

+470
-36
lines changed

cloudstack/data_source_cloudstack_zone.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func dataSourceCloudstackZoneRead(d *schema.ResourceData, meta interface{}) erro
8787
}
8888

8989
func zoneDescriptionAttributes(d *schema.ResourceData, zone *cloudstack.Zone) error {
90-
d.SetId(zone.Name)
90+
d.SetId(zone.Id)
9191
d.Set("name", zone.Name)
9292
d.Set("dns1", zone.Dns1)
9393
d.Set("internal_dns1", zone.Internaldns1)

cloudstack/resource_cloudstack_physical_network.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,22 @@ func resourceCloudStackPhysicalNetwork() *schema.Resource {
4040
"broadcast_domain_range": {
4141
Type: schema.TypeString,
4242
Optional: true,
43+
ForceNew: true,
4344
},
4445
"domain_id": {
4546
Type: schema.TypeString,
4647
Optional: true,
48+
ForceNew: true,
4749
},
4850
"isolation_methods": {
4951
Type: schema.TypeString,
5052
Optional: true,
53+
ForceNew: true,
5154
},
5255
"name": {
5356
Type: schema.TypeString,
5457
Required: true,
58+
ForceNew: true,
5559
},
5660
"network_speed": {
5761
Type: schema.TypeString,
@@ -68,6 +72,7 @@ func resourceCloudStackPhysicalNetwork() *schema.Resource {
6872
"zone_id": {
6973
Type: schema.TypeString,
7074
Required: true,
75+
ForceNew: true,
7176
},
7277
},
7378
}

cloudstack/resource_cloudstack_physical_network_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ resource "cloudstack_physical_network" "test" {
5656
name = "test01"
5757
network_speed = "1G"
5858
tags = "vlan"
59-
zone_id = cloudstack_zone.test.id
59+
zone_id = cloudstack_zone.test.id
6060
}
6161
`
6262

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package cloudstack
21+
22+
import (
23+
"fmt"
24+
25+
"github.com/apache/cloudstack-go/v2/cloudstack"
26+
"github.com/hashicorp/terraform/helper/schema"
27+
)
28+
29+
func resourceCloudStackSecondaryStorage() *schema.Resource {
30+
return &schema.Resource{
31+
Create: resourceCloudStackSecondaryStorageCreate,
32+
Read: resourceCloudStackSecondaryStorageRead,
33+
Delete: resourceCloudStackSecondaryStorageDelete,
34+
Importer: &schema.ResourceImporter{
35+
State: schema.ImportStatePassthrough,
36+
},
37+
Schema: map[string]*schema.Schema{
38+
"name": {
39+
Type: schema.TypeString,
40+
Optional: true,
41+
Computed: true,
42+
ForceNew: true,
43+
},
44+
"storage_provider": {
45+
Type: schema.TypeString,
46+
Required: true,
47+
ForceNew: true,
48+
},
49+
"url": {
50+
Type: schema.TypeString,
51+
Optional: true,
52+
Computed: true,
53+
ForceNew: true,
54+
},
55+
"zone_id": {
56+
Type: schema.TypeString,
57+
Optional: true,
58+
Computed: true,
59+
ForceNew: true,
60+
},
61+
},
62+
}
63+
}
64+
65+
func resourceCloudStackSecondaryStorageCreate(d *schema.ResourceData, meta interface{}) error {
66+
cs := meta.(*cloudstack.CloudStackClient)
67+
68+
p := cs.ImageStore.NewAddImageStoreParams(d.Get("storage_provider").(string))
69+
if v, ok := d.GetOk("name"); ok {
70+
p.SetName(v.(string))
71+
}
72+
if v, ok := d.GetOk("url"); ok {
73+
p.SetUrl(v.(string))
74+
}
75+
if v, ok := d.GetOk("zone_id"); ok {
76+
p.SetZoneid(v.(string))
77+
}
78+
79+
r, err := cs.ImageStore.AddImageStore(p)
80+
if err != nil {
81+
return err
82+
}
83+
84+
d.SetId(r.Id)
85+
86+
return resourceCloudStackSecondaryStorageRead(d, meta)
87+
}
88+
89+
func resourceCloudStackSecondaryStorageRead(d *schema.ResourceData, meta interface{}) error {
90+
cs := meta.(*cloudstack.CloudStackClient)
91+
92+
r, _, err := cs.ImageStore.GetImageStoreByID(d.Id())
93+
if err != nil {
94+
return err
95+
}
96+
97+
d.Set("name", r.Name)
98+
d.Set("storage_provider", r.Providername)
99+
d.Set("url", r.Url)
100+
d.Set("zone_id", r.Zoneid)
101+
102+
return nil
103+
}
104+
105+
func resourceCloudStackSecondaryStorageDelete(d *schema.ResourceData, meta interface{}) error {
106+
cs := meta.(*cloudstack.CloudStackClient)
107+
108+
_, err := cs.ImageStore.DeleteImageStore(cs.ImageStore.NewDeleteImageStoreParams(d.Id()))
109+
if err != nil {
110+
return fmt.Errorf("Error deleting secondary storage: %s", err)
111+
}
112+
113+
return nil
114+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
19+
20+
package cloudstack
21+
22+
import (
23+
"testing"
24+
25+
"github.com/hashicorp/terraform/helper/resource"
26+
)
27+
28+
func TestAccCloudStackSecondaryStorage_basic(t *testing.T) {
29+
resource.Test(t, resource.TestCase{
30+
PreCheck: func() { testAccPreCheck(t) },
31+
Providers: testAccProviders,
32+
Steps: []resource.TestStep{
33+
{
34+
Config: testAccCloudStackSecondaryStorage_basic,
35+
},
36+
},
37+
})
38+
}
39+
40+
const testAccCloudStackSecondaryStorage_basic = `
41+
data "cloudstack_zone" "test" {
42+
filter {
43+
name = "name"
44+
value = "Sandbox-simulator"
45+
}
46+
}
47+
resource "cloudstack_secondary_storage" "test" {
48+
name = "acctest_secondarystorage"
49+
storage_provider = "NFS"
50+
url = "nfs://10.147.28.6:/export/home/sandbox/secondary"
51+
zone_id = data.cloudstack_zone.test.id
52+
}
53+
`

0 commit comments

Comments
 (0)