@@ -45,6 +45,10 @@ type RegistryModules interface {
45
45
// ReadVersion Read a registry module version
46
46
ReadVersion (ctx context.Context , moduleID RegistryModuleID , version string ) (* RegistryModuleVersion , error )
47
47
48
+ // ReadRegistry Reads a registry module from the Terraform Registry.
49
+ // https://developer.hashicorp.com/terraform/enterprise/api-docs/private-registry/modules#hcp-terraform-registry-implementation
50
+ ReadRegistry (ctx context.Context , moduleID RegistryModuleID , version string ) (* TerraformRegistryModule , error )
51
+
48
52
// Delete a registry module
49
53
// Warning: This method is deprecated and will be removed from a future version of go-tfe. Use DeleteByName instead.
50
54
Delete (ctx context.Context , organization string , name string ) error
@@ -70,6 +74,66 @@ type RegistryModules interface {
70
74
UploadTarGzip (ctx context.Context , url string , r io.Reader ) error
71
75
}
72
76
77
+ // TerraformRegistryModule contains data about a module from the Terraform Registry.
78
+ type TerraformRegistryModule struct {
79
+ ID string `json:"id"`
80
+ Owner string `json:"owner"`
81
+ Namespace string `json:"namespace"`
82
+ Name string `json:"name"`
83
+ Version string `json:"version"`
84
+ Provider string `json:"provider"`
85
+ ProviderLogoURL string `json:"provider_logo_url"`
86
+ Description string `json:"description"`
87
+ Source string `json:"source"`
88
+ Tag string `json:"tag"`
89
+ PublishedAt string `json:"published_at"`
90
+ Downloads int `json:"downloads"`
91
+ Verified bool `json:"verified"`
92
+ Root `json:"root"`
93
+ // Submodules []Submodule `json:"submodules"`
94
+ // Examples []Example `json:"examples"`
95
+ Providers []string `json:"providers"`
96
+ Versions []string `json:"versions"`
97
+ // Deprecation *Deprecation `json:"deprecation"`
98
+ }
99
+
100
+ type Root struct {
101
+ Path string `json:"path"`
102
+ Name string `json:"name"`
103
+ Readme string `json:"readme"`
104
+ Empty bool `json:"empty"`
105
+ Inputs []Input `json:"inputs"`
106
+ Outputs []Output `json:"outputs"`
107
+ // Dependencies []Dependency `json:"dependencies"`
108
+ ProviderDependencies []ProviderDependency `json:"provider_dependencies"`
109
+ Resources []Resource `json:"resources"`
110
+ }
111
+
112
+ type Input struct {
113
+ Name string `json:"name"`
114
+ Type string `json:"type"`
115
+ Description string `json:"description"`
116
+ Default string `json:"default"`
117
+ Required bool `json:"required"`
118
+ }
119
+
120
+ type Output struct {
121
+ Name string `json:"name"`
122
+ Description string `json:"description"`
123
+ }
124
+
125
+ type ProviderDependency struct {
126
+ Name string `json:"name"`
127
+ Namespace string `json:"namespace"`
128
+ Source string `json:"source"`
129
+ Version string `json:"version"`
130
+ }
131
+
132
+ type Resource struct {
133
+ Name string `json:"name"`
134
+ Type string `json:"type"`
135
+ }
136
+
73
137
// registryModules implements RegistryModules.
74
138
type registryModules struct {
75
139
client * Client
@@ -572,6 +636,38 @@ func (r *registryModules) Read(ctx context.Context, moduleID RegistryModuleID) (
572
636
573
637
return rm , nil
574
638
}
639
+
640
+ // ReadRegistry fetches a registry module from the Terraform Registry.
641
+ func (r * registryModules ) ReadRegistry (ctx context.Context , moduleID RegistryModuleID , version string ) (* TerraformRegistryModule , error ) {
642
+ u := fmt .Sprintf (
643
+ "https://app.terraform.io/api/registry/v1/modules/%s/%s/%s/%s" ,
644
+ moduleID .Namespace ,
645
+ moduleID .Name ,
646
+ moduleID .Provider ,
647
+ version ,
648
+ )
649
+ if moduleID .RegistryName == PublicRegistry {
650
+ u = fmt .Sprintf (
651
+ "https://app.terraform.io/api/registry/public/v1/modules/%s/%s/%s/%s" ,
652
+ moduleID .Namespace ,
653
+ moduleID .Name ,
654
+ moduleID .Provider ,
655
+ version ,
656
+ )
657
+ }
658
+ req , err := r .client .NewRequest ("GET" , u , nil )
659
+ if err != nil {
660
+ return nil , err
661
+ }
662
+
663
+ trm := & TerraformRegistryModule {}
664
+ err = req .DoJSON (ctx , trm )
665
+ if err != nil {
666
+ return nil , err
667
+ }
668
+ return trm , nil
669
+ }
670
+
575
671
func (r * registryModules ) ReadVersion (ctx context.Context , moduleID RegistryModuleID , version string ) (* RegistryModuleVersion , error ) {
576
672
if err := moduleID .valid (); err != nil {
577
673
return nil , err
0 commit comments