### Install color Library Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/fatih/color/README.md Use 'go get' to install the color library. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-version Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/go-version/README.md Install the go-version library using the standard go get command. ```bash $ go get github.com/hashicorp/go-version ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/mattn/go-isatty/README.md Install the go-isatty package using the go get command. ```bash go get github.com/mattn/go-isatty ``` -------------------------------- ### Install msgpack/v5 Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/vmihailenco/msgpack/v5/README.md Install the msgpack/v5 library using go get. Ensure you are using Go modules. ```shell go get github.com/vmihailenco/msgpack/v5 ``` -------------------------------- ### hc-install Installation Output Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md Example output from the hc-install command after successfully installing a product. ```sh hc-install: will install terraform@1.3.7 installed terraform@1.3.7 to /current/working/dir/terraform ``` -------------------------------- ### Install copystructure Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/mitchellh/copystructure/README.md Use `go get` to install the library. This is the standard method for obtaining Go packages. ```bash $ go get github.com/mitchellh/copystructure ``` -------------------------------- ### Install msgpack Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/vmihailenco/msgpack/README.md Use 'go get' to install or update the msgpack package. ```shell go get -u github.com/vmihailenco/msgpack ``` -------------------------------- ### Install Golang Tag Parser Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/vmihailenco/tagparser/v2/README.md Use 'go get' to install the tagparser library. ```shell go get github.com/vmihailenco/tagparser/v2 ``` -------------------------------- ### Install Transform Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/tidwall/transform/README.md Install the Transform package using go get. ```sh go get -u github.com/tidwall/transform ``` -------------------------------- ### Install go-ini/ini Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/gopkg.in/ini.v1/README.md Install the go-ini/ini package using the go get command. Use the -u flag for future updates. ```sh go get gopkg.in/ini.v1 ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/mitchellh/mapstructure/README.md Use standard go get to install the mapstructure library. ```bash $ go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install go-colorable Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/mattn/go-colorable/README.md Use the go get command to download and install the go-colorable package into your Go workspace. ```bash go get github.com/mattn/go-colorable ``` -------------------------------- ### CLI Installation Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md Instructions for installing the `hc-install` command-line utility. ```APIDOC ## CLI Installation ### Homebrew (macOS / Linux) ```sh brew install hashicorp/tap/hc-install ``` ### Linux (Debian/Ubuntu/RHEL/CentOS/Fedora/Amazon Linux) Follow instructions in the [Official Packaging Guide](https://www.hashicorp.com/official-packaging-guide) to install the `hc-install` package from official HashiCorp repositories. ``` -------------------------------- ### Install Levenshtein Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/agext/levenshtein/README.md Use 'go get' to install the Levenshtein package for use in your Go projects. ```bash go get github.com/agext/levenshtein ``` -------------------------------- ### Install UUID Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/gofrs/uuid/README.md Use `go get` to download the package directly if you are unable to use a dependency manager. ```Shell $ go get github.com/gofrs/uuid ``` -------------------------------- ### Get User Details by GUID and Output Attributes Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/data-sources/user.md Use the `ad_user` data source to fetch user details by providing the user's GUID. The example demonstrates how to output the SAM account name, country, and trusted for delegation status. ```terraform data "ad_user" "u" { user_id = "DC3E5929-71C0-4232-9C32-9C7AFAABF0BB" } output "username" { value = data.ad_user.u.sam_account_name } output "country" { value = data.ad_user.u.country } output "trusted_for_delegation" { value = data.ad_user.u.trusted_for_delegation } ``` -------------------------------- ### Quickstart: Marshal and Unmarshal Data Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/vmihailenco/msgpack/v5/README.md Demonstrates basic usage of msgpack for marshaling a struct into MessagePack format and then unmarshaling it back. Includes error handling. ```go import "github.com/vmihailenco/msgpack/v5" func ExampleMarshal() { type Item struct { Foo string } b, err := msgpack.Marshal(&Item{Foo: "bar"}) if err != nil { panic(err) } var item Item err = msgpack.Unmarshal(b, &item) if err != nil { panic(err) } fmt.Println(item.Foo) // Output: bar } ``` -------------------------------- ### Install Terraform 1.3.7 with hc-install Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md Example of how to use the hc-install command to install a specific version of Terraform. ```sh hc-install install -version 1.3.7 terraform ``` -------------------------------- ### Build and Install Provider to terraform.d/plugins Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/_about/CONTRIBUTING.md Builds the provider binary and installs it to the default plugin directory. Requires Go and Make. Ensure Terraform is configured to detect plugins from this location. ```bash make build go install ``` -------------------------------- ### Installer Methods Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md The Installer offers high-level methods for managing product versions. Ensure finds, installs, or builds a product version, while Install specifically installs a product version. ```APIDOC ## Installer Methods ### `Ensure(context.Context, []src.Source)` **Description**: Finds, installs, or builds a product version based on the provided sources. ### `Install(context.Context, []src.Installable)` **Description**: Installs a specific product version. ``` -------------------------------- ### hc-install Install Command Syntax Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md This shows the command-line syntax for installing a HashiCorp product using hc-install. It specifies required and optional arguments. ```text Usage: hc-install install [options] -version This command installs a HashiCorp product. Options: -version [REQUIRED] Version of product to install. -path Path to directory where the product will be installed. Defaults to current working directory. -log-file Path to file where logs will be written. /dev/stdout or /dev/stderr can be used to log to STDOUT/STDERR. ``` -------------------------------- ### Quickstart: Marshal and Unmarshal Struct Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/vmihailenco/msgpack/README.md Demonstrates basic usage of Marshal and Unmarshal to encode and decode a Go struct. Ensure error handling for production code. ```go func ExampleMarshal() { type Item struct { Foo string } b, err := msgpack.Marshal(&Item{Foo: "bar"}) if err != nil { panic(err) } var item Item err = msgpack.Unmarshal(b, &item) if err != nil { panic(err) } fmt.Println(item.Foo) // Output: bar } ``` -------------------------------- ### Provider Configuration Examples Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/index.md This section provides various examples of how to configure the AD provider for different authentication methods and scenarios, including remote Basic, NTLM, and Kerberos authentication, as well as local execution on Windows. ```hcl variable "hostname" { default = "ad.yourdomain.com" } variable "username" { default = "user" } variable "password" { default = "password" } // remote using Basic authentication provider "ad" { winrm_hostname = var.hostname winrm_username = var.username winrm_password = var.password } // remote using NTLM authentication provider "ad" { winrm_hostname = var.hostname winrm_username = var.username winrm_password = var.password winrm_use_ntlm = true } // remote using NTLM authentication and HTTPS provider "ad" { winrm_hostname = var.hostname winrm_username = var.username winrm_password = var.password winrm_use_ntlm = true winrm_port = 5986 winrm_proto = "https" winrm_insecure = true } // remote using Kerberos authentication provider "ad" { winrm_hostname = var.hostname winrm_username = var.username winrm_password = var.password krb_realm = "YOURDOMAIN.COM" } // remote using Kerberos authentication with krb5.conf file provider "ad" { winrm_hostname = var.hostname winrm_username = var.username winrm_password = var.password krb_conf = "/etc/krb5.conf" } // local (windows only) provider "ad" { winrm_hostname = "" winrm_username = "" winrm_password = "" } ``` -------------------------------- ### Source Types for Installer Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md The Installer methods accept various Source types, each with different trade-offs for obtaining binaries. ```APIDOC ## Source Types ### `fs.{AnyVersion,ExactVersion,Version}` **Description**: Finds a binary in `$PATH` or additional paths. Convenient if the product is already installed and managed by the user. **Pros**: Relies on existing installations. **Cons**: Only supports a single version; user must manage installation. ``` ```APIDOC ### `releases.{LatestVersion,ExactVersion}` **Description**: Downloads, verifies, and installs any known product from `releases.hashicorp.com`. Suitable for obtaining pre-built versions, including enterprise editions. **Pros**: Fast, reliable, supports enterprise versions. **Cons**: Consumes bandwidth, disk space, and time; potentially less stable builds. ``` ```APIDOC ### `checkpoint.LatestVersion` **Description**: Downloads, verifies, and installs any known product available in HashiCorp Checkpoint. Typically contains stable product versions. **Pros**: Installs stable versions. **Cons**: Consumes bandwidth, disk space, and time; does not support old or enterprise versions. ``` ```APIDOC ### `build.GitRevision` **Description**: Clones raw source code and builds the product from it. Useful for early bug detection before product release. **Pros**: Catches bugs early. **Cons**: Time-consuming and resource-intensive build process; potential for fragile CI builds due to build instruction changes. ``` -------------------------------- ### Importing an ad_computer Resource Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/computer.md This demonstrates how to import an existing computer object into Terraform management using its GUID. Replace the example GUID with the actual GUID of the computer object. ```shell $ terraform import ad_computer 9CB8219C-31FF-4A85-A7A3-9BCBB6A41D02 ``` -------------------------------- ### Get App Engine Go SDK Package Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/google.golang.org/appengine/CONTRIBUTING.md Use 'go get -d' to download the App Engine Go SDK package. Ensure you change into the checked-out source directory before proceeding. ```bash go get -d google.golang.org/appengine ``` -------------------------------- ### Install gRPC-Go Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/google.golang.org/grpc/README.md Add this import to your Go code to automatically fetch gRPC-Go dependencies during build, run, or test. ```go import "google.golang.org/grpc" ``` -------------------------------- ### HCL Native Syntax Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Illustrates the native HCL syntax with attributes and nested blocks for service configuration. ```hcl io_mode = "async" service "http" "web_proxy" { listen_addr = "127.0.0.1:8080" process "main" { command = ["/usr/local/bin/awesome-app", "server"] } process "mgmt" { command = ["/usr/local/bin/awesome-app", "mgmt"] } } ``` -------------------------------- ### Example Usage of ad_group_membership Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/group_membership.md This example demonstrates how to create an Active Directory group and a user, and then add them as members to another group using the `ad_group_membership` resource. Ensure the variables for domain, OU, and group details are set appropriately. ```terraform variable name { default = "TestOU" } variable path { default = "dc=yourdomain,dc=com" } variable description { default = "some description" } variable protected { default = false } variable container { default = "CN=Users,dc=yourdomain,dc=com" } variable name { default = "test group" } variable sam_account_name { default = "TESTGROUP" } variable scope { default = "global" } variable category { default = "security" } resource "ad_group" "g" { name = var.name sam_account_name = var.sam_account_name scope = var.scope category = var.category container = var.container } resource ad_group "g2" { name = "${var.name}-2" sam_account_name = "${var.sam_account_name}-2" container = var.container } resource ad_user "u" { display_name = "test user" principal_name = "testUser" sam_account_name = "testUser" initial_password = "SuperSecure1234!!" container = var.container } resource ad_group_membership "gm" { group_id = ad_group.g.id group_members = [ ad_group.g2.id, ad_user.u.id ] } ``` -------------------------------- ### Kerberos Configuration Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/index.md This is an example of a Kerberos configuration file. It specifies default realm, DNS lookup settings, and realm-specific configurations including Key Distribution Center (KDC) and admin server details. This configuration is used when Kerberos authentication is enabled for WinRM connections. ```ini [libdefaults] default_realm = YOURDOMAIN.COM dns_lookup_realm = false dns_lookup_kdc = false [realms] YOURDOMAIN.COM = { kdc = 192.168.1.122 admin_server = 192.168.1.122 default_domain = YOURDOMAIN.COM } [domain_realm] yourdomain.com = YOURDOMAIN.COM ``` -------------------------------- ### Example Usage of ad_gplink Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/gplink.md This example demonstrates how to create an Organizational Unit (OU), a Group Policy Object (GPO), and then link them together using the ad_gplink resource. Ensure that the domain and path are correctly configured for your Active Directory environment. ```terraform resource "ad_ou" "o" { name = "gplinktestOU" path = "dc=yourdomain,dc=com" description = "OU for gplink tests" protected = false } resource "ad_gpo" "g" { name = "gplinktestGPO" domain = "yourdomain.com" description = "gpo for gplink tests" status = "AllSettingsEnabled" } resource "ad_gplink" "og" { gpo_guid = ad_gpo.g.id target_dn = ad_ou.o.dn enforced = true enabled = true } ``` -------------------------------- ### Wrap String Example in Go Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/mitchellh/go-wordwrap/README.md Demonstrates basic usage of the WrapString function to wrap a given string to a specified width. Ensure the 'fmt' package is imported for printing. ```go wrapped := wordwrap.WrapString("foo bar baz", 3) fmt.Println(wrapped) ``` -------------------------------- ### Importing HCL v1 and v2 in Go Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Example of how to import both HCL v1 and v2 packages in a Go program using semantic versioning. ```go import ( hcl1 "github.com/hashicorp/hcl" hcl2 "github.com/hashicorp/hcl/v2" ) ``` -------------------------------- ### HCL JSON Representation Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hcl/v2/README.md Shows the JSON equivalent of the HCL native syntax configuration. ```json { "io_mode": "async", "service": { "http": { "web_proxy": { "listen_addr": "127.0.0.1:8080", "process": { "main": { "command": ["/usr/local/bin/awesome-app", "server"] }, "mgmt": { "command": ["/usr/local/bin/awesome-app", "mgmt"] }, } } } } } ``` -------------------------------- ### Object For Expression Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Constructs an object by iterating over a list and mapping values to keys. ```hcl {for i, v in ["a", "b"]: v => i} ``` -------------------------------- ### Initialize Terraform with -plugin-dir Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/_about/CONTRIBUTING.md Initializes Terraform, specifying a custom directory for the provider binary using the `-plugin-dir` flag. This is useful for testing local builds without installing them globally. ```bash terraform init -plugin-dir /path/to/terraform-provider-ad ``` -------------------------------- ### Basic ad_computer Resource Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/computer.md This example shows how to declare an ad_computer resource with the required name and pre2kname attributes. Ensure these variables are defined in your Terraform configuration. ```terraform variable "name" { default = "test" } variable "pre2kname" { default = "TEST" } resource "ad_computer" "c" { name = var.name pre2kname = var.pre2kname } ``` -------------------------------- ### Basic ad_user Resource Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/user.md This is a basic example of how to create an ad_user resource. It requires principal_name, sam_account_name, and display_name. Custom attributes can be set using jsonencode. ```terraform variable principal_name { default = "testuser" } variable samaccountname { default = "testuser" } resource "ad_user" "u" { principal_name = var.principal_name sam_account_name = var.samaccountname display_name = "Terraform Test User" custom_attributes = jsonencode({ "carLicense": ["This is", "a multi-value", "attribute"], "comment": "and this is a single value attribute" }) } ``` -------------------------------- ### WinRM Client with Input and Output Handling (HTTP) Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/masterzen/winrm/README.md Shows how to create a WinRM client and execute a command that accepts standard input and streams output. Useful for interactive commands or commands requiring specific input. ```go package main import ( "github.com/masterzen/winrm" "fmt" "os" ) endpoint := winrm.NewEndpoint("localhost", 5985, false, false, nil, nil, nil, 0) client, err := winrm.NewClient(endpoint,"Administrator", "secret") if err != nil { panic(err) } ctx, cancel := context.WithCancel(context.Background()) defuncancel() _, err := client.RunWithContextWithInput(ctx, "ipconfig", os.Stdout, os.Stderr, os.Stdin) if err != nil { panic(err) } ``` -------------------------------- ### Use the global logger Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/go-hclog/README.md Logs a simple "hello world" message using the default global logger. Timestamps are included in the output. ```go hclog.Default().Info("hello world") ``` -------------------------------- ### Yamux Server Setup and Stream Acceptance Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/yamux/README.md Illustrates how to set up a Yamux server session to accept incoming TCP connections and then accept new streams from clients. It shows how to read data from an accepted stream. ```go func server() { // Accept a TCP connection conn, err := listener.Accept() if err != nil { panic(err) } // Setup server side of yamux session, err := yamux.Server(conn, nil) if err != nil { panic(err) } // Accept a stream stream, err := session.Accept() if err != nil { panic(err) } // Listen for a message buf := make([]byte, 4) stream.Read(buf) } ``` -------------------------------- ### Create WinRM Client and Run Command Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/masterzen/winrm/README.md Demonstrates how to create a WinRM client with TLS options and execute a command on a remote machine. Ensure proper context cancellation for aborting remote commands. ```go endpoint := "http://127.0.0.1:5985/wsman" client, err := winrm.NewClient(endpoint, "Administrator", "password") if err != nil { log.Fatalf("failed to create client: %q", err) } ctx, cancel := context.WithCancel(context.Background()) defer cancel() _, err = client.RunWithContext(ctx, "whoami", os.Stdout, os.Stderr) if err != nil { log.Fatalf("failed to run command: %q", err) } ``` -------------------------------- ### Get Group Details by GUID Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/data-sources/group.md Use the `group_id` argument to specify the group's GUID. The `output` blocks demonstrate how to access the group's name and ID. ```terraform data "ad_group" "g" { group_id = "DC3E5929-71C0-4232-9C32-9C7AFAABF0BB" } output "groupname" { value = data.ad_group.g.name } ``` -------------------------------- ### Create Root Logger in Go Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/go-logr/logr/README.md Demonstrates how to create the initial 'root' logger using a specific implementation (logimpl) with initial parameters. This is typically done early in an application's main function. ```go func main() { // ... other setup code ... // Create the "root" logger. We have chosen the "logimpl" implementation, // which takes some initial parameters and returns a logr.Logger. logger := logimpl.New(param1, param2) // ... other setup code ... ``` -------------------------------- ### Get Computer Details Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/data-sources/computer.md Use the `ad_computer` data source to retrieve details of a computer object by its distinguished name. The `guid` output can then be used in other resources or outputs. ```terraform data "ad_computer" "c" { dn = "cn=test123,cn=Computers,dc=yourdomain,dc=com" } output "computer_guid" { value = data.ad_computer.c.guid } ``` -------------------------------- ### Get ad_gpo Data Source Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/data-sources/gpo.md Use the `ad_gpo` data source to fetch details of a Group Policy Object by its name. The `guid` output can then be used to reference the GPO's unique identifier. ```terraform data "ad_gpo" "g" { name = "Some GPO" } output "gpo_uuid" { value = data.ad_gpo.g.guid } ``` -------------------------------- ### Get User Details by Distinguished Name and Output ID Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/data-sources/user.md This example shows how to use the `ad_user` data source with a user's Distinguished Name to retrieve their details. It then outputs the user's unique ID. ```terraform data "ad_user" "u2" { user_id = "CN=Test User,OU=Users,DC=contoso,DC=com" } output "testuser_guid" { value = data.ad_user.u2.id } ``` -------------------------------- ### Basic WinRM Client and Command Execution (HTTP) Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/masterzen/winrm/README.md Demonstrates creating a WinRM client for HTTP and executing a command. Use this for simple, non-interactive command execution. ```go package main import ( "github.com/masterzen/winrm" "os" ) endpoint := winrm.NewEndpoint(host, 5986, false, false, nil, nil, nil, 0) client, err := winrm.NewClient(endpoint, "Administrator", "secret") if err != nil { panic(err) } c{ ctx, cancel := context.WithCancel(context.Background()) defer cancel() client.RunWithContext(ctx, "ipconfig /all", os.Stdout, os.Stderr) } ``` -------------------------------- ### Install hc-install via Homebrew Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hc-install/README.md Installs the hc-install CLI tool using Homebrew on macOS or Linux systems. ```sh brew install hashicorp/tap/hc-install ``` -------------------------------- ### Yamux Client Setup and Stream Usage Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/yamux/README.md Demonstrates how to set up a Yamux client session over a TCP connection and open a new stream for communication. The stream itself implements the net.Conn interface. ```go func client() { // Get a TCP connection conn, err := net.Dial(...) if err != nil { panic(err) } // Setup client side of yamux session, err := yamux.Client(conn, nil) if err != nil { panic(err) } // Open a new stream stream, err := session.Open() if err != nil { panic(err) } // Stream implements net.Conn stream.Write([]byte("ping")) } ``` -------------------------------- ### Importing an ad_gplink Resource Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/gplink.md This shows the command to import an existing ad_gplink resource into your Terraform state. The ID format requires the GPO GUID and the container (OU) GUID, separated by an underscore. ```shell # The ID for this resource is comprised of the GPO GUID and the container (OU) GUID separated by # an underscore $ terraform import ad_gplink 9CB8219C-31FF-4A85-A7A3-9BCBB6A41D02_5AB72AD7-1AA0-4D97-923B-6FBCDD143CB2 ``` -------------------------------- ### Simple GET Request with go-retryablehttp Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/go-retryablehttp/README.md Demonstrates a basic GET request using the retryablehttp client. If the request fails or receives a 500-range status code, it will automatically retry with exponential backoff. ```go resp, err := retryablehttp.Get("/foo") if err != nil { panic(err) } ``` -------------------------------- ### Link GPOs to OUs with `ad_gplink` Source: https://context7.com/hashicorp/terraform-provider-ad/llms.txt Creates a link between a GPO and a container object (typically an OU). Multiple GPOs can be linked to the same OU and ordered by precedence. Import requires the GPO GUID followed by '_' and the OU GUID. ```terraform resource "ad_gplink" "baseline_to_engineering" { gpo_guid = ad_gpo.security_baseline.id target_dn = ad_ou.engineering.dn enabled = true enforced = true # enforced links cannot be blocked by child OUs order = 1 # lower = higher precedence } # Import: GPO GUID + "_" + OU GUID # terraform import ad_gplink.baseline_to_engineering \ # 9CB8219C-31FF-4A85-A7A3-9BCBB6A41D02_5AB72AD7-1AA0-4D97-923B-6FBCDD143CB2 ``` -------------------------------- ### WinRM Client with Kerberos Authentication Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/masterzen/winrm/README.md Demonstrates setting up Kerberos authentication for the WinRM client by specifying the necessary parameters in the TransportDecorator. Ensure Kerberos configuration files and credentials are correctly set up. ```go package main import ( "os" "fmt" "github.com/masterzen/winrm" ) endpoint := winrm.NewEndpoint("srv-win", 5985, false, false, nil, nil, nil, 0) params := winrm.DefaultParameters params.TransportDecorator = func() Transporter { return &winrm.ClientKerberos{ Username: "test", Password: "s3cr3t", Hostname: "srv-win", Realm: "DOMAIN.LAN", Port: 5985, Proto: "http", KrbConf: "/etc/krb5.conf", SPN: fmt.Sprintf("HTTP/%s", hostname), } } client, err := NewClientWithParameters(endpoint, "test", "s3cr3t", params) if err != nil { panic(err) } ctx, cancel := context.WithCancel(context.Background()) defuncancel() _, err := client.RunWithContextWithInput(ctx, "ipconfig", os.Stdout, os.Stderr, os.Stdin) if err != nil { panic(err) } ``` -------------------------------- ### Create Provider with Explicit Hostname and Namespace Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/terraform-registry-address/README.md The `NewProvider` function constructs a `Provider` struct. It panics if an empty, placeholder ("-"), or unknown ("?") namespace is provided, enforcing valid provider address creation. ```go NewProvider(DefaultProviderRegistryHost, "", "aws") // panic NewProvider(DefaultProviderRegistryHost, "-", "aws") // panic NewProvider(DefaultProviderRegistryHost, "?", "aws") // panic ``` -------------------------------- ### Build WinRM Go Library Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/masterzen/winrm/README.md Clone the WinRM repository and build the Go library from source. Requires Go 1.5+. ```sh git clone https://github.com/masterzen/winrm cd winrm make ``` -------------------------------- ### Tuple For Expression Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/hashicorp/hcl/v2/hclsyntax/spec.md Constructs a tuple by iterating over a list and projecting each element. ```hcl [for v in ["a", "b"]: v] ``` -------------------------------- ### Look Up an AD GPO Source: https://context7.com/hashicorp/terraform-provider-ad/llms.txt Retrieves an existing Group Policy Object by its name or GUID. ```terraform data "ad_gpo" "baseline" { name = "Security-Baseline" } output "gpo_guid" { value = data.ad_gpo.baseline.id } output "gpo_domain" { value = data.ad_gpo.baseline.domain } ``` -------------------------------- ### Enable Key Conversion for Basic/Manual Scaling Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/google.golang.org/appengine/README.md Enable key conversion for all handlers in the service by calling EnableKeyConversion in the /_ah/start handler. This is for basic and manual scaling environments. ```go http.HandleFunc("/_ah/start", func(w http.ResponseWriter, r *http.Request) { datastore.EnableKeyConversion(appengine.NewContext(r)) }) ``` -------------------------------- ### ad_computer Data Source Source: https://context7.com/hashicorp/terraform-provider-ad/llms.txt Retrieves the details of an existing AD computer object by DN or GUID. ```APIDOC ## ad_computer Data Source — Look Up a Computer Retrieves the details of an existing AD computer object by DN or GUID. ### Example ```terraform data "ad_computer" "ws" { computer_id = "cn=WS-ALICE-01,OU=Engineering,DC=contoso,DC=com" } output "ws_name" { value = data.ad_computer.ws.name } output "ws_sid" { value = data.ad_computer.ws.sid } ``` ``` -------------------------------- ### Look Up an AD Computer Source: https://context7.com/hashicorp/terraform-provider-ad/llms.txt Retrieves details of an existing AD computer object. Use DN or GUID for lookup. ```terraform data "ad_computer" "ws" { computer_id = "cn=WS-ALICE-01,OU=Engineering,DC=contoso,DC=com" } output "ws_name" { value = data.ad_computer.ws.name } output "ws_sid" { value = data.ad_computer.ws.sid } ``` -------------------------------- ### ad_user Resource with All Attributes Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/docs/resources/user.md This example demonstrates the usage of the ad_user resource with all available attributes. It includes basic user information, contact details, and advanced settings like smart_card_logon_required and trusted_for_delegation. ```terraform variable principal_name2 { default = "testuser2" } variable samaccountname2 { default = "testuser2" } variable container { default = "CN=Users,DC=contoso,DC=com" } resource "ad_user" "u2" { principal_name = var.principal_name2 sam_account_name = var.samaccountname2 display_name = "Terraform Test User" container = var.container initial_password = "Password" city = "City" company = "Company" country = "us" department = "Department" description = "Description" division = "Division" email_address = "some@email.com" employee_id = "id" employee_number = "number" fax = "Fax" given_name = "GivenName" home_directory = "HomeDirectory" home_drive = "HomeDrive" home_phone = "HomePhone" home_page = "HomePage" initials = "Initia" mobile_phone = "MobilePhone" office = "Office" office_phone = "OfficePhone" organization = "Organization" other_name = "OtherName" po_box = "POBox" postal_code = "PostalCode" state = "State" street_address = "StreetAddress" surname = "Surname" title = "Title" smart_card_logon_required = false trusted_for_delegation = true } ``` -------------------------------- ### Add Goroutine with io.ReadCloser Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/oklog/run/README.md This example demonstrates adding a goroutine that reads from an io.ReadCloser. The connection is closed in the interrupt handler. ```go var conn io.ReadCloser = ... g.Add(func() error { s := bufio.NewScanner(conn) for s.Scan() { println(s.Text()) } return s.Err() }, func(error) { conn.Close() }) ``` -------------------------------- ### Chaining Transformers Example Source: https://github.com/hashicorp/terraform-provider-ad/blob/main/vendor/github.com/tidwall/transform/README.md Demonstrates chaining multiple transformers: LineMatch to filter lines containing 'o', LineTrimSpace to remove whitespace, and ToUpper to convert to uppercase. The output is read using ioutil.ReadAll. ```go phrases := " lacy timber \n" phrases += "\t\thybrid gossiping\t\n" phrases += " coy radioactivity\n" phrases += "rocky arrow \n" r := ToUpper(LineTrimSpace(LineMatch(bytes.NewBufferString(phrases), "o"))) // Pass the string though the transformer. out, err := ioutil.ReadAll(r) if err != nil { log.Fatal(err) } fmt.Printf("%s\n", out) ```