Skip to content

Commit d735249

Browse files
authored
Improve Content Library test (#72)
Signed-off-by: abarreiro <abarreiro@vmware.com>
1 parent cfc09e3 commit d735249

File tree

7 files changed

+143
-35
lines changed

7 files changed

+143
-35
lines changed

.changes/v1.0.0/12-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- **New Resource:** `vcfa_content_library` to manage Content Libraries [GH-12, GH-42, GH-43, GH-50, GH-53, GH-62, GH-69]
2-
- **New Data Source:** `vcfa_content_library` to read Content Libraries [GH-12, GH-42, GH-50, GH-53, GH-62, GH-69, GH-70]
1+
- **New Resource:** `vcfa_content_library` to manage Content Libraries [GH-12, GH-42, GH-43, GH-50, GH-53, GH-62, GH-69, GH-72]
2+
- **New Data Source:** `vcfa_content_library` to read Content Libraries [GH-12, GH-42, GH-50, GH-53, GH-62, GH-69, GH-70, GH-72]
33
- **New Data Source:** `vcfa_region_storage_policy` to read Region Storage Policies [GH-12]
44
- **New Data Source:** `vcfa_storage_class` to read Storage Classes [GH-12]

vcfa/config_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const (
3838
envSecondVcfaSysOrg = "VCFA_SYSORG2"
3939
)
4040

41+
// vsphereProviderVersion specifies the version of vSphere Terraform Provider
42+
var vsphereProviderVersion = "~> 2.11"
43+
4144
func init() {
4245

4346
// To list the flags when we run "go test -tags functional -vcfa-help", the flag name must start with "vcfa"
@@ -101,13 +104,12 @@ type TestConfig struct {
101104
SupervisorZone string `json:"supervisorZone"`
102105
} `json:"cci"`
103106
Tm struct {
104-
Org string `json:"org"`
105-
CreateRegion bool `json:"createRegion"`
106-
Region string `json:"region"`
107-
StorageClass string `json:"storageClass"`
108-
RegionVmClasses []string `json:"regionVmClasses"`
109-
ContentLibrary string `json:"contentLibrary"`
110-
SubscriptionContentLibraryUrl string `json:"subscriptionContentLibraryUrl"`
107+
Org string `json:"org"`
108+
CreateRegion bool `json:"createRegion"`
109+
Region string `json:"region"`
110+
StorageClass string `json:"storageClass"`
111+
RegionVmClasses []string `json:"regionVmClasses"`
112+
ContentLibrary string `json:"contentLibrary"`
111113

112114
CreateNsxManager bool `json:"createNsxManager"`
113115
NsxManagerUsername string `json:"nsxManagerUsername"`
@@ -121,6 +123,8 @@ type TestConfig struct {
121123
VcenterUsername string `json:"vcenterUsername"`
122124
VcenterPassword string `json:"vcenterPassword"`
123125
VcenterUrl string `json:"vcenterUrl"`
126+
VcenterDatacenter string `json:"vcenterDatacenter"`
127+
VcenterDatastore string `json:"vcenterDatastore"`
124128
VcenterStorageProfile string `json:"vcenterStorageProfile"`
125129
VcenterSupervisor string `json:"vcenterSupervisor"`
126130
VcenterSupervisorZone string `json:"vcenterSupervisorZone"`

vcfa/datasource_vcfa_content_library.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,6 @@ func datasourceVcfaContentLibrary() *schema.Resource {
7575
Computed: true,
7676
Description: fmt.Sprintf("Subscription url of this %s", labelVcfaContentLibrary),
7777
},
78-
"password": {
79-
Type: schema.TypeString,
80-
Computed: true,
81-
Description: "Password to use to authenticate with the publisher",
82-
},
8378
},
8479
},
8580
},
@@ -103,7 +98,9 @@ func datasourceVcfaContentLibraryRead(ctx context.Context, d *schema.ResourceDat
10398
}
10499
return tmClient.GetContentLibraryByName(name, tenantContext)
105100
},
106-
stateStoreFunc: setContentLibraryData,
101+
stateStoreFunc: func(tmClient *VCDClient, d *schema.ResourceData, outerType *govcd.ContentLibrary) error {
102+
return setContentLibraryData(tmClient, d, outerType, "datasource")
103+
},
107104
}
108105
return readDatasource(ctx, d, meta, c)
109106
}

vcfa/resource_vcfa_content_library.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,19 @@ func resourceVcfaContentLibrary() *schema.Resource {
9696
Type: schema.TypeList,
9797
MaxItems: 1,
9898
Optional: true,
99-
ForceNew: true, // Can't change subscription settings
10099
Description: fmt.Sprintf("A block representing subscription settings of a %s", labelVcfaContentLibrary),
101100
Elem: &schema.Resource{
102101
Schema: map[string]*schema.Schema{
103102
"subscription_url": {
104103
Type: schema.TypeString,
105104
Required: true,
105+
ForceNew: true, // Can't change subscription url
106106
Description: fmt.Sprintf("Subscription url of this %s", labelVcfaContentLibrary),
107107
},
108108
"password": {
109109
Type: schema.TypeString,
110-
Optional: true, // Required at Runtime as cannot be Required + Computed in schema. (It is computed as password cannot be recovered)
111-
Computed: true,
110+
Optional: true,
111+
Sensitive: true,
112112
Description: "Password to use to authenticate with the publisher",
113113
},
114114
},
@@ -133,7 +133,7 @@ func resourceVcfaContentLibraryCreate(ctx context.Context, d *schema.ResourceDat
133133
if err != nil {
134134
return diag.FromErr(err)
135135
}
136-
err = setContentLibraryData(tmClient, d, cl)
136+
err = setContentLibraryData(tmClient, d, cl, "resource")
137137
if err != nil {
138138
return diag.FromErr(err)
139139
}
@@ -163,7 +163,7 @@ func resourceVcfaContentLibraryRead(_ context.Context, d *schema.ResourceData, m
163163
return diag.FromErr(err)
164164
}
165165

166-
err = setContentLibraryData(tmClient, d, cl)
166+
err = setContentLibraryData(tmClient, d, cl, "resource")
167167
if err != nil {
168168
return diag.FromErr(err)
169169
}
@@ -261,7 +261,7 @@ func getContentLibraryType(d *schema.ResourceData) *types.ContentLibrary {
261261
return t
262262
}
263263

264-
func setContentLibraryData(_ *VCDClient, d *schema.ResourceData, cl *govcd.ContentLibrary) error {
264+
func setContentLibraryData(_ *VCDClient, d *schema.ResourceData, cl *govcd.ContentLibrary, origin string) error {
265265
if cl == nil || cl.ContentLibrary == nil {
266266
return fmt.Errorf("provided %s is nil", labelVcfaContentLibrary)
267267
}
@@ -292,10 +292,17 @@ func setContentLibraryData(_ *VCDClient, d *schema.ResourceData, cl *govcd.Conte
292292
subscriptionConfig = []interface{}{
293293
map[string]interface{}{
294294
"subscription_url": cl.ContentLibrary.SubscriptionConfig.SubscriptionUrl,
295-
"password": cl.ContentLibrary.SubscriptionConfig.Password,
296295
},
297296
}
297+
// Password is only available in resource
298+
if origin == "resource" {
299+
// Password is never returned by backend. We save what we have currently
300+
if p := d.Get("subscription_config.0.password"); p != "" {
301+
subscriptionConfig[0].(map[string]interface{})["password"] = p
302+
}
303+
}
298304
}
305+
299306
err = d.Set("subscription_config", subscriptionConfig)
300307
if err != nil {
301308
return err

0 commit comments

Comments
 (0)