|
| 1 | +terraform { |
| 2 | + required_providers { |
| 3 | + tmc = { |
| 4 | + source = "vmware/tanzu/tmc" |
| 5 | + } |
| 6 | + } |
| 7 | +} |
| 8 | +// Create namespace with attached set as default value. |
| 9 | +resource "tmc_namespace" "create_namespace" { |
| 10 | + name = "tf-namespace" // Required |
| 11 | + cluster_name = "testcluster" // Required |
| 12 | + provisioner_name = "attached" // Default: attached |
| 13 | + management_cluster_name = "attached" // Default: attached |
| 14 | + |
| 15 | + meta { |
| 16 | + description = "Create namespace through terraform" |
| 17 | + labels = { "key" : "value" } |
| 18 | + } |
| 19 | + |
| 20 | + spec { |
| 21 | + workspace_name = "default" // Default: default |
| 22 | + attach = false // Default: false |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// Create namespace with attached set as 'true' |
| 27 | +resource "tmc_namespace" "create_namespace_attached" { |
| 28 | + name = "tf-namespace" // Required |
| 29 | + cluster_name = "testcluster" // Required |
| 30 | + provisioner_name = "attached" // Default: attached |
| 31 | + management_cluster_name = "attached" // Default: attached |
| 32 | + |
| 33 | + meta { |
| 34 | + description = "Create namespace through terraform" |
| 35 | + labels = { "key" : "value" } |
| 36 | + } |
| 37 | + |
| 38 | + spec { |
| 39 | + workspace_name = "default" // Default: default |
| 40 | + attach = true |
| 41 | + } |
| 42 | +} |
| 43 | +// Read TMC namespace : fetch namespace details |
| 44 | +data "tmc_namespace" "read_namespace" { |
| 45 | + name = "tf-namespace" // Required |
| 46 | + cluster_name = "testcluster" // Required |
| 47 | + management_cluster_name = "attached" // Default: attached |
| 48 | + provisioner_name = "attached" // Default: attached |
| 49 | +} |
| 50 | + |
| 51 | +// Output namespace resource |
| 52 | +output "namespace" { |
| 53 | + value = tmc_namespace.create_namespace |
| 54 | +} |
| 55 | +// Get namespace resource |
| 56 | +output "display_namespace" { |
| 57 | + value = data.tmc_namespace.read_namespace |
| 58 | +} |
0 commit comments