From c100473d29402c45c5d328349b7f1f5b912d592d Mon Sep 17 00:00:00 2001 From: Ryan Hristovski <61257223+ryanhristovski@users.noreply.github.com> Date: Thu, 10 Oct 2024 14:49:45 -0400 Subject: [PATCH] Have a generic example for users to be able to adapt (#61) --- examples/main.tf | 70 +++++++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 30 deletions(-) diff --git a/examples/main.tf b/examples/main.tf index 68e2721..1e25633 100644 --- a/examples/main.tf +++ b/examples/main.tf @@ -5,48 +5,58 @@ terraform { version = "~> 0.2" } } +} + +# Initialize provider +provider "docker" {} - required_version = "~>1.9" +# Define local variables for customization +locals { + namespace = "my-docker-namespace" + repo_name = "my-docker-repo" + org_name = "my-docker-org" + team_name = "my-team" + my_team_users = ["user1", "user2"] + token_label = "my-pat-token" + token_scopes = ["repo:read", "repo:write"] + permission = "admin" } -provider "docker" { - host = "hub-stage.docker.com" +# Create repository +resource "docker_hub_repository" "org_hub_repo" { + namespace = local.namespace + name = local.repo_name + description = "This is a generic Docker repository." + full_description = "Full description for the repository." } -# Resources Demo # Create team -resource "docker_org_team" "terraform-team" { - org_name = "dockerterraform" - team_name = "terraformhackk" - team_description = "Terraform Hackathon Demo - 2024" +resource "docker_org_team" "team" { + org_name = local.org_name + team_name = local.team_name + team_description = "Team description goes here." } # Team association -resource "docker_org_team_member" "example_association" { - org_name = "dockerterraform" - team_name = resource.docker_org_team.terraform-team.team_name - user_name = "username-placeholder" -} +resource "docker_org_team_member" "team_membership" { + for_each = toset(local.my_team_users) -# Create repository -resource "docker_hub_repository" "org_hub_repo" { - namespace = "dockerterraform" - name = "docker-terraform-repo-demo" - description = "This is a repo demo" - full_description = "Lorem ipsum" + org_name = local.org_name + team_name = docker_org_team.team.team_name + user_name = each.value } # Create repository team permission -resource "docker_hub_repository_team_permission" "test" { +resource "docker_hub_repository_team_permission" "repo_permission" { repo_id = docker_hub_repository.org_hub_repo.id - team_id = docker_org_team.terraform-team.id - permission = "admin" + team_id = docker_org_team.team.id + permission = local.permission } # Create access token -resource "docker_access_token" "new_token_v2" { - token_label = "terraform-created PAT-v2" - scopes = ["repo:read", "repo:write"] +resource "docker_access_token" "access_token" { + token_label = local.token_label + scopes = local.token_scopes } @@ -56,14 +66,14 @@ output "repo_output" { } output "org_team_output" { - value = resource.docker_org_team.terraform-team + value = resource.docker_org_team.team } output "org_team_association_output" { - value = resource.docker_org_team_member.example_association + value = resource.docker_org_team_member.team_membership } -# output "access_tokens_uuids_output" { -# value = resource.docker_access_token.new_token.uuid -# } +output "access_tokens_uuids_output" { + value = resource.docker_access_token.access_token.uuid +}