From d5770b57a6099efcc5cbcad9b718b3a5681e81a3 Mon Sep 17 00:00:00 2001 From: Sabari Jaganathan <93724860+sajagana@users.noreply.github.com> Date: Mon, 26 Aug 2024 17:36:50 +0530 Subject: [PATCH] [ignore] Added getBaseSiteResourceModel function to the nd_site resource --- internal/provider/provider.go | 2 +- internal/provider/resource_nd_site.go | 19 ++++++++++++++++++- internal/provider/resource_nd_site_test.go | 11 ----------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 83d7914..a098209 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -35,7 +35,7 @@ func New(version string) func() provider.Provider { // ndProvider is the provider implementation. type ndProvider struct { // version is set to the provider version on release, "dev" when the - // provider is built and ran locally, and "test" when running acceptance + // provider is built and run locally, and "test" when running acceptance // testing. version string } diff --git a/internal/provider/resource_nd_site.go b/internal/provider/resource_nd_site.go index 1a6f730..951d3b3 100644 --- a/internal/provider/resource_nd_site.go +++ b/internal/provider/resource_nd_site.go @@ -63,6 +63,21 @@ type SiteResourceModel struct { Longitude types.String `tfsdk:"longitude"` } +func getBaseSiteResourceModel(username, password, login_domain string) *SiteResourceModel { + return &SiteResourceModel{ + Id: basetypes.NewStringNull(), + SiteName: basetypes.NewStringNull(), + SitePassword: basetypes.NewStringValue(password), + SiteUsername: basetypes.NewStringValue(username), + LoginDomain: basetypes.NewStringValue(login_domain), + InbandEpg: basetypes.NewStringNull(), + Url: basetypes.NewStringNull(), + SiteType: basetypes.NewStringNull(), + Latitude: basetypes.NewStringNull(), + Longitude: basetypes.NewStringNull(), + } +} + func (r *SiteResource) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { tflog.Debug(ctx, "Start metadata of resource: nd_site") resp.TypeName = req.ProviderTypeName + "_site" @@ -428,6 +443,7 @@ func setSiteId(ctx context.Context, data *SiteResourceModel) { func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, client *Client, data *SiteResourceModel) { responseData := DoRestRequest(ctx, diags, client, fmt.Sprintf("%s/%s", sitePath, data.Id.ValueString()), "GET", nil) + *data = *getBaseSiteResourceModel(data.SiteUsername.ValueString(), data.SitePassword.ValueString(), data.LoginDomain.ValueString()) if diags.HasError() { return @@ -439,6 +455,7 @@ func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, clien for attributeName, attributeValue := range specReadInfo { if attributeName == "name" { data.SiteName = basetypes.NewStringValue(attributeValue.(string)) + data.Id = basetypes.NewStringValue(attributeValue.(string)) } if attributeName == "siteConfig" { @@ -463,7 +480,7 @@ func getAndSetSiteAttributes(ctx context.Context, diags *diag.Diagnostics, clien if os.Getenv("ND_LOGIN_DOMAIN") != "" { data.LoginDomain = basetypes.NewStringValue(os.Getenv("ND_LOGIN_DOMAIN")) - } else if attributeName == "loginDomain" && data.LoginDomain.IsUnknown() { + } else if attributeName == "loginDomain" { data.LoginDomain = basetypes.NewStringValue(attributeValue.(string)) } } diff --git a/internal/provider/resource_nd_site_test.go b/internal/provider/resource_nd_site_test.go index 1e68184..03c178e 100644 --- a/internal/provider/resource_nd_site_test.go +++ b/internal/provider/resource_nd_site_test.go @@ -62,17 +62,6 @@ func TestAccResourceNdSiteWithImportTest(t *testing.T) { ResourceName: "nd_site.example_2", ImportState: true, ImportStateVerify: true, - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("nd_site.example_2", "inband_epg", "test_epg"), - resource.TestCheckResourceAttr("nd_site.example_2", "latitude", ""), - resource.TestCheckResourceAttr("nd_site.example_2", "login_domain", "local"), - resource.TestCheckResourceAttr("nd_site.example_2", "longitude", ""), - resource.TestCheckResourceAttr("nd_site.example_2", "name", "example_2"), - resource.TestCheckResourceAttr("nd_site.example_2", "password", "password"), - resource.TestCheckResourceAttr("nd_site.example_2", "type", "aci"), - resource.TestCheckResourceAttr("nd_site.example_2", "username", "admin"), - resource.TestCheckResourceAttr("nd_site.example_2", "url", "10.195.219.155"), - ), }, // Update with full config and verify default ND values {