Skip to content

Commit

Permalink
Merge pull request #6 from deploymenttheory/feature-scaffolding
Browse files Browse the repository at this point in the history
Updated docs
  • Loading branch information
ShocOne authored Jul 20, 2024
2 parents 0049f7a + 67da109 commit 5b9a216
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 41 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# Terraform Provider for Microsoft 365
# Community Terraform Provider for Microsoft 365

## Disclaimer
The community Microsoft 365 Terraform Provider allows managing environments and other resources within [Intune](https://intune.microsoft.com/) , [Office365](https://www.office.com/
), [MicrosoftTeams](https://teams.microsoft.com/
) and [MicrosoftSecurity](https://security.microsoft.com/
).

**This project is under active development, and new releases for specific resource types may introduce changes that are not backward compatible with previous release versions. Users should be aware that older implementations may break with updates. We recommend thoroughly reviewing release notes and testing new versions in a staging environment before deploying to production.**
> [!WARNING]
> This code is experimental and provided solely for evaluation purposes. It is **NOT** intended for production use and may contain bugs, incomplete features, or other issues. Use at your own risk, as it may undergo significant changes without notice until it reaches general availability, and no guarantees or support is provided. By using this code, you acknowledge and agree to these conditions. Consult the documentation or contact the maintainer if you have questions or concerns.
# To-Do List

Expand Down
23 changes: 23 additions & 0 deletions internal/provider/datasources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package provider

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/datasource"
)

// DataSources returns a slice of functions that each return a datasource.DataSource.
// This function is a method of the M365Provider type and takes a context.Context as an argument.
// The returned slice is intended to hold the Microsoft 365 provider datasources.
//
// Parameters:
// - ctx: The context for controlling cancellation and timeout.
//
// Returns:
//
// []func() datasource.DataSource: A slice of functions, each returning a datasource.DataSource.
func (p *M365Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
// Add microsoft 365 provider datasources here
}
}
62 changes: 24 additions & 38 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
azidentity "github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
khttp "github.com/microsoft/kiota-http-go"
Expand All @@ -33,27 +31,27 @@ type M365Provider struct {

// M365ProviderModel describes the provider data model.
type M365ProviderModel struct {
TenantID types.String `tfsdk:"tenant_id"`
AuthMethod types.String `tfsdk:"auth_method"`
ClientID types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
CertificatePath types.String `tfsdk:"certificate_path"`
UserAssertion types.String `tfsdk:"user_assertion"`
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`
RedirectURL types.String `tfsdk:"redirect_url"`
Token types.String `tfsdk:"token"`
UseGraphBeta types.Bool `tfsdk:"use_graph_beta"`
UseProxy types.Bool `tfsdk:"use_proxy"`
ProxyURL types.String `tfsdk:"proxy_url"`
EnableChaos types.Bool `tfsdk:"enable_chaos"`
NationalCloudDeployment types.Bool `tfsdk:"national_cloud_deployment"`
NationalCloudDeploymentTokenEndpoint types.String `tfsdk:"national_cloud_deployment_token_endpoint"`
NationalCloudDeploymentServiceRoot types.String `tfsdk:"national_cloud_deployment_service_root"`
TenantID types.String `tfsdk:"tenant_id"`
AuthMethod types.String `tfsdk:"auth_method"`
ClientID types.String `tfsdk:"client_id"`
ClientSecret types.String `tfsdk:"client_secret"`
CertificatePath types.String `tfsdk:"certificate_path"`
UserAssertion types.String `tfsdk:"user_assertion"`
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`
RedirectURL types.String `tfsdk:"redirect_url"`
Token types.String `tfsdk:"token"`
UseGraphBeta types.Bool `tfsdk:"use_graph_beta"`
UseProxy types.Bool `tfsdk:"use_proxy"`
ProxyURL types.String `tfsdk:"proxy_url"`
EnableChaos types.Bool `tfsdk:"enable_chaos"`
NationalCloudDeployment types.Bool `tfsdk:"national_cloud_deployment"`
NationalCloudDeploymentTokenEndpoint types.String `tfsdk:"national_cloud_deployment_token_endpoint"`
NationalCloudDeploymentServiceEndpointRoot types.String `tfsdk:"national_cloud_deployment_service_endpoint_root"`
}

func (p *M365Provider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "M365"
resp.TypeName = "Microsoft365"
resp.Version = p.version
}

Expand Down Expand Up @@ -172,13 +170,13 @@ func (p *M365Provider) Schema(ctx context.Context, req provider.SchemaRequest, r
},
"national_cloud_deployment_token_endpoint": schema.StringAttribute{
Optional: true,
Description: "By default, the provider is configured to access data in the Microsoft Graph global service, using the https://graph.microsoft.com root URL to access the Microsoft Graph REST API. This field overrides this configuration to connect to Microsoft Graph national cloud deployments. Microsoft Cloud for US Government and Microsoft Azure and Microsoft 365 operated by 21Vianet in China. https://learn.microsoft.com/en-gb/graph/deployments",
Description: "By default, the provider is configured to access data in the Microsoft Graph global service, using the https://login.microsoftonline.com root URL to access the Microsoft Graph REST API. This field overrides this configuration to connect to Microsoft Graph national cloud deployments. Microsoft Cloud for US Government and Microsoft Azure and Microsoft 365 operated by 21Vianet in China. https://learn.microsoft.com/en-gb/graph/deployments",
Validators: []validator.String{
validateURL(),
validateNationalCloudDeployment(),
},
},
"national_cloud_deployment_service_root": schema.StringAttribute{
"national_cloud_deployment_service_endpoint_root": schema.StringAttribute{
Optional: true,
Description: "The Microsoft Graph service root endpoint for the national cloud deployment. Overrides the default Microsoft Graph service root endpoint (https://graph.microsoft.com/v1.0 / https://graph.microsoft.com/beta).This field overrides this configuration to connect to Microsoft Graph national cloud deployments. Microsoft Cloud for US Government and Microsoft Azure and Microsoft 365 operated by 21Vianet in China. https://learn.microsoft.com/en-gb/graph/deployments",
Validators: []validator.String{
Expand Down Expand Up @@ -236,7 +234,7 @@ func (p *M365Provider) Configure(ctx context.Context, req provider.ConfigureRequ
enableChaos := data.EnableChaos.ValueBool()
nationalCloudDeployment := data.NationalCloudDeployment.ValueBool()
nationalCloudDeploymentTokenEndpoint := data.NationalCloudDeploymentTokenEndpoint.ValueString()
nationalCloudDeploymentServiceRoot := data.NationalCloudDeploymentServiceRoot.ValueString()
NationalCloudDeploymentServiceEndpointRoot := data.NationalCloudDeploymentServiceEndpointRoot.ValueString()

var cred azcore.TokenCredential
var err error
Expand Down Expand Up @@ -445,11 +443,11 @@ func (p *M365Provider) Configure(ctx context.Context, req provider.ConfigureRequ
}

// Set the service root for national cloud deployments
if nationalCloudDeployment && nationalCloudDeploymentServiceRoot != "" {
if nationalCloudDeployment && NationalCloudDeploymentServiceEndpointRoot != "" {
if useGraphBeta {
betaAdapter.SetBaseUrl(fmt.Sprintf("%s/v1.0", nationalCloudDeploymentServiceRoot))
betaAdapter.SetBaseUrl(fmt.Sprintf("%s/v1.0", NationalCloudDeploymentServiceEndpointRoot))
} else {
stableAdapter.SetBaseUrl(fmt.Sprintf("%s/v1.0", nationalCloudDeploymentServiceRoot))
stableAdapter.SetBaseUrl(fmt.Sprintf("%s/v1.0", NationalCloudDeploymentServiceEndpointRoot))
}
}

Expand All @@ -466,18 +464,6 @@ func (p *M365Provider) Configure(ctx context.Context, req provider.ConfigureRequ

}

func (p *M365Provider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
// Add your resource functions here
}
}

func (p *M365Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
// Add your datasource functions here
}
}

func New(version string) func() provider.Provider {
return func() provider.Provider {
return &M365Provider{
Expand Down
23 changes: 23 additions & 0 deletions internal/provider/resources.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package provider

import (
"context"

"github.com/hashicorp/terraform-plugin-framework/resource"
)

// Resources returns a slice of functions that each return a resource.Resource.
// This function is a method of the M365Provider type and takes a context.Context as an argument.
// The returned slice is intended to hold the Microsoft 365 provider resources.
//
// Parameters:
// - ctx: The context for controlling cancellation and timeout.
//
// Returns:
//
// []func() resource.Resource: A slice of functions, each returning a resource.Resource.
func (p *M365Provider) Resources(ctx context.Context) []func() resource.Resource {
return []func() resource.Resource{
// Add microsoft 365 provider resources here
}
}

0 comments on commit 5b9a216

Please sign in to comment.