Skip to content

Commit

Permalink
Merge pull request #511 from vmware/provider_info_data
Browse files Browse the repository at this point in the history
Introduce provider_info data source
  • Loading branch information
annakhm authored Nov 20, 2020
2 parents da15653 + f4b3d13 commit 260a1b1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
3 changes: 2 additions & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ TEST?=$$(go list ./... |grep -v 'vendor')
GOFMT_FILES?=$$(find . -name '*.go' |grep -v vendor)
WEBSITE_REPO=github.com/hashicorp/terraform-website
PKG_NAME=nsxt
GIT_COMMIT=$$(git rev-list -1 HEAD)

default: build

Expand All @@ -11,7 +12,7 @@ tools:
GO111MODULE=on go install -mod=mod github.com/katbyte/terrafmt

build: fmtcheck
go install
go install -ldflags "-X github.com/vmware/terraform-provider-nsxt/nsxt.GitCommit=$(GIT_COMMIT)"

test: fmtcheck
go test -i $(TEST) || exit 1
Expand Down
38 changes: 38 additions & 0 deletions nsxt/data_source_nsxt_provider_info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* Copyright © 2020 VMware, Inc. All Rights Reserved.
SPDX-License-Identifier: MPL-2.0 */

package nsxt

import (
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

var GitCommit string

func dataSourceNsxtProviderInfo() *schema.Resource {
return &schema.Resource{
Read: dataSourceNsxtProviderInfoRead,

Schema: map[string]*schema.Schema{
"commit": {
Type: schema.TypeString,
Description: "Latest commit hash",
Computed: true,
},
"date": {
Type: schema.TypeString,
Description: "Date compiled",
Computed: true,
},
},
}
}

func dataSourceNsxtProviderInfoRead(d *schema.ResourceData, m interface{}) error {
d.SetId("nsxt")
d.Set("commit", GitCommit)
d.Set("date", time.Now().Format(time.Stamp))
return nil
}
1 change: 1 addition & 0 deletions nsxt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func Provider() *schema.Provider {
},

DataSourcesMap: map[string]*schema.Resource{
"nsxt_provider_info": dataSourceNsxtProviderInfo(),
"nsxt_transport_zone": dataSourceNsxtTransportZone(),
"nsxt_switching_profile": dataSourceNsxtSwitchingProfile(),
"nsxt_logical_tier0_router": dataSourceNsxtLogicalTier0Router(),
Expand Down

0 comments on commit 260a1b1

Please sign in to comment.