Skip to content

Commit 5dd974b

Browse files
committed
Merge branch 'enpolat/45-resource-powerplatform_data_record' of https://github.com/microsoft/terraform-provider-power-platform into enpolat/45-resource-powerplatform_data_record
2 parents bc35671 + 73b0014 commit 5dd974b

File tree

53 files changed

+498
-229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+498
-229
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Power Platform Terraform Provider Development",
55
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6-
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
6+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu22.04",
77
// Features to add to the dev container. More info: https://containers.dev/features.
88
"features": {
99
"ghcr.io/devcontainers/features/azure-cli:1": {
@@ -18,7 +18,7 @@
1818
"terragrunt": "latest"
1919
},
2020
"ghcr.io/devcontainers/features/go:1": {
21-
"version": "latest"
21+
"version": "1.22.3"
2222
},
2323
"./features/acceptance_test_dependencies": {},
2424
"./features/local_provider_dev": {},

.github/dependabot.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,36 @@ updates:
1010
schedule:
1111
interval: "daily"
1212
- package-ecosystem: "terraform" # See documentation for possible values
13-
directory: "/examples" # Location of package manifests
13+
directories: # Location of terraform modules
14+
# Workaround for not having glob support yet. Uncommment globs and remove individual paths when available. https://github.blog/changelog/2024-04-29-dependabot-multi-directory-configuration-public-beta-now-available/
15+
# - "/examples/resources/*"
16+
# - "/examples/data-sources/*"
17+
- "/examples/resources/powerplatform_billing_policy"
18+
- "/examples/resources/powerplatform_billing_policy_environment"
19+
- "/examples/resources/powerplatform_data_loss_prevention_policy"
20+
- "/examples/resources/powerplatform_environment"
21+
- "/examples/resources/powerplatform_environment_application_packages"
22+
- "/examples/resources/powerplatform_environment_settings"
23+
- "/examples/resources/powerplatform_managed_environment"
24+
- "/examples/resources/powerplatform_solution"
25+
- "/examples/resources/powerplatform_tenant_settings"
26+
- "/examples/resources/powerplatform_user"
27+
- "/examples/data-sources/powerplatform_billing_policies"
28+
- "/examples/data-sources/powerplatform_billing_policies_environments"
29+
- "/examples/data-sources/powerplatform_connectors"
30+
- "/examples/data-sources/powerplatform_currencies"
31+
- "/examples/data-sources/powerplatform_environment_application_packages"
32+
- "/examples/data-sources/powerplatform_environment_powerapps"
33+
- "/examples/data-sources/powerplatform_environment_settings"
34+
- "/examples/data-sources/powerplatform_environment_templates"
35+
- "/examples/data-sources/powerplatform_environments"
36+
- "/examples/data-sources/powerplatform_languages"
37+
- "/examples/data-sources/powerplatform_locations"
38+
- "/examples/data-sources/powerplatform_policies"
39+
- "/examples/data-sources/powerplatform_securityroles"
40+
- "/examples/data-sources/powerplatform_solutions"
41+
- "/examples/data-sources/powerplatform_tenant_application_packages"
42+
- "/examples/data-sources/powerplatform_tenant_settings"
1443
schedule:
1544
interval: "daily"
1645
- package-ecosystem: "github-actions" # See documentation for possible values

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
3838
passphrase: ${{ secrets.PASSPHRASE }}
3939
- name: Run GoReleaser
40-
uses: goreleaser/goreleaser-action@7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8 # v5.0.0
40+
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811 # v5.1.0
4141
with:
4242
args: release --clean
4343
env:

.github/workflows/terraform_provider.yml

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,37 @@ jobs:
7070
go build -v .
7171
7272
# run tfproviderlint
73-
linter:
74-
name: Run tfproviderlint
75-
needs: build
76-
runs-on: ubuntu-latest
77-
steps:
78-
79-
- name: Harden Runner
80-
uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
81-
with:
82-
egress-policy: audit
83-
84-
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
85-
- uses: bflad/tfproviderlint-github-action@3d16e28385eb2783700821cdf1b70f9f318bed3d # master
86-
with:
87-
args: ./...
73+
# linter:
74+
# name: Run tfproviderlint
75+
# needs: build
76+
# runs-on: ubuntu-latest
77+
# steps:
78+
79+
# - name: Harden Runner
80+
# uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1
81+
# with:
82+
# egress-policy: audit
83+
84+
# - name: Check out code into the Go module directory
85+
# uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
86+
87+
# - name: Set up Go
88+
# uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
89+
# with:
90+
# cache: true
91+
# go-version-file: 'go.mod'
92+
# id: go
93+
94+
# - run: |
95+
# go version
96+
97+
# - name: Install Provider Linter
98+
# run: |
99+
# go install github.com/bflad/tfproviderlint/cmd/tfproviderlint@latest
100+
101+
# - name: Run tfproviderlint
102+
# run: |
103+
# tfproviderlint ./...
88104

89105
# run unit tests
90106
unit_test:

DEVELOPER.md

Lines changed: 62 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,20 @@ For more information about devcontainers, you can check out the [devcontainer do
5858

5959
### Tenant
6060

61-
Developers should have access to a tenant where they can create and delete Power Platform environments and other resources.
62-
63-
TODO: more information about tenant and permissions needed by the dev user
61+
Developers should have access to a tenant where they can create and delete Power Platform environments and other resources and run acceptance test.
62+
You can setup access to you tenant using the following [bootstrap readme](https://github.com/microsoft/power-platform-terraform-quickstarts/blob/main/bootstrap/README.md) from our quickstarts repository.
6463

6564
### Credentials
6665

67-
See the [provider's user documentation](https://microsoft.github.io/terraform-provider-power-platform#authentication) on getting a service principal or user account credentials configured.
66+
See the [provider's user documentation](https://microsoft.github.io/terraform-provider-power-platform#authentication) on authenticating to the provider once your tenant is set up.
6867

6968
### Environment Variables
7069

7170
Use environment variables to configure the provider to use your chosen credentials. You may either pass credentials as terraform variables (via `TF_VAR_*` environment variables) or by using the provider's own environment variables (`POWER_PLATFORM_*`). See the [provider's user documentation](https://microsoft.github.io/terraform-provider-power-platform#authentication) for more information on configuring credentials for the provider.
7271

73-
## Running Provider locally in VSCode (linux)
72+
## Running Provider locally in VSCode
7473

75-
Open bash terminal inside VS Code and execute the following commands:
74+
Open bash terminal inside VSCode and execute the following commands:
7675

7776
```bash
7877
# you should already be in this directory, but just in case
@@ -88,7 +87,17 @@ cd examples/data-sources/powerplatform_environments
8887
terraform plan
8988
```
9089

91-
Note: You cannot run `terraform init` when using dev overrides. `terraform init` will validate the versions and provider source, while `terraform plan` will skip those validations when `dev overrides` is part of your config.
90+
If you prefer to use you operating system terminal instead of VSCode you can run the following command:
91+
92+
```bash
93+
docker exec -u vscode -w /workspaces/terraform-provider-power-platform -it <your_docker_container_name_goes_here> bash -c "exec bash"
94+
```
95+
96+
> [!NOTE]
97+
> You cannot run `terraform init` when using dev overrides. `terraform init` will validate the versions and provider source, while `terraform plan` will skip those validations when `dev overrides` is part of your config. You can simply run `terraforn plan` and `terrafirn apply` when working in devcontainer.
98+
99+
> [!TIP]
100+
> Because when working locally the `terraform init` command will not work, if you need additional terraform providers from terraform registry, all of them have to be added locally to the devcontainer in order to `terraform plan` and `terraform apply` work. You can add you missing terraform providers by adding them `.devcontainer/features/acceptance_test_dependencies/main.tf` and rebuild the devcontainer.
92101
93102
## Debugging provider in VSCode
94103

@@ -128,15 +137,32 @@ To run single unit test
128137
TF_ACC=0 go test -v ./... -run TestUnit<test_name>
129138
```
130139

131-
Note: The tests require permissions on the folders, these permissions are assigned when creating your container.
132-
If you have permission problems when running the unit tests, you can rebuild your development container
133-
or run the following commands again to assign the permissions to the necessary folders.
140+
> [!NOTE]
141+
> The tests require permissions on the folders, these permissions are assigned when creating your container. If you have permission problems when running the unit tests, you can rebuild your development container or run the following commands again to assign the permissions to the necessary folders.
134142
135143
```bash
136144
sudo chown -R vscode /workspaces/terraform-provider-power-platform/
137145
sudo chown -R vscode /go/pkg
138146
```
139147

148+
## Writing Tests
149+
150+
All the test for a given resource/datasource are located in `/internal/powerplatform/<resource/datasource_name>_test.go` file. When writing a new feature you should try to create [happy path](https://en.wikipedia.org/wiki/Happy_path) test(s) for you feature covering create, read and deletion of your new feature. For updates you should cover not only update of all properties but situation when a force recreate of a resource is requried (if you have such propeties in you resource).
151+
152+
### Writing Unit Tests
153+
154+
Unit test are created by mocking HTTP request, some of the often used HTTP mocks encapsulated in `ActivateEnvironmentHttpMocks` function, so that you don't have to write them for every test. When implementing new mocks, the mokcked response json files should be located in `/internal/powerplatform/services/<your_service_name>/test/<resource_or_datasource>/<name_of_the_unit_test>` folder
155+
156+
> [!TIP]
157+
> When creating mocked json responses you can resuse the exising one by **duplicating** then into you `<name_of_the_unit_test>` folder.
158+
159+
> [!CAUTION]
160+
> Your mocked json response file should not contain any Personally Identifiable Information such as tenantid, usernames, phone numbers, emails, addresses etc. You should anonymize that data.
161+
162+
### Writing Acceptance Tests
163+
164+
Each acceptance test is a copy of an unit test from tested use case perspective. That means for a given unit test we should have an acceptance test that validates the same use case but against a real infrastructure.
165+
140166
## Adding Dependencies
141167

142168
This provider uses [Go modules](https://github.com/golang/go/wiki/Modules).
@@ -161,7 +187,8 @@ make deps
161187

162188
User documentation markdown files in [/docs](/docs/) are auto-generated by the [terraform plugin docs tool](https://github.com/hashicorp/terraform-plugin-docs).
163189

164-
Do not manually edit the markdown files in [/docs](/docs/). If you need to edit documentation edit the following sources:
190+
> [!IMPORTANT]
191+
> Do not manually edit the markdown files in [/docs](/docs/). If you need to edit documentation edit the following sources:
165192
166193
- schema information in the provider, resource, and data-source golang files that are in [/internal](/internal/)
167194
- [template files](templates/)
@@ -174,6 +201,9 @@ User documentation is temporarily served on GitHub Pages which requires the [pag
174201

175202
## Making a Release
176203

204+
> [!TIP]
205+
> In you development work flow, you don't have to release the provider in order to test it locally, instread you can use the devcontainer and keep installing it locally in there by using `make install` command.
206+
177207
Our releases use [semantic versioning](https://semver.org/).
178208

179209
Given a version number MAJOR.MINOR.PATCH, increment the:
@@ -189,8 +219,27 @@ Use the `preview` extension to the MAJOR.MINOR.PATCH format for preview release
189219
Use the `git tag` command on the `main` branch (ensure main is up to date) and then push that release back to origin.
190220

191221
``` bash
192-
git tag -a v0.7.0-preview -m "v0.7.0-preview"
193-
git push origin v0.7.0-preview
222+
git tag -a v1.0.0-preview -m "v1.0.0-preview"
223+
git push origin v1.0.0-preview
194224
```
195225

196226
Once the release is pushed to the repo, the [release.yml](/.github/workflows/release.yml) action pipeline will detect the new tag and create a draft release. After the build completes, you can publish the release if it looks good.
227+
228+
## Developer work flow
229+
230+
Once you decide to contribute back to this reposity by fixing a bug or adding a feature you work flow will be as follows:
231+
232+
1. Fork this repository and open in locally
233+
1. Start working in devcontainer on your changes. (commands: `make install`, `terraform plan`, `terraform apply`)
234+
- Completly new feature should be located in a new `/internal/powerplatform/services/<new_service_name>` folder.
235+
1. Add and/or update unit and accaptance tests. Tests for new feature should be created in new resource/datasource_test.go file (commands: `make unittest`, `make acctest`)
236+
- When working on a bug remember to add a new unit and acceptance test(s) covering your use case if that test does not exist yet.
237+
- When working on a new feature add unit and acceptance tests covering [happy path](https://en.wikipedia.org/wiki/Happy_path) for your feature, ideally also some edge cases. If you feature enhances existing resource/datasource, add/change validation of your new properties in all tests that use that resource/datasource
238+
1. Create/Update examples in `/examples/...` folder(s)
239+
- When working on enhacement remeber to add new enhacement properties to all existing examples using that resource/datasource, especially if it is a requried property.
240+
- When creating new resource/datasource, create new examples showcasing how to use it.
241+
1. Regenerate the docs. (commands: `make docs`)
242+
1. Raise a pull request from your fork back the this repository
243+
244+
> [!NOTE]
245+
> If your use case requries testing outside local devcontainer like for example running it from a Github action, then you will need to create a realease from your fork repository.

docs/data-sources/billing_policies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data "powerplatform_billing_policies" "all_policies" {}
3434
### Read-Only
3535

3636
- `billing_policies` (Attributes List) [Power Platform Billing Policy](https://learn.microsoft.com/en-us/rest/api/power-platform/licensing/billing-policy/get-billing-policy#billingpolicyresponsemodel) (see [below for nested schema](#nestedatt--billing_policies))
37-
- `id` (Number) Placeholder identifier attribute
37+
- `id` (Number) Id of the read operation
3838

3939
<a id="nestedatt--billing_policies"></a>
4040
### Nested Schema for `billing_policies`

docs/data-sources/data_loss_prevention_policies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Fetches the list of Data Loss Prevention Policies in a Power Platform tenant. Se
1717

1818
### Read-Only
1919

20-
- `id` (String) The ID of this resource.
20+
- `id` (String) Id of the read operation
2121
- `policies` (Attributes List) List of Data Loss Prevention Policies (see [below for nested schema](#nestedatt--policies))
2222

2323
<a id="nestedatt--policies"></a>

docs/data-sources/environment_powerapps.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ data "powerplatform_environment_powerapps" "all" {}
3333

3434
### Read-Only
3535

36-
- `id` (String) The ID of this resource.
36+
- `id` (String) Id of the read operation
3737
- `powerapps` (Attributes List) List of Power Apps (see [below for nested schema](#nestedatt--powerapps))
3838

3939
<a id="nestedatt--powerapps"></a>

docs/data-sources/environment_settings.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Power Platform Environment Settings Data Source. Power Platform Settings are con
2727

2828
### Read-Only
2929

30-
- `id` (String) Id
30+
- `id` (String) Id of the read operation
3131

3232
<a id="nestedatt--audit_and_logs"></a>
3333
### Nested Schema for `audit_and_logs`

docs/data-sources/environments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ data "powerplatform_environments" "all_environments" {}
3434
### Read-Only
3535

3636
- `environments` (Attributes List) List of environments (see [below for nested schema](#nestedatt--environments))
37-
- `id` (Number) Placeholder identifier attribute
37+
- `id` (Number) Id of the read operation
3838

3939
<a id="nestedatt--environments"></a>
4040
### Nested Schema for `environments`

0 commit comments

Comments
 (0)