Skip to content

Commit

Permalink
Have a generic example for users to be able to adapt (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhristovski authored Oct 10, 2024
1 parent fa85960 commit c100473
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions examples/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand All @@ -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
}

0 comments on commit c100473

Please sign in to comment.