This repository is built on the Terraform Plugin Framework. The repository built on the Terraform Plugin SDK can be found at terraform-provider-scaffolding. See Which SDK Should I Use? in the Terraform documentation for additional information.
This repository is a NGC Terraform Provider which building from the template for a Terraform provider, containing:
- Resources and datasources (
internal/provider/
), - Examples (
examples/
) and generated documentation (docs/
), - Miscellaneous meta files.
- Clone the repository
- Enter the repository directory
- Build the provider using the Go
install
command:
go install .
This provider uses Go modules. Please see the Go documentation for the most up to date information about using Go modules.
To add a new dependency github.com/author/dependency
to your Terraform provider:
go get github.com/author/dependency
go mod tidy
Then commit the changes to go.mod
and go.sum
.
Fill this in for each provider
If you wish to work on the provider, you'll first need Go installed on your machine (see Requirements above).
To compile the provider, run go install
. This will build the provider and put the provider binary in the $GOPATH/bin
directory.
To generate or update documentation, run go generate
.
In order to run the full suite of Acceptance tests, run make testacc
.
Note: Acceptance tests create real resources, and often cost money to run.
make testacc
-
Update the
~/terraformrc
provider_installation { dev_overrides { "nvidia.com/dev/ngc" = "/home/huaweic/go/bin" # The path of go bin. } # For all other providers, install them directly from their origin provider # registries as normal. If you omit this, Terraform will _only_ use # the dev_overrides block, and so no other providers will be available. direct {} }
-
Change debug level
export TF_LOG=DEBUG
-
Setup NGC key
export NGC_API_KEY=nvapi-REDACTED
-
Test with terraform HCL. Here is an example. Please replace
backend
andinstance_type
by yourselves.terraform { required_providers { ngc = { source = "nvidia.com/dev/ngc" } } } provider "ngc" { ngc_org = "shhh2i6mga69" # Omniverse Cloud Prod ngc_team = "devinfra" } resource "ngc_cloud_function" "helm_based_cloud_function_example" { function_name = "terraform-cloud-function-resource-example-helm" helm_chart = "https://helm.ngc.nvidia.com/shhh2i6mga69/devinfra/charts/inference-test-0.1.tgz" helm_chart_service_name = "entrypoint" inference_port = 8000 inference_url = "/echo" health_uri = "/health" api_body_format = "CUSTOM" deployment_specifications = [ { configuration = "{\"image\":{\"repository\":\"nvcr.io/shhh2i6mga69/devinfra/fastapi_echo_sample\",\"tag\":\"latest\"}}", backend = "dgxc-forge-az33-prd1" instance_type = "DGX-CLOUD.GPU.L40_1x" gpu_type = "L40" max_instances = 1 min_instances = 1 max_request_concurrency = 1 } ] } resource "ngc_cloud_function" "helm_based_cloud_function_example_version" { function_name = ngc_cloud_function.helm_based_cloud_function_example.function_name function_id = ngc_cloud_function.helm_based_cloud_function_example.id helm_chart = "https://helm.ngc.nvidia.com/shhh2i6mga69/devinfra/charts/inference-test-0.1.tgz" helm_chart_service_name = "entrypoint" inference_port = 8000 inference_url = "/echo" health_uri = "/health" api_body_format = "CUSTOM" deployment_specifications = [ { configuration = "{\"image\":{\"repository\":\"nvcr.io/shhh2i6mga69/devinfra/fastapi_echo_sample\",\"tag\":\"latest\"}}", backend = "dgxc-forge-az33-prd1" instance_type = "DGX-CLOUD.GPU.L40_1x" gpu_type = "L40" max_instances = 1 min_instances = 1 max_request_concurrency = 1 } ] } resource "ngc_cloud_function" "container_based_cloud_function_example" { function_name = "terraform-cloud-function-resource-example-container" container_image = "nvcr.io/shhh2i6mga69/devinfra/fastapi_echo_sample:latest" inference_port = 8000 inference_url = "/echo" health_uri = "/health" api_body_format = "CUSTOM" deployment_specifications = [ { backend = "dgxc-forge-az33-prd1" instance_type = "DGX-CLOUD.GPU.L40_1x" gpu_type = "L40" max_instances = 1 min_instances = 1 max_request_concurrency = 1 } ] } resource "ngc_cloud_function" "container_based_cloud_function_example_version" { function_name = ngc_cloud_function.container_based_cloud_function_example.function_name function_id = ngc_cloud_function.container_based_cloud_function_example.id container_image = "nvcr.io/shhh2i6mga69/devinfra/fastapi_echo_sample:latest" inference_port = 8000 inference_url = "/echo" health_uri = "/health" api_body_format = "CUSTOM" deployment_specifications = [ { backend = "dgxc-forge-az33-prd1" instance_type = "DGX-CLOUD.GPU.L40_1x" gpu_type = "L40" max_instances = 1 min_instances = 1 max_request_concurrency = 1 } ] } data "ngc_cloud_function" "terraform-cloud-function-datasource-example" { function_id = "fe97aa46-c8ea-4237-ba56-1212036f4d0f" version_id = "868d2192-6819-4b53-89f5-3c7fb1df2a72" } output "function_details" { value = data.ngc_cloud_function.terraform-cloud-function-datasource-example }
-
Prepare testconfig file. Default is
./test-config.env
-
Create NGC personal key with
Function Management
permissions -
Execute test
# Run with default test config
make NGC_API_KEY=nvapi-REDACTED testacc
# Run with custom test config
make TEST_ENV_FILE={{ file path }} NGC_API_KEY=nvapi-REDACTED testacc
make test